4909fbbb963f010dee6e6cc177ccb23123868cce
[pub/Android/ownCloud.git] / automationTest / src / test / java / androidtest / tests / RenameFileTestSuite.java
1 package androidtest.tests;
2
3 import org.junit.After;
4 import org.junit.Before;
5 import org.junit.runners.MethodSorters;
6 import org.junit.FixMethodOrder;
7 import org.junit.Test;
8 import org.openqa.selenium.By;
9 import org.openqa.selenium.support.ui.ExpectedConditions;
10
11 import androidtest.actions.Actions;
12 import androidtest.models.ElementMenuOptions;
13 import androidtest.models.MainView;
14 import androidtest.models.NewFolderPopUp;
15 import androidtest.models.WaitAMomentPopUp;
16
17
18 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
19 public class RenameFileTestSuite extends Common{
20
21 private Boolean fileHasBeenCreated = false;
22 private final String OLD_FILE_NAME = "test";
23 private final String FILE_NAME = "newNameFile";
24 private String CurrentCreatedFile = "";
25
26
27 @Before
28 public void setUp() throws Exception {
29 setUpCommonDriver();
30 }
31
32 @Test
33 public void testRenameFile () throws Exception {
34 MainView mainView = Actions.login(Config.URL, Config.user,Config.password, Config.isTrusted, driver);
35 waitForTextPresent("ownCloud", mainView.getTitleTextElement());
36
37 //TODO. if the file already exists, do not upload
38 MainView mainViewAfterUploadFile = Actions.uploadFile(OLD_FILE_NAME, mainView);
39
40 //check if the file with the new name already exists, if true delete it
41 Actions.deleteElement(FILE_NAME, mainView, driver);
42
43 mainViewAfterUploadFile.scrollTillFindElement(OLD_FILE_NAME);
44 assertTrue(fileHasBeenCreated = mainViewAfterUploadFile.getFileElement().isDisplayed());
45 CurrentCreatedFile = OLD_FILE_NAME;
46 waitTillElementIsNotPresent(mainViewAfterUploadFile.getProgressCircular(), 1000);
47 wait.until(ExpectedConditions.visibilityOf(mainViewAfterUploadFile.getFileElementLayout().findElement(By.id(MainView.getLocalFileIndicator()))));
48 ElementMenuOptions menuOptions = mainViewAfterUploadFile.longPressOnElement(OLD_FILE_NAME);
49 NewFolderPopUp newFolderPopUp = menuOptions.clickOnRename();
50 newFolderPopUp.typeNewFolderName(FILE_NAME);
51 WaitAMomentPopUp waitAMomentPopUp = newFolderPopUp.clickOnNewFolderOkButton();
52 waitTillElementIsNotPresent(waitAMomentPopUp.getWaitAMomentTextElement(), 100);
53 mainViewAfterUploadFile.scrollTillFindElement(FILE_NAME);
54 assertNotNull(mainViewAfterUploadFile.getFileElement());
55 assertTrue(mainViewAfterUploadFile.getFileElement().isDisplayed());
56 assertEquals(FILE_NAME , mainViewAfterUploadFile.getFileElement().getText());
57 CurrentCreatedFile = FILE_NAME;
58 }
59
60 @After
61 public void tearDown() throws Exception {
62 takeScreenShotOnFailed(getName());
63 if (fileHasBeenCreated) {
64 MainView mainView = new MainView(driver);
65 Actions.deleteElement(CurrentCreatedFile,mainView, driver);
66 }
67 driver.removeApp("com.owncloud.android");
68 driver.quit();
69 }
70
71 }