4c9b293be96477648b3784e4061ceb263b475b5f
[pub/Android/ownCloud.git] / automationTest / src / test / java / com / owncloud / android / test / ui / testSuites / RenameFileTestSuite.java
1 package com.owncloud.android.test.ui.testSuites;
2
3 import static org.junit.Assert.*;
4 import io.appium.java_client.android.AndroidDriver;
5
6 import org.junit.After;
7 import org.junit.Before;
8 import org.junit.Rule;
9 import org.junit.experimental.categories.Category;
10 import org.junit.rules.TestName;
11 import org.junit.runners.MethodSorters;
12 import org.junit.FixMethodOrder;
13 import org.junit.Test;
14 import org.openqa.selenium.By;
15 import org.openqa.selenium.support.ui.ExpectedConditions;
16
17 import com.owncloud.android.test.ui.actions.Actions;
18 import com.owncloud.android.test.ui.groups.NoIgnoreTestCategory;
19 import com.owncloud.android.test.ui.groups.SmokeTestCategory;
20 import com.owncloud.android.test.ui.models.ElementMenuOptions;
21 import com.owncloud.android.test.ui.models.FileListView;
22 import com.owncloud.android.test.ui.models.NewFolderPopUp;
23 import com.owncloud.android.test.ui.models.WaitAMomentPopUp;
24
25
26 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
27 public class RenameFileTestSuite{
28
29 AndroidDriver driver;
30 Common common;
31 private Boolean fileHasBeenCreated = false;
32 private final String OLD_FILE_NAME = Config.fileToTestName;
33 private final String FILE_NAME = "newNameFile";
34 private String CurrentCreatedFile = "";
35
36 @Rule public TestName name = new TestName();
37
38 @Before
39 public void setUp() throws Exception {
40 common=new Common();
41 driver=common.setUpCommonDriver();
42 }
43
44 @Test
45 @Category({NoIgnoreTestCategory.class, SmokeTestCategory.class})
46 public void testRenameFile () throws Exception {
47 FileListView fileListView = Actions.login(Config.URL, Config.user,Config.password, Config.isTrusted, driver);
48 common.assertIsInFileListView();
49
50 //TODO. if the file already exists, do not upload
51 FileListView fileListViewAfterUploadFile = Actions.uploadFile(OLD_FILE_NAME, fileListView);
52
53 //check if the file with the new name already exists, if true delete it
54 Actions.deleteElement(FILE_NAME, fileListView, driver);
55
56 fileListViewAfterUploadFile.scrollTillFindElement(OLD_FILE_NAME);
57 assertTrue(fileHasBeenCreated = fileListViewAfterUploadFile.getFileElement().isDisplayed());
58 CurrentCreatedFile = OLD_FILE_NAME;
59 Common.waitTillElementIsNotPresent(fileListViewAfterUploadFile.getProgressCircular(), 1000);
60 common.wait.until(ExpectedConditions.visibilityOf(fileListViewAfterUploadFile.getFileElementLayout().findElement(By.id(FileListView.getLocalFileIndicator()))));
61 ElementMenuOptions menuOptions = fileListViewAfterUploadFile.longPressOnElement(OLD_FILE_NAME);
62 NewFolderPopUp newFolderPopUp = menuOptions.clickOnRename();
63 newFolderPopUp.typeNewFolderName(FILE_NAME);
64 WaitAMomentPopUp waitAMomentPopUp = newFolderPopUp.clickOnNewFolderOkButton();
65 Common.waitTillElementIsNotPresent(waitAMomentPopUp.getWaitAMomentTextElement(), 100);
66 fileListViewAfterUploadFile.scrollTillFindElement(FILE_NAME);
67 assertNotNull(fileListViewAfterUploadFile.getFileElement());
68 assertTrue(fileListViewAfterUploadFile.getFileElement().isDisplayed());
69 assertEquals(FILE_NAME , fileListViewAfterUploadFile.getFileElement().getText());
70 CurrentCreatedFile = FILE_NAME;
71 }
72
73 @After
74 public void tearDown() throws Exception {
75 common.takeScreenShotOnFailed(name.getMethodName());
76 if (fileHasBeenCreated) {
77 FileListView fileListView = new FileListView(driver);
78 Actions.deleteElement(CurrentCreatedFile,fileListView, driver);
79 }
80 driver.removeApp("com.owncloud.android");
81 driver.quit();
82 }
83
84 }