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