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
.NoIgnoreTestCategory
;
44 import com
.owncloud
.android
.test
.ui
.groups
.UnfinishedTestCategory
;
45 import com
.owncloud
.android
.test
.ui
.models
.FileDetailsView
;
46 import com
.owncloud
.android
.test
.ui
.models
.ElementMenuOptions
;
47 import com
.owncloud
.android
.test
.ui
.models
.GmailEmailListView
;
48 import com
.owncloud
.android
.test
.ui
.models
.GmailEmailView
;
49 import com
.owncloud
.android
.test
.ui
.models
.ImageView
;
50 import com
.owncloud
.android
.test
.ui
.models
.FileListView
;
51 import com
.owncloud
.android
.test
.ui
.models
.UploadView
;
54 @FixMethodOrder(MethodSorters
.NAME_ASCENDING
)
55 @Category({NoIgnoreTestCategory
.class})
56 public class UploadTestSuite
{
60 String FILE_NAME
= Config
.fileToTestName
;
61 String FILE_GMAIL_NAME
= Config
.fileToTestSendByEmailName
;
62 private Boolean fileHasBeenUploadedFromGmail
= false
;
63 private Boolean fileHasBeenUploaded
= false
;
65 @Rule public TestName name
= new TestName();
69 public void setUp() throws Exception
{
71 driver
=common
.setUpCommonDriver();
75 @Category(NoIgnoreTestCategory
.class)
76 public void testUploadFile () throws Exception
{
78 FileListView fileListView
= Actions
.login(Config
.URL
, Config
.user
,
79 Config
.password
, Config
.isTrusted
, driver
);
80 common
.assertIsInFileListView();
82 //check if the file already exists and if true, delete it
83 Actions
.deleteElement(FILE_NAME
, fileListView
, driver
);
85 FileListView fileListViewAfterUploadFile
= Actions
86 .uploadFile(FILE_NAME
, fileListView
);
88 fileListViewAfterUploadFile
.scrollTillFindElement(FILE_NAME
);
89 assertTrue(fileListViewAfterUploadFile
.getFileElement().isDisplayed());
90 Common
.waitTillElementIsNotPresent(
91 fileListViewAfterUploadFile
.getProgressCircular(), 1000);
92 common
.wait
.until(ExpectedConditions
.visibilityOf(
93 fileListViewAfterUploadFile
.getFileElementLayout()
94 .findElement(By
.id(FileListView
.getLocalFileIndicator()))));
95 assertTrue(fileListViewAfterUploadFile
.getFileElementLayout()
96 .findElement(By
.id(FileListView
.getLocalFileIndicator()))
98 fileListView
= new FileListView(driver
);
99 fileListView
.scrollTillFindElement(FILE_NAME
);
101 fileHasBeenUploaded
= fileListView
.getFileElement().isDisplayed());
105 @Category(UnfinishedTestCategory
.class)
106 public void testUploadFromGmail () throws Exception
{
107 FileListView fileListView
= Actions
.login(Config
.URL
, Config
.user
,
108 Config
.password
, Config
.isTrusted
, driver
);
109 driver
.startActivity("com.google.android.gm",
110 ".ConversationListActivityGmail");
111 GmailEmailListView gmailEmailListView
= new GmailEmailListView(driver
);
113 GmailEmailView gmailEmailView
= gmailEmailListView
.clickOnEmail();
114 ImageView imageView
= gmailEmailView
.clickOnfileButton();
115 imageView
.clickOnOptionsButton();
116 imageView
.clickOnShareButton();
117 imageView
.clickOnOwnCloudButton();
118 //justonce button do not appear always
120 imageView
.clickOnJustOnceButton();
121 }catch (NoSuchElementException e
) {
123 UploadView uploadView
= new UploadView(driver
);
124 uploadView
.clickOUploadButton();
125 driver
.sendKeyEvent(android
.view
.KeyEvent
.KEYCODE_HOME
);
126 driver
.startActivity("com.owncloud.android",
127 ".ui.activity.FileDisplayActivity");
128 common
.wait
.until(ExpectedConditions
129 .visibilityOfAllElementsLocatedBy(By
.name(FILE_GMAIL_NAME
)));
130 assertEquals(Config
.fileToTestSendByEmailName
,
131 driver
.findElementByName(FILE_GMAIL_NAME
).getText());
132 fileListView
= new FileListView(driver
);
133 fileListView
.scrollTillFindElement(FILE_GMAIL_NAME
);
134 assertTrue(fileHasBeenUploadedFromGmail
= fileListView
135 .getFileElement().isDisplayed());
136 //TODO. correct assert if fileListView is shown in grid mode
141 @Category({FailingTestCategory
.class})
142 public void testKeepFileUpToDate () throws Exception
{
144 FileListView fileListView
= Actions
.login(Config
.URL
, Config
.user
,
145 Config
.password
, Config
.isTrusted
, driver
);
146 common
.assertIsInFileListView();
148 Common
.waitTillElementIsNotPresent(fileListView
.getProgressCircular(),
151 FileListView fileListViewAfterUploadFile
= Actions
152 .uploadFile(FILE_NAME
, fileListView
);
153 fileListViewAfterUploadFile
.scrollTillFindElement(FILE_NAME
);
154 assertTrue(fileListViewAfterUploadFile
.getFileElement().isDisplayed());
156 ElementMenuOptions menuOptions
= fileListViewAfterUploadFile
157 .longPressOnElement(FILE_NAME
);
158 FileDetailsView fileDetailsView
= menuOptions
.clickOnDetails();
159 fileDetailsView
.checkKeepFileUpToDateCheckbox();
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()))
172 public void tearDown() throws Exception
{
173 common
.takeScreenShotOnFailed(name
.getMethodName());
174 FileListView fileListView
= new FileListView(driver
);
175 if (fileHasBeenUploadedFromGmail
) {
176 Actions
.deleteElement(FILE_GMAIL_NAME
,fileListView
, driver
);
178 if(fileHasBeenUploaded
){
179 Actions
.deleteElement(FILE_NAME
,fileListView
, driver
);
182 driver
.removeApp("com.owncloud.android");