6e04a20d2b5316f84c8dee2e2fe5b507ad9bb56e
[pub/Android/ownCloud.git] / automationTest / src / test / java / com / owncloud / android / test / ui / testSuites / RenameFileTestSuite.java
1 /**
2 * ownCloud Android client application
3 *
4 * @author purigarcia
5 * Copyright (C) 2015 ownCloud Inc.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2,
9 * as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 package com.owncloud.android.test.ui.testSuites;
22
23 import static org.junit.Assert.*;
24 import io.appium.java_client.android.AndroidDriver;
25
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Rule;
29 import org.junit.experimental.categories.Category;
30 import org.junit.rules.TestName;
31 import org.junit.runners.MethodSorters;
32 import org.junit.FixMethodOrder;
33 import org.junit.Test;
34 import org.openqa.selenium.By;
35 import org.openqa.selenium.support.ui.ExpectedConditions;
36
37 import com.owncloud.android.test.ui.actions.Actions;
38 import com.owncloud.android.test.ui.groups.NoIgnoreTestCategory;
39 import com.owncloud.android.test.ui.groups.SmokeTestCategory;
40 import com.owncloud.android.test.ui.models.ElementMenuOptions;
41 import com.owncloud.android.test.ui.models.FileListView;
42 import com.owncloud.android.test.ui.models.NewFolderPopUp;
43 import com.owncloud.android.test.ui.models.WaitAMomentPopUp;
44
45
46 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
47 public class RenameFileTestSuite{
48
49 AndroidDriver driver;
50 Common common;
51 private Boolean fileHasBeenCreated = false;
52 private final String OLD_FILE_NAME = Config.fileToTestName;
53 private final String FILE_NAME = "newNameFile";
54 private String CurrentCreatedFile = "";
55
56 @Rule public TestName name = new TestName();
57
58 @Before
59 public void setUp() throws Exception {
60 common=new Common();
61 driver=common.setUpCommonDriver();
62 }
63
64 @Test
65 @Category({NoIgnoreTestCategory.class, SmokeTestCategory.class})
66 public void testRenameFile () throws Exception {
67 FileListView fileListView = Actions.login(Config.URL, Config.user,
68 Config.password, Config.isTrusted, driver);
69 common.assertIsInFileListView();
70
71 //TODO. if the file already exists, do not upload
72 FileListView fileListViewAfterUploadFile = Actions
73 .uploadFile(OLD_FILE_NAME, fileListView);
74
75 //check if the file with the new name already exists, if true delete it
76 Actions.deleteElement(FILE_NAME, fileListView, driver);
77
78 fileListViewAfterUploadFile.scrollTillFindElement(OLD_FILE_NAME);
79 assertTrue(fileHasBeenCreated = fileListViewAfterUploadFile
80 .getFileElement().isDisplayed());
81 CurrentCreatedFile = OLD_FILE_NAME;
82 Common.waitTillElementIsNotPresent(fileListViewAfterUploadFile
83 .getProgressCircular(), 1000);
84 common.wait.until(ExpectedConditions.visibilityOf(
85 fileListViewAfterUploadFile.getFileElementLayout()
86 .findElement(By.id(FileListView.getLocalFileIndicator()))));
87 ElementMenuOptions menuOptions = fileListViewAfterUploadFile
88 .longPressOnElement(OLD_FILE_NAME);
89 NewFolderPopUp newFolderPopUp = menuOptions.clickOnRename();
90 newFolderPopUp.typeNewFolderName(FILE_NAME);
91 WaitAMomentPopUp waitAMomentPopUp = newFolderPopUp
92 .clickOnNewFolderOkButton();
93 Common.waitTillElementIsNotPresent(waitAMomentPopUp
94 .getWaitAMomentTextElement(), 100);
95 fileListViewAfterUploadFile.scrollTillFindElement(FILE_NAME);
96 assertNotNull(fileListViewAfterUploadFile.getFileElement());
97 assertTrue(fileListViewAfterUploadFile.getFileElement().isDisplayed());
98 assertEquals(FILE_NAME , fileListViewAfterUploadFile.getFileElement()
99 .getText());
100 CurrentCreatedFile = FILE_NAME;
101 }
102
103 @After
104 public void tearDown() throws Exception {
105 common.takeScreenShotOnFailed(name.getMethodName());
106 if (fileHasBeenCreated) {
107 FileListView fileListView = new FileListView(driver);
108 Actions.deleteElement(CurrentCreatedFile,fileListView, driver);
109 }
110 driver.removeApp("com.owncloud.android");
111 driver.quit();
112 }
113
114 }