2 * ownCloud Android client application
5 * Copyright (C) 2015 ownCloud Inc.
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.
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.
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/>.
21 package com
.owncloud
.android
.test
.ui
.testSuites
;
24 import static org
.junit
.Assert
.*;
25 import io
.appium
.java_client
.MobileBy
;
26 import io
.appium
.java_client
.android
.AndroidDriver
;
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
;
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
;
56 @FixMethodOrder(MethodSorters
.NAME_ASCENDING
)
57 @Category({NoIgnoreTestCategory
.class})
58 public class UploadTestSuite
{
62 String FILE_NAME
= Config
.fileToTestName
;
63 String FILE_GMAIL_NAME
= Config
.fileToTestSendByEmailName
;
64 private Boolean fileHasBeenUploadedFromGmail
= false
;
65 private Boolean fileHasBeenUploaded
= false
;
67 @Rule public TestName name
= new TestName();
71 public void setUp() throws Exception
{
73 driver
=common
.setUpCommonDriver();
77 @Category({NoIgnoreTestCategory
.class, SmokeTestCategory
.class})
78 public void testUploadFile () throws Exception
{
80 FileListView fileListView
= Actions
.login(Config
.URL
, Config
.user
,
81 Config
.password
, Config
.isTrusted
, driver
);
82 common
.assertIsInFileListView();
84 //check if the file already exists and if true, delete it
85 Actions
.deleteElement(FILE_NAME
, fileListView
, driver
);
87 FileListView fileListViewAfterUploadFile
= Actions
88 .uploadFile(FILE_NAME
, fileListView
);
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()))
100 fileListView
= new FileListView(driver
);
101 fileListView
.scrollTillFindElement(FILE_NAME
);
103 fileHasBeenUploaded
= fileListView
.getFileElement().isDisplayed());
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
);
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
122 imageView
.clickOnJustOnceButton();
123 }catch (NoSuchElementException e
) {
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
143 @Category({FailingTestCategory
.class})
144 public void testKeepFileUpToDate () throws Exception
{
146 FileListView fileListView
= Actions
.login(Config
.URL
, Config
.user
,
147 Config
.password
, Config
.isTrusted
, driver
);
148 common
.assertIsInFileListView();
150 Common
.waitTillElementIsNotPresent(fileListView
.getProgressCircular(),
153 FileListView fileListViewAfterUploadFile
= Actions
154 .uploadFile(FILE_NAME
, fileListView
);
155 fileListViewAfterUploadFile
.scrollTillFindElement(FILE_NAME
);
156 assertTrue(fileHasBeenUploaded
= fileListViewAfterUploadFile
157 .getFileElement().isDisplayed());
159 ElementMenuOptions menuOptions
= fileListViewAfterUploadFile
160 .longPressOnElement(FILE_NAME
);
161 FileDetailsView fileDetailsView
= menuOptions
.clickOnDetails();
162 fileDetailsView
.checkKeepFileUpToDateCheckbox();
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()))
174 @Category({NoIgnoreTestCategory
.class})
175 public void testKeepFileUpToDateAndRefresh () throws Exception
{
177 FileListView fileListView
= Actions
.login(Config
.URL
, Config
.user
,
178 Config
.password
, Config
.isTrusted
, driver
);
179 common
.assertIsInFileListView();
181 Common
.waitTillElementIsNotPresent(fileListView
.getProgressCircular(),
184 FileListView fileListViewAfterUploadFile
= Actions
185 .uploadFile(FILE_NAME
, fileListView
);
186 fileListViewAfterUploadFile
.scrollTillFindElement(FILE_NAME
);
187 assertTrue(fileHasBeenUploaded
= fileListViewAfterUploadFile
188 .getFileElement().isDisplayed());
190 ElementMenuOptions menuOptions
= fileListViewAfterUploadFile
191 .longPressOnElement(FILE_NAME
);
192 FileDetailsView fileDetailsView
= menuOptions
.clickOnDetails();
193 fileDetailsView
.checkKeepFileUpToDateCheckbox();
195 driver
.sendKeyEvent(android
.view
.KeyEvent
.KEYCODE_BACK
);
197 fileListViewAfterUploadFile
.pulldownToRefresh();
198 //assertTrue(fileListView.getProgressCircular().isDisplayed());
199 Common
.waitTillElementIsNotPresent(fileListView
.getProgressCircular(),
202 assertTrue(common
.isElementPresent(
203 fileListViewAfterUploadFile
.getFileElementLayout(),
204 MobileBy
.id(FileListView
.getFavoriteFileIndicator())));
205 assertTrue(fileListViewAfterUploadFile
.getFileElementLayout()
206 .findElement(By
.id(FileListView
.getFavoriteFileIndicator()))
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
);
218 if(fileHasBeenUploaded
){
219 Actions
.deleteElement(FILE_NAME
,fileListView
, driver
);
222 driver
.removeApp("com.owncloud.android");