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
.actions
;
23 import java
.util
.HashMap
;
25 import org
.openqa
.selenium
.By
;
26 import org
.openqa
.selenium
.NoSuchElementException
;
27 import org
.openqa
.selenium
.ScreenOrientation
;
28 import org
.openqa
.selenium
.remote
.RemoteWebElement
;
29 import io
.appium
.java_client
.android
.AndroidDriver
;
30 import io
.appium
.java_client
.android
.AndroidElement
;
31 import org
.openqa
.selenium
.support
.ui
.ExpectedConditions
;
32 import org
.openqa
.selenium
.support
.ui
.WebDriverWait
;
33 import com
.owncloud
.android
.test
.ui
.models
.CertificatePopUp
;
34 import com
.owncloud
.android
.test
.ui
.models
.ElementMenuOptions
;
35 import com
.owncloud
.android
.test
.ui
.models
.GmailSendMailView
;
36 import com
.owncloud
.android
.test
.ui
.models
.ShareView
;
37 import com
.owncloud
.android
.test
.ui
.models
.UploadFilesView
;
38 import com
.owncloud
.android
.test
.ui
.models
.LoginForm
;
39 import com
.owncloud
.android
.test
.ui
.models
.FileListView
;
40 import com
.owncloud
.android
.test
.ui
.models
.MenuList
;
41 import com
.owncloud
.android
.test
.ui
.models
.NewFolderPopUp
;
42 import com
.owncloud
.android
.test
.ui
.models
.RemoveConfirmationView
;
43 import com
.owncloud
.android
.test
.ui
.models
.SettingsView
;
44 import com
.owncloud
.android
.test
.ui
.models
.WaitAMomentPopUp
;
45 import com
.owncloud
.android
.test
.ui
.testSuites
.Common
;
46 import com
.owncloud
.android
.test
.ui
.testSuites
.Config
;
48 public class Actions
{
50 public static FileListView
login(String url
, String user
, String password
,
51 Boolean isTrusted
, AndroidDriver driver
)
52 throws InterruptedException
{
53 LoginForm loginForm
= new LoginForm(driver
);
54 CertificatePopUp certificatePopUp
= loginForm
.typeHostUrl(url
);
56 WebDriverWait wait
= new WebDriverWait(driver
, 30);
57 //sometimes the certificate has been already accept
58 //and it doesn't appear again
60 wait
.until(ExpectedConditions
61 .visibilityOf(certificatePopUp
.getOkButtonElement()));
62 //we need to repaint the screen
63 //because of some element are misplaced
64 driver
.rotate(ScreenOrientation
.LANDSCAPE
);
65 driver
.rotate(ScreenOrientation
.PORTRAIT
);
66 certificatePopUp
.clickOnOkButton();
67 }catch (NoSuchElementException e
) {
72 loginForm
.typeUserName(user
);
73 loginForm
.typePassword(password
);
74 //TODO. Assert related to check the connection?
75 return loginForm
.clickOnConnectButton();
78 public static WaitAMomentPopUp
createFolder(String folderName
,
79 FileListView fileListView
){
80 NewFolderPopUp newFolderPopUp
= fileListView
.clickOnNewFolderButton();
81 newFolderPopUp
.typeNewFolderName(folderName
);
82 WaitAMomentPopUp waitAMomentPopUp
= newFolderPopUp
83 .clickOnNewFolderOkButton();
85 return waitAMomentPopUp
;
89 public static AndroidElement
scrollTillFindElement (String elementName
,
90 AndroidElement element
, AndroidDriver driver
) {
91 AndroidElement fileElement
;
93 if(element
.getAttribute("scrollable").equals("true")){
94 HashMap
<String
, String
> scrollObject
= new HashMap
<String
,String
>();
95 scrollObject
.put("text", elementName
);
96 scrollObject
.put("element", ( (RemoteWebElement
) element
).getId());
97 driver
.executeScript("mobile: scrollTo", scrollObject
);
100 fileElement
= (AndroidElement
) driver
101 .findElementByName(elementName
);
102 } catch (NoSuchElementException e
) {
109 public static void deleteAccount (FileListView fileListView
) {
110 MenuList menulist
= fileListView
.clickOnMenuButton();
111 SettingsView settingView
= menulist
.clickOnSettingsButton();
112 deleteAccount(settingView
);
115 public static void deleteAccount (SettingsView settingsView
) {
116 settingsView
.tapOnAccountElement(1, 1000);
117 settingsView
.clickOnDeleteAccountElement();
120 public static void clickOnMainLayout(AndroidDriver driver
){
121 driver
.tap(1, 0, 0, 1);
125 public static AndroidElement
deleteElement(String elementName
,
126 FileListView fileListView
, AndroidDriver driver
) throws Exception
{
127 AndroidElement fileElement
;
128 WaitAMomentPopUp waitAMomentPopUp
;
130 //To open directly the "file list view" and
131 //we don't need to know in which view we are
132 driver
.startActivity("com.owncloud.android",
133 ".ui.activity.FileDisplayActivity");
134 fileElement
= (AndroidElement
) driver
135 .findElementByName(elementName
);
136 ElementMenuOptions menuOptions
= fileListView
137 .longPressOnElement(elementName
);
138 RemoveConfirmationView removeConfirmationView
= menuOptions
140 waitAMomentPopUp
= removeConfirmationView
141 .clickOnRemoteAndLocalButton();
142 Common
.waitTillElementIsNotPresent(
143 waitAMomentPopUp
.getWaitAMomentTextElement(), 100);
144 }catch(NoSuchElementException e
){
150 public static AndroidElement
shareLinkElementByGmail(String elementName
,
151 FileListView fileListView
, AndroidDriver driver
, Common common
)
154 //To open directly the "file list view" and
155 //we don't need to know in which view we are
156 driver
.startActivity("com.owncloud.android",
157 ".ui.activity.FileDisplayActivity");
158 ElementMenuOptions menuOptions
= fileListView
159 .longPressOnElement(elementName
);
160 ShareView shareView
= menuOptions
.clickOnShareLinkElement();
161 Actions
.scrollTillFindElement("Gmail", shareView
162 .getListViewLayout(), driver
).click();
163 GmailSendMailView gmailSendMailView
= new GmailSendMailView(driver
);
164 gmailSendMailView
.typeToEmailAdress(Config
.gmailAccount
);
165 gmailSendMailView
.clickOnSendButton();
166 Common
.waitTillElementIsNotPresentWithoutTimeout(fileListView
167 .getProgressCircular(), 1000);
168 common
.wait
.until(ExpectedConditions
.visibilityOf(
169 fileListView
.getFileElementLayout()
170 .findElement(By
.id(FileListView
171 .getSharedElementIndicator()))));
173 }catch(NoSuchElementException e
){
176 return (AndroidElement
) fileListView
.getFileElementLayout()
177 .findElement(By
.id(FileListView
.getSharedElementIndicator()));
180 public static AndroidElement
shareLinkElementByCopyLink(String elementName
,
181 FileListView fileListView
, AndroidDriver driver
, Common common
)
184 //To open directly the "file list view" and
185 //we don't need to know in which view we are
186 driver
.startActivity("com.owncloud.android",
187 ".ui.activity.FileDisplayActivity");
188 ElementMenuOptions menuOptions
= fileListView
189 .longPressOnElement(elementName
);
190 ShareView shareView
= menuOptions
.clickOnShareLinkElement();
191 Actions
.scrollTillFindElement("Copy link", shareView
.getListViewLayout(),
193 WaitAMomentPopUp waitAMomentPopUp
= new WaitAMomentPopUp(driver
);
194 Common
.waitTillElementIsNotPresentWithoutTimeout(waitAMomentPopUp
195 .getWaitAMomentTextElement(), 100);
196 common
.wait
.until(ExpectedConditions
.visibilityOf(
197 fileListView
.getFileElementLayout()
198 .findElement(By
.id(FileListView
.getSharedElementIndicator()))));
199 }catch(NoSuchElementException e
){
202 return (AndroidElement
) fileListView
.getFileElementLayout()
203 .findElement(By
.id(FileListView
.getSharedElementIndicator()));
207 public static void unshareLinkElement(String elementName
,
208 FileListView fileListView
, AndroidDriver driver
, Common common
)
211 //To open directly the "file list view" and
212 //we don't need to know in which view we are
213 driver
.startActivity("com.owncloud.android",
214 ".ui.activity.FileDisplayActivity");
215 ElementMenuOptions menuOptions
= fileListView
216 .longPressOnElement(elementName
);
217 WaitAMomentPopUp waitAMomentPopUp
= menuOptions
218 .clickOnUnshareLinkElement();
219 Common
.waitTillElementIsNotPresentWithoutTimeout(waitAMomentPopUp
220 .getWaitAMomentTextElement(), 100);
221 Common
.waitTillElementIsNotPresent((AndroidElement
) fileListView
222 .getFileElementLayout()
223 .findElement(By
.id(FileListView
.getSharedElementIndicator())
225 }catch(NoSuchElementException e
){
231 public static FileListView
uploadFile(String elementName
,
232 FileListView fileListView
) throws InterruptedException
{
233 fileListView
.clickOnUploadButton();
234 UploadFilesView uploadFilesView
= fileListView
235 .clickOnFilesElementUploadFile();
236 uploadFilesView
.clickOnFileName(elementName
);
237 FileListView fileListViewAfterUploadFile
= uploadFilesView
238 .clickOnUploadButton();
239 //TO DO. detect when the file is successfully uploaded
241 return fileListViewAfterUploadFile
;