af956477d406a884bdb46496b52fd5ae35a1b8a5
[pub/Android/ownCloud.git] / automationTest / src / test / java / com / owncloud / android / test / ui / testSuites / UploadTestSuite.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
24 import static org.junit.Assert.*;
25 import io.appium.java_client.MobileBy;
26 import io.appium.java_client.android.AndroidDriver;
27
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Rule;
31 import org.junit.experimental.categories.Category;
32 import org.junit.rules.TestName;
33 import org.junit.runners.MethodSorters;
34 import org.junit.FixMethodOrder;
35 import org.junit.Test;
36 import org.openqa.selenium.By;
37 import org.openqa.selenium.NoSuchElementException;
38 import org.openqa.selenium.support.ui.ExpectedConditions;
39
40 import com.owncloud.android.test.ui.actions.Actions;
41 import com.owncloud.android.test.ui.groups.FailingTestCategory;
42 import com.owncloud.android.test.ui.groups.InProgressCategory;
43 import com.owncloud.android.test.ui.groups.NoIgnoreTestCategory;
44 import com.owncloud.android.test.ui.groups.SmokeTestCategory;
45 import com.owncloud.android.test.ui.groups.UnfinishedTestCategory;
46 import com.owncloud.android.test.ui.models.FileDetailsView;
47 import com.owncloud.android.test.ui.models.ElementMenuOptions;
48 import com.owncloud.android.test.ui.models.GmailEmailListView;
49 import com.owncloud.android.test.ui.models.GmailEmailView;
50 import com.owncloud.android.test.ui.models.ImageView;
51 import com.owncloud.android.test.ui.models.FileListView;
52 import com.owncloud.android.test.ui.models.NotificationView;
53 import com.owncloud.android.test.ui.models.SettingsView;
54 import com.owncloud.android.test.ui.models.UploadView;
55
56
57 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
58 @Category({NoIgnoreTestCategory.class})
59 public class UploadTestSuite{
60
61 AndroidDriver driver;
62 Common common;
63 String FILE_NAME = Config.fileToTestName;
64 String BIG_FILE_NAME = Config.bigFileToTestName;
65 String FILE_GMAIL_NAME = Config.fileToTestSendByEmailName;
66 private Boolean fileHasBeenUploadedFromGmail = false;
67 private Boolean fileHasBeenUploaded = false;
68
69 @Rule public TestName name = new TestName();
70
71
72 @Before
73 public void setUp() throws Exception {
74 common=new Common();
75 driver=common.setUpCommonDriver();
76 }
77
78 @Test
79 @Category({NoIgnoreTestCategory.class, SmokeTestCategory.class})
80 public void testUploadFile () throws Exception {
81
82 FileListView fileListView = Actions.login(Config.URL, Config.user,
83 Config.password, Config.isTrusted, driver);
84 common.assertIsInFileListView();
85
86 //check if the file already exists and if true, delete it
87 Actions.deleteElement(FILE_NAME, fileListView, driver);
88
89 FileListView fileListViewAfterUploadFile = Actions
90 .uploadFile(FILE_NAME, fileListView);
91
92 fileListViewAfterUploadFile.scrollTillFindElement(FILE_NAME);
93 assertTrue(fileListViewAfterUploadFile.getFileElement().isDisplayed());
94 Common.waitTillElementIsNotPresentWithoutTimeout(
95 fileListViewAfterUploadFile.getProgressCircular(), 1000);
96 common.wait.until(ExpectedConditions.visibilityOf(
97 fileListViewAfterUploadFile.getFileElementLayout()
98 .findElement(By.id(FileListView.getLocalFileIndicator()))));
99 assertTrue(fileListViewAfterUploadFile.getFileElementLayout()
100 .findElement(By.id(FileListView.getLocalFileIndicator()))
101 .isDisplayed());
102 fileListView = new FileListView(driver);
103 fileListView.scrollTillFindElement(FILE_NAME);
104 assertTrue(
105 fileHasBeenUploaded = fileListView.getFileElement().isDisplayed());
106 }
107
108 @Test
109 @Category({NoIgnoreTestCategory.class, SmokeTestCategory.class, InProgressCategory.class})
110 public void testUploadBigFile () throws Exception {
111
112 FileListView fileListView = Actions.login(Config.URL, Config.user,
113 Config.password, Config.isTrusted, driver);
114 common.assertIsInFileListView();
115
116 //check if the file already exists and if true, delete it
117 Actions.deleteElement(BIG_FILE_NAME, fileListView, driver);
118
119 FileListView fileListViewAfterUploadFile = Actions
120 .uploadFile(BIG_FILE_NAME, fileListView);
121
122 fileListViewAfterUploadFile.scrollTillFindElement(BIG_FILE_NAME);
123 driver.openNotifications();
124 NotificationView notificationView = new NotificationView(driver);
125
126 try{
127 if(notificationView.getUploadingNotification().isDisplayed()){
128 Common.waitTillElementIsPresent(
129 notificationView.getUploadSucceededNotification(),1000);
130 }
131 } catch (NoSuchElementException e) {
132 try{
133 if(notificationView.getClearAllNotificationButton().isDisplayed()){
134 notificationView.tapOnClearAllNotification();
135 }
136 } catch (NoSuchElementException e2) {
137 notificationView.tapOnBottomNotificationArea();
138 }
139 }
140
141
142
143
144 //fileListViewAfterUploadFile.pulldownToSeeNotification();
145
146 assertTrue(fileListViewAfterUploadFile.getFileElement().isDisplayed());
147 Common.waitTillElementIsNotPresentWithoutTimeout(
148 fileListViewAfterUploadFile.getProgressCircular(), 1000);
149 common.wait.until(ExpectedConditions.visibilityOf(
150 fileListViewAfterUploadFile.getFileElementLayout()
151 .findElement(By.id(FileListView.getLocalFileIndicator()))));
152 assertTrue(fileListViewAfterUploadFile.getFileElementLayout()
153 .findElement(By.id(FileListView.getLocalFileIndicator()))
154 .isDisplayed());
155 fileListView = new FileListView(driver);
156 fileListView.scrollTillFindElement(BIG_FILE_NAME);
157 assertTrue(
158 fileHasBeenUploaded = fileListView.getFileElement().isDisplayed());
159 }
160
161 @Test
162 @Category(UnfinishedTestCategory.class)
163 public void testUploadFromGmail () throws Exception {
164 FileListView fileListView = Actions.login(Config.URL, Config.user,
165 Config.password, Config.isTrusted, driver);
166 driver.startActivity("com.google.android.gm",
167 ".ConversationListActivityGmail");
168 GmailEmailListView gmailEmailListView = new GmailEmailListView(driver);
169 Thread.sleep(3000);
170 GmailEmailView gmailEmailView = gmailEmailListView.clickOnEmail();
171 ImageView imageView = gmailEmailView.clickOnfileButton();
172 imageView.clickOnOptionsButton();
173 imageView.clickOnShareButton();
174 imageView.clickOnOwnCloudButton();
175 //justonce button do not appear always
176 try{
177 imageView.clickOnJustOnceButton();
178 }catch (NoSuchElementException e) {
179 }
180 UploadView uploadView = new UploadView(driver);
181 uploadView.clickOUploadButton();
182 driver.sendKeyEvent(android.view.KeyEvent.KEYCODE_HOME);
183 driver.startActivity("com.owncloud.android",
184 ".ui.activity.FileDisplayActivity");
185 common.wait.until(ExpectedConditions
186 .visibilityOfAllElementsLocatedBy(By.name(FILE_GMAIL_NAME)));
187 assertEquals(Config.fileToTestSendByEmailName ,
188 driver.findElementByName(FILE_GMAIL_NAME).getText());
189 fileListView = new FileListView(driver);
190 fileListView.scrollTillFindElement(FILE_GMAIL_NAME);
191 assertTrue(fileHasBeenUploadedFromGmail = fileListView
192 .getFileElement().isDisplayed());
193 //TODO. correct assert if fileListView is shown in grid mode
194 }
195
196
197 @Test
198 @Category({FailingTestCategory.class})
199 public void testKeepFileUpToDate () throws Exception {
200
201 FileListView fileListView = Actions.login(Config.URL, Config.user,
202 Config.password, Config.isTrusted, driver);
203 common.assertIsInFileListView();
204
205 Common.waitTillElementIsNotPresentWithoutTimeout(fileListView.getProgressCircular(),
206 1000);
207
208 FileListView fileListViewAfterUploadFile = Actions
209 .uploadFile(FILE_NAME, fileListView);
210 fileListViewAfterUploadFile.scrollTillFindElement(FILE_NAME);
211 assertTrue(fileHasBeenUploaded = fileListViewAfterUploadFile
212 .getFileElement().isDisplayed());
213
214 ElementMenuOptions menuOptions = fileListViewAfterUploadFile
215 .longPressOnElement(FILE_NAME);
216 FileDetailsView fileDetailsView = menuOptions.clickOnDetails();
217 fileDetailsView.checkKeepFileUpToDateCheckbox();
218 Thread.sleep(3000);
219 driver.sendKeyEvent(android.view.KeyEvent.KEYCODE_BACK);
220 assertTrue(common.isElementPresent(
221 fileListViewAfterUploadFile.getFileElementLayout(),
222 MobileBy.id(FileListView.getFavoriteFileIndicator())));
223 assertTrue(fileListViewAfterUploadFile.getFileElementLayout()
224 .findElement(By.id(FileListView.getFavoriteFileIndicator()))
225 .isDisplayed());
226 }
227
228 @Test
229 @Category({NoIgnoreTestCategory.class})
230 public void testKeepFileUpToDateAndRefresh () throws Exception {
231
232 FileListView fileListView = Actions.login(Config.URL, Config.user,
233 Config.password, Config.isTrusted, driver);
234 common.assertIsInFileListView();
235
236 Common.waitTillElementIsNotPresentWithoutTimeout(fileListView.getProgressCircular(),
237 1000);
238
239 FileListView fileListViewAfterUploadFile = Actions
240 .uploadFile(FILE_NAME, fileListView);
241 fileListViewAfterUploadFile.scrollTillFindElement(FILE_NAME);
242 assertTrue(fileHasBeenUploaded = fileListViewAfterUploadFile
243 .getFileElement().isDisplayed());
244
245 ElementMenuOptions menuOptions = fileListViewAfterUploadFile
246 .longPressOnElement(FILE_NAME);
247 FileDetailsView fileDetailsView = menuOptions.clickOnDetails();
248 fileDetailsView.checkKeepFileUpToDateCheckbox();
249 Thread.sleep(3000);
250 driver.sendKeyEvent(android.view.KeyEvent.KEYCODE_BACK);
251
252 fileListViewAfterUploadFile.pulldownToRefresh();
253 //assertTrue(fileListView.getProgressCircular().isDisplayed());
254 Common.waitTillElementIsNotPresentWithoutTimeout(fileListView.getProgressCircular(),
255 100);
256
257 assertTrue(common.isElementPresent(
258 fileListViewAfterUploadFile.getFileElementLayout(),
259 MobileBy.id(FileListView.getFavoriteFileIndicator())));
260 assertTrue(fileListViewAfterUploadFile.getFileElementLayout()
261 .findElement(By.id(FileListView.getFavoriteFileIndicator()))
262 .isDisplayed());
263 }
264
265
266 @After
267 public void tearDown() throws Exception {
268 common.takeScreenShotOnFailed(name.getMethodName());
269 FileListView fileListView = new FileListView(driver);
270 if (fileHasBeenUploadedFromGmail) {
271 Actions.deleteElement(FILE_GMAIL_NAME,fileListView, driver);
272 }
273 if(fileHasBeenUploaded){
274 Actions.deleteElement(FILE_NAME,fileListView, driver);
275 Actions.deleteElement(BIG_FILE_NAME,fileListView, driver);
276 }
277
278 driver.removeApp("com.owncloud.android");
279 driver.quit();
280 }
281
282
283 }
284