287b43da00822fc79b8ae71e1baefe5a8662a434
[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
109
110 @Test
111 @Category({UnfinishedTestCategory.class, InProgressCategory.class})
112 public void testUploadBigFile () throws Exception {
113
114 FileListView fileListView = Actions.login(Config.URL, Config.user,
115 Config.password, Config.isTrusted, driver);
116 common.assertIsInFileListView();
117
118 //check if the file already exists and if true, delete it
119 Actions.deleteElement(BIG_FILE_NAME, fileListView, driver);
120
121 FileListView fileListViewAfterUploadFile = Actions
122 .uploadFile(BIG_FILE_NAME, fileListView);
123
124
125 driver.openNotifications();
126 NotificationView notificationView = new NotificationView(driver);
127
128 try{
129 if(notificationView.getUploadingNotification().isDisplayed()){
130 Common.waitTillElementIsPresent(
131 notificationView.getUploadSucceededNotification(),300000);
132 driver.sendKeyEvent(android.view.KeyEvent.KEYCODE_HOME);
133 driver.startActivity("com.owncloud.android",
134 ".ui.activity.FileDisplayActivity");
135
136 }
137 } catch (NoSuchElementException e) {
138 driver.sendKeyEvent(android.view.KeyEvent.KEYCODE_HOME);
139 driver.startActivity("com.owncloud.android",
140 ".ui.activity.FileDisplayActivity");
141 }
142
143 fileListViewAfterUploadFile.scrollTillFindElement(BIG_FILE_NAME);
144
145 assertTrue(fileListViewAfterUploadFile.getFileElement().isDisplayed());
146
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
162 @Test
163 @Category(UnfinishedTestCategory.class)
164 public void testUploadFromGmail () throws Exception {
165 FileListView fileListView = Actions.login(Config.URL, Config.user,
166 Config.password, Config.isTrusted, driver);
167 driver.startActivity("com.google.android.gm",
168 ".ConversationListActivityGmail");
169 GmailEmailListView gmailEmailListView = new GmailEmailListView(driver);
170 Thread.sleep(3000);
171 GmailEmailView gmailEmailView = gmailEmailListView.clickOnEmail();
172 ImageView imageView = gmailEmailView.clickOnfileButton();
173 imageView.clickOnOptionsButton();
174 imageView.clickOnShareButton();
175 imageView.clickOnOwnCloudButton();
176 //justonce button do not appear always
177 try{
178 imageView.clickOnJustOnceButton();
179 }catch (NoSuchElementException e) {
180 }
181 UploadView uploadView = new UploadView(driver);
182 uploadView.clickOUploadButton();
183 driver.sendKeyEvent(android.view.KeyEvent.KEYCODE_HOME);
184 driver.startActivity("com.owncloud.android",
185 ".ui.activity.FileDisplayActivity");
186 common.wait.until(ExpectedConditions
187 .visibilityOfAllElementsLocatedBy(By.name(FILE_GMAIL_NAME)));
188 assertEquals(Config.fileToTestSendByEmailName ,
189 driver.findElementByName(FILE_GMAIL_NAME).getText());
190 fileListView = new FileListView(driver);
191 fileListView.scrollTillFindElement(FILE_GMAIL_NAME);
192 assertTrue(fileHasBeenUploadedFromGmail = fileListView
193 .getFileElement().isDisplayed());
194 //TODO. correct assert if fileListView is shown in grid mode
195 }
196
197
198 @Test
199 @Category({FailingTestCategory.class})
200 public void testKeepFileUpToDate () throws Exception {
201
202 FileListView fileListView = Actions.login(Config.URL, Config.user,
203 Config.password, Config.isTrusted, driver);
204 common.assertIsInFileListView();
205
206 Common.waitTillElementIsNotPresentWithoutTimeout(fileListView.getProgressCircular(),
207 1000);
208
209 FileListView fileListViewAfterUploadFile = Actions
210 .uploadFile(FILE_NAME, fileListView);
211 fileListViewAfterUploadFile.scrollTillFindElement(FILE_NAME);
212 assertTrue(fileHasBeenUploaded = fileListViewAfterUploadFile
213 .getFileElement().isDisplayed());
214
215 ElementMenuOptions menuOptions = fileListViewAfterUploadFile
216 .longPressOnElement(FILE_NAME);
217 FileDetailsView fileDetailsView = menuOptions.clickOnDetails();
218 fileDetailsView.checkKeepFileUpToDateCheckbox();
219 Thread.sleep(3000);
220 driver.sendKeyEvent(android.view.KeyEvent.KEYCODE_BACK);
221 assertTrue(common.isElementPresent(
222 fileListViewAfterUploadFile.getFileElementLayout(),
223 MobileBy.id(FileListView.getFavoriteFileIndicator())));
224 assertTrue(fileListViewAfterUploadFile.getFileElementLayout()
225 .findElement(By.id(FileListView.getFavoriteFileIndicator()))
226 .isDisplayed());
227 }
228
229 @Test
230 @Category({NoIgnoreTestCategory.class})
231 public void testKeepFileUpToDateAndRefresh () throws Exception {
232
233 FileListView fileListView = Actions.login(Config.URL, Config.user,
234 Config.password, Config.isTrusted, driver);
235 common.assertIsInFileListView();
236
237 Common.waitTillElementIsNotPresentWithoutTimeout(fileListView.getProgressCircular(),
238 1000);
239
240 FileListView fileListViewAfterUploadFile = Actions
241 .uploadFile(FILE_NAME, fileListView);
242 fileListViewAfterUploadFile.scrollTillFindElement(FILE_NAME);
243 assertTrue(fileHasBeenUploaded = fileListViewAfterUploadFile
244 .getFileElement().isDisplayed());
245
246 ElementMenuOptions menuOptions = fileListViewAfterUploadFile
247 .longPressOnElement(FILE_NAME);
248 FileDetailsView fileDetailsView = menuOptions.clickOnDetails();
249 fileDetailsView.checkKeepFileUpToDateCheckbox();
250 Thread.sleep(3000);
251 driver.sendKeyEvent(android.view.KeyEvent.KEYCODE_BACK);
252
253 fileListViewAfterUploadFile.pulldownToRefresh();
254 //assertTrue(fileListView.getProgressCircular().isDisplayed());
255 Common.waitTillElementIsNotPresentWithoutTimeout(fileListView.getProgressCircular(),
256 100);
257
258 assertTrue(common.isElementPresent(
259 fileListViewAfterUploadFile.getFileElementLayout(),
260 MobileBy.id(FileListView.getFavoriteFileIndicator())));
261 assertTrue(fileListViewAfterUploadFile.getFileElementLayout()
262 .findElement(By.id(FileListView.getFavoriteFileIndicator()))
263 .isDisplayed());
264 }
265
266
267 @After
268 public void tearDown() throws Exception {
269 common.takeScreenShotOnFailed(name.getMethodName());
270 FileListView fileListView = new FileListView(driver);
271 if (fileHasBeenUploadedFromGmail) {
272 Actions.deleteElement(FILE_GMAIL_NAME,fileListView, driver);
273 }
274 if(fileHasBeenUploaded){
275 Actions.deleteElement(FILE_NAME,fileListView, driver);
276 Actions.deleteElement(BIG_FILE_NAME,fileListView, driver);
277 }
278
279 //driver.removeApp("com.owncloud.android");
280 driver.quit();
281 }
282
283
284 }
285