add new testCases. prepare the test to have them into categories
[pub/Android/ownCloud.git] / automationTest / src / test / java / androidtest / tests / UploadTestSuite.java
1 package androidtest.tests;
2
3
4 import static org.junit.Assert.*;
5 import io.appium.java_client.MobileBy;
6 import io.appium.java_client.android.AndroidDriver;
7
8 import org.junit.After;
9 import org.junit.Before;
10 import org.junit.Rule;
11 import org.junit.experimental.categories.Category;
12 import org.junit.rules.TestName;
13 import org.junit.runners.MethodSorters;
14 import org.junit.FixMethodOrder;
15 import org.junit.Test;
16 import org.openqa.selenium.By;
17 import org.openqa.selenium.support.ui.ExpectedConditions;
18
19 import androidtest.actions.Actions;
20 import androidtest.groups.FailingTestCategory;
21 import androidtest.groups.IgnoreTestCategory;
22 import androidtest.groups.NoIgnoreTestCategory;
23 import androidtest.models.AppDetailsView;
24 import androidtest.models.ElementMenuOptions;
25 import androidtest.models.GmailEmailListView;
26 import androidtest.models.GmailEmailView;
27 import androidtest.models.ImageView;
28 import androidtest.models.MainView;
29 import androidtest.models.UploadView;
30
31
32 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
33 @Category({NoIgnoreTestCategory.class})
34 public class UploadTestSuite{
35
36 AndroidDriver driver;
37 Common common;
38 String FILE_NAME = "test";
39
40 @Rule public TestName name = new TestName();
41
42
43 @Before
44 public void setUp() throws Exception {
45 common=new Common();
46 driver=common.setUpCommonDriver();
47 }
48
49 @Test
50 @Category(NoIgnoreTestCategory.class)
51 public void testUploadFile () throws Exception {
52
53 MainView mainView = Actions.login(Config.URL, Config.user,Config.password, Config.isTrusted, driver);
54 common.assertIsInMainView();
55
56 //check if the file already exists and if true, delete it
57 Actions.deleteElement(FILE_NAME, mainView, driver);
58
59 MainView mainViewAfterUploadFile = Actions.uploadFile(FILE_NAME, mainView);
60
61 mainViewAfterUploadFile.scrollTillFindElement(FILE_NAME);
62 assertTrue(mainViewAfterUploadFile.getFileElement().isDisplayed());
63 Common.waitTillElementIsNotPresent(mainViewAfterUploadFile.getProgressCircular(), 1000);
64 common.wait.until(ExpectedConditions.visibilityOf(mainViewAfterUploadFile.getFileElementLayout().findElement(By.id(MainView.getLocalFileIndicator()))));
65
66
67 }
68
69 @Test
70 @Category(IgnoreTestCategory.class)
71 public void testUploadFromGmail () throws Exception {
72 MainView mainView = Actions.login(Config.URL, Config.user,Config.password, Config.isTrusted, driver);
73 driver.startActivity("com.google.android.gm", ".ConversationListActivityGmail");
74 GmailEmailListView gmailEmailListView = new GmailEmailListView(driver);
75 GmailEmailView gmailEmailView = gmailEmailListView.clickOnEmail();
76 ImageView imageView = gmailEmailView.clickOnfileButton();
77 imageView.clickOnOptionsButton();
78 imageView.clickOnShareButton();
79 imageView.clickOnOwnCloudButton();
80 imageView.clickOnJustOnceButton();
81 UploadView uploadView = new UploadView(driver);
82 uploadView.clickOUploadButton();
83 driver.startActivity("com.owncloud.android", ".ui.activity.FileDisplayActivity");
84 common.wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.name("test.jpg")));
85 assertEquals("test.jpg" , driver.findElementByName("test.jpg").getText());
86 }
87
88
89 @Test
90 @Category({IgnoreTestCategory.class, FailingTestCategory.class})
91 public void testKeepFileUpToDate () throws Exception {
92
93 MainView mainView = Actions.login(Config.URL, Config.user,Config.password, Config.isTrusted, driver);
94 common.assertIsInMainView();
95
96 Common.waitTillElementIsNotPresent(mainView.getProgressCircular(), 1000);
97
98 MainView mainViewAfterUploadFile = Actions.uploadFile(FILE_NAME, mainView);
99 mainViewAfterUploadFile.scrollTillFindElement(FILE_NAME);
100 assertTrue(mainViewAfterUploadFile.getFileElement().isDisplayed());
101
102 ElementMenuOptions menuOptions = mainViewAfterUploadFile.longPressOnElement(FILE_NAME);
103 AppDetailsView appDetailsView = menuOptions.clickOnDetails();
104 appDetailsView.checkKeepFileUpToDateCheckbox();
105 Thread.sleep(3000);
106 driver.sendKeyEvent(android.view.KeyEvent.KEYCODE_BACK);
107 assertTrue(common.isElementPresent(mainViewAfterUploadFile.getFileElementLayout(), MobileBy.id(MainView.getFavoriteFileIndicator())));
108
109 }
110
111
112 @After
113 public void tearDown() throws Exception {
114 common.takeScreenShotOnFailed(name.getMethodName());
115 MainView mainView = new MainView(driver);
116 Actions.deleteElement(FILE_NAME,mainView, driver);
117 driver.removeApp("com.owncloud.android");
118 driver.quit();
119 }
120
121
122 }
123