cf8f84d06ac25b7fe0afcdce85619a8ba3618ac4
[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 import com.owncloud.android.test.ui.actions.Actions;
40 import com.owncloud.android.test.ui.groups.FailingTestCategory;
41 import com.owncloud.android.test.ui.groups.NoIgnoreTestCategory;
42 import com.owncloud.android.test.ui.groups.SmokeTestCategory;
43 import com.owncloud.android.test.ui.groups.UnfinishedTestCategory;
44 import com.owncloud.android.test.ui.models.FileDetailsView;
45 import com.owncloud.android.test.ui.models.ElementMenuOptions;
46 import com.owncloud.android.test.ui.models.GmailEmailListView;
47 import com.owncloud.android.test.ui.models.GmailEmailView;
48 import com.owncloud.android.test.ui.models.ImageView;
49 import com.owncloud.android.test.ui.models.FileListView;
50 import com.owncloud.android.test.ui.models.UploadView;
51
52
53 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
54 @Category({NoIgnoreTestCategory.class})
55 public class UploadTestSuite{
56
57 AndroidDriver driver;
58 Common common;
59 String FILE_NAME = Config.fileToTestName;
60 String FILE_GMAIL_NAME = Config.fileToTestSendByEmailName;
61 private Boolean fileHasBeenUploadedFromGmail = false;
62 private Boolean fileHasBeenUploaded = false;
63
64 @Rule public TestName name = new TestName();
65
66
67 @Before
68 public void setUp() throws Exception {
69 common=new Common();
70 driver=common.setUpCommonDriver();
71 }
72
73 @Test
74 @Category({NoIgnoreTestCategory.class, SmokeTestCategory.class})
75 public void testUploadFile () throws Exception {
76
77 FileListView fileListView = Actions.login(Config.URL, Config.user,
78 Config.password, Config.isTrusted, driver);
79 common.assertIsInFileListView();
80
81 //check if the file already exists and if true, delete it
82 Actions.deleteElement(FILE_NAME, fileListView, driver);
83
84 FileListView fileListViewAfterUploadFile = Actions
85 .uploadFile(FILE_NAME, fileListView);
86
87 fileListViewAfterUploadFile.scrollTillFindElement(FILE_NAME);
88 assertTrue(fileListViewAfterUploadFile.getFileElement().isDisplayed());
89 Common.waitTillElementIsNotPresentWithoutTimeout(
90 fileListViewAfterUploadFile.getProgressCircular(), 1000);
91 common.wait.until(ExpectedConditions.visibilityOf(
92 fileListViewAfterUploadFile.getFileElementLayout()
93 .findElement(By.id(FileListView.getLocalFileIndicator()))));
94 assertTrue(fileListViewAfterUploadFile.getFileElementLayout()
95 .findElement(By.id(FileListView.getLocalFileIndicator()))
96 .isDisplayed());
97 fileListView = new FileListView(driver);
98 fileListView.scrollTillFindElement(FILE_NAME);
99 assertTrue(
100 fileHasBeenUploaded = fileListView.getFileElement().isDisplayed());
101 }
102
103 @Test
104 @Category(UnfinishedTestCategory.class)
105 public void testUploadFromGmail () throws Exception {
106 FileListView fileListView = Actions.login(Config.URL, Config.user,
107 Config.password, Config.isTrusted, driver);
108 driver.startActivity("com.google.android.gm",
109 ".ConversationListActivityGmail");
110 GmailEmailListView gmailEmailListView = new GmailEmailListView(driver);
111 Thread.sleep(3000);
112 GmailEmailView gmailEmailView = gmailEmailListView.clickOnEmail();
113 ImageView imageView = gmailEmailView.clickOnfileButton();
114 imageView.clickOnOptionsButton();
115 imageView.clickOnShareButton();
116 imageView.clickOnOwnCloudButton();
117 //justonce button do not appear always
118 try{
119 imageView.clickOnJustOnceButton();
120 }catch (NoSuchElementException e) {
121 }
122 UploadView uploadView = new UploadView(driver);
123 uploadView.clickOUploadButton();
124 driver.sendKeyEvent(android.view.KeyEvent.KEYCODE_HOME);
125 driver.startActivity("com.owncloud.android",
126 ".ui.activity.FileDisplayActivity");
127 common.wait.until(ExpectedConditions
128 .visibilityOfAllElementsLocatedBy(By.name(FILE_GMAIL_NAME)));
129 assertEquals(Config.fileToTestSendByEmailName ,
130 driver.findElementByName(FILE_GMAIL_NAME).getText());
131 fileListView = new FileListView(driver);
132 fileListView.scrollTillFindElement(FILE_GMAIL_NAME);
133 assertTrue(fileHasBeenUploadedFromGmail = fileListView
134 .getFileElement().isDisplayed());
135 //TODO. correct assert if fileListView is shown in grid mode
136 }
137
138
139 @Test
140 @Category({FailingTestCategory.class})
141 public void testKeepFileUpToDate () throws Exception {
142
143 FileListView fileListView = Actions.login(Config.URL, Config.user,
144 Config.password, Config.isTrusted, driver);
145 common.assertIsInFileListView();
146
147 Common.waitTillElementIsNotPresentWithoutTimeout(fileListView.getProgressCircular(),
148 1000);
149
150 FileListView fileListViewAfterUploadFile = Actions
151 .uploadFile(FILE_NAME, fileListView);
152 fileListViewAfterUploadFile.scrollTillFindElement(FILE_NAME);
153 assertTrue(fileHasBeenUploaded = fileListViewAfterUploadFile
154 .getFileElement().isDisplayed());
155
156 ElementMenuOptions menuOptions = fileListViewAfterUploadFile
157 .longPressOnElement(FILE_NAME);
158 FileDetailsView fileDetailsView = menuOptions.clickOnDetails();
159 fileDetailsView.checkKeepFileUpToDateCheckbox();
160 Thread.sleep(3000);
161 driver.sendKeyEvent(android.view.KeyEvent.KEYCODE_BACK);
162 assertTrue(common.isElementPresent(
163 fileListViewAfterUploadFile.getFileElementLayout(),
164 MobileBy.id(FileListView.getFavoriteFileIndicator())));
165 assertTrue(fileListViewAfterUploadFile.getFileElementLayout()
166 .findElement(By.id(FileListView.getFavoriteFileIndicator()))
167 .isDisplayed());
168 }
169
170 @Test
171 @Category({NoIgnoreTestCategory.class})
172 public void testKeepFileUpToDateAndRefresh () throws Exception {
173
174 FileListView fileListView = Actions.login(Config.URL, Config.user,
175 Config.password, Config.isTrusted, driver);
176 common.assertIsInFileListView();
177
178 Common.waitTillElementIsNotPresentWithoutTimeout(fileListView.getProgressCircular(),
179 1000);
180
181 FileListView fileListViewAfterUploadFile = Actions
182 .uploadFile(FILE_NAME, fileListView);
183 fileListViewAfterUploadFile.scrollTillFindElement(FILE_NAME);
184 assertTrue(fileHasBeenUploaded = fileListViewAfterUploadFile
185 .getFileElement().isDisplayed());
186
187 ElementMenuOptions menuOptions = fileListViewAfterUploadFile
188 .longPressOnElement(FILE_NAME);
189 FileDetailsView fileDetailsView = menuOptions.clickOnDetails();
190 fileDetailsView.checkKeepFileUpToDateCheckbox();
191 Thread.sleep(3000);
192 driver.sendKeyEvent(android.view.KeyEvent.KEYCODE_BACK);
193
194 fileListViewAfterUploadFile.pulldownToRefresh();
195 //assertTrue(fileListView.getProgressCircular().isDisplayed());
196 Common.waitTillElementIsNotPresentWithoutTimeout(fileListView.getProgressCircular(),
197 100);
198
199 assertTrue(common.isElementPresent(
200 fileListViewAfterUploadFile.getFileElementLayout(),
201 MobileBy.id(FileListView.getFavoriteFileIndicator())));
202 assertTrue(fileListViewAfterUploadFile.getFileElementLayout()
203 .findElement(By.id(FileListView.getFavoriteFileIndicator()))
204 .isDisplayed());
205 }
206
207
208 @After
209 public void tearDown() throws Exception {
210 common.takeScreenShotOnFailed(name.getMethodName());
211 FileListView fileListView = new FileListView(driver);
212 if (fileHasBeenUploadedFromGmail) {
213 Actions.deleteElement(FILE_GMAIL_NAME,fileListView, driver);
214 }
215 if(fileHasBeenUploaded){
216 Actions.deleteElement(FILE_NAME,fileListView, driver);
217 }
218
219 driver.removeApp("com.owncloud.android");
220 driver.quit();
221 }
222
223
224 }
225