add new testCases. prepare the test to have them into categories
[pub/Android/ownCloud.git] / automationTest / src / test / java / androidtest / tests / RenameFileTestSuite.java
1 package androidtest.tests;
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 androidtest.actions.Actions;
18 import androidtest.groups.NoIgnoreTestCategory;
19 import androidtest.groups.SmokeTestCategory;
20 import androidtest.models.ElementMenuOptions;
21 import androidtest.models.MainView;
22 import androidtest.models.NewFolderPopUp;
23 import androidtest.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 = "test";
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 MainView mainView = Actions.login(Config.URL, Config.user,Config.password, Config.isTrusted, driver);
48 common.assertIsInMainView();
49
50 //TODO. if the file already exists, do not upload
51 MainView mainViewAfterUploadFile = Actions.uploadFile(OLD_FILE_NAME, mainView);
52
53 //check if the file with the new name already exists, if true delete it
54 Actions.deleteElement(FILE_NAME, mainView, driver);
55
56 mainViewAfterUploadFile.scrollTillFindElement(OLD_FILE_NAME);
57 assertTrue(fileHasBeenCreated = mainViewAfterUploadFile.getFileElement().isDisplayed());
58 CurrentCreatedFile = OLD_FILE_NAME;
59 Common.waitTillElementIsNotPresent(mainViewAfterUploadFile.getProgressCircular(), 1000);
60 common.wait.until(ExpectedConditions.visibilityOf(mainViewAfterUploadFile.getFileElementLayout().findElement(By.id(MainView.getLocalFileIndicator()))));
61 ElementMenuOptions menuOptions = mainViewAfterUploadFile.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 mainViewAfterUploadFile.scrollTillFindElement(FILE_NAME);
67 assertNotNull(mainViewAfterUploadFile.getFileElement());
68 assertTrue(mainViewAfterUploadFile.getFileElement().isDisplayed());
69 assertEquals(FILE_NAME , mainViewAfterUploadFile.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 MainView mainView = new MainView(driver);
78 Actions.deleteElement(CurrentCreatedFile,mainView, driver);
79 }
80 driver.removeApp("com.owncloud.android");
81 driver.quit();
82 }
83
84 }