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
.NoSuchElementException
;
26 import org
.openqa
.selenium
.ScreenOrientation
;
27 import org
.openqa
.selenium
.remote
.RemoteWebElement
;
29 import io
.appium
.java_client
.android
.AndroidDriver
;
30 import io
.appium
.java_client
.android
.AndroidElement
;
32 import org
.openqa
.selenium
.support
.ui
.ExpectedConditions
;
33 import org
.openqa
.selenium
.support
.ui
.WebDriverWait
;
35 import com
.owncloud
.android
.test
.ui
.models
.CertificatePopUp
;
36 import com
.owncloud
.android
.test
.ui
.models
.ElementMenuOptions
;
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
;
47 public class Actions
{
49 public static FileListView
login(String url
, String user
, String password
,
50 Boolean isTrusted
, AndroidDriver driver
)
51 throws InterruptedException
{
52 LoginForm loginForm
= new LoginForm(driver
);
53 CertificatePopUp certificatePopUp
= loginForm
.typeHostUrl(url
);
55 WebDriverWait wait
= new WebDriverWait(driver
, 30);
56 //sometimes the certificate has been already accept
57 //and it doesn't appear again
59 wait
.until(ExpectedConditions
60 .visibilityOf(certificatePopUp
.getOkButtonElement()));
61 //we need to repaint the screen
62 //because of some element are misplaced
63 driver
.rotate(ScreenOrientation
.LANDSCAPE
);
64 driver
.rotate(ScreenOrientation
.PORTRAIT
);
65 certificatePopUp
.clickOnOkButton();
66 }catch (NoSuchElementException e
) {
71 loginForm
.typeUserName(user
);
72 loginForm
.typePassword(password
);
73 //TODO. Assert related to check the connection?
74 return loginForm
.clickOnConnectButton();
77 public static WaitAMomentPopUp
createFolder(String folderName
,
78 FileListView fileListView
){
79 NewFolderPopUp newFolderPopUp
= fileListView
.clickOnNewFolderButton();
80 newFolderPopUp
.typeNewFolderName(folderName
);
81 WaitAMomentPopUp waitAMomentPopUp
= newFolderPopUp
82 .clickOnNewFolderOkButton();
84 return waitAMomentPopUp
;
88 public static AndroidElement
scrollTillFindElement (String elementName
,
89 AndroidElement element
, AndroidDriver driver
) {
90 AndroidElement fileElement
;
92 if(element
.getAttribute("scrollable").equals("true")){
93 HashMap
<String
, String
> scrollObject
= new HashMap
<String
,String
>();
94 scrollObject
.put("text", elementName
);
95 scrollObject
.put("element", ( (RemoteWebElement
) element
).getId());
96 driver
.executeScript("mobile: scrollTo", scrollObject
);
99 fileElement
= (AndroidElement
) driver
100 .findElementByName(elementName
);
101 } catch (NoSuchElementException e
) {
108 public static void deleteAccount (FileListView fileListView
) {
109 MenuList menulist
= fileListView
.clickOnMenuButton();
110 SettingsView settingView
= menulist
.clickOnSettingsButton();
111 deleteAccount(settingView
);
114 public static void deleteAccount (SettingsView settingsView
) {
115 settingsView
.tapOnAccountElement(1, 1000);
116 settingsView
.clickOnDeleteAccountElement();
119 public static void clickOnMainLayout(AndroidDriver driver
){
120 driver
.tap(1, 0, 0, 1);
123 //TODO. convert deleteFodler and deleteFile in deleteElement
124 public static AndroidElement
deleteElement(String elementName
,
125 FileListView fileListView
, AndroidDriver driver
) throws Exception
{
126 AndroidElement fileElement
;
127 WaitAMomentPopUp waitAMomentPopUp
;
129 //To open directly the "file list view" and
130 //we don't need to know in which view we are
131 driver
.startActivity("com.owncloud.android",
132 ".ui.activity.FileDisplayActivity");
133 fileElement
= (AndroidElement
) driver
134 .findElementByName(elementName
);
135 ElementMenuOptions menuOptions
= fileListView
136 .longPressOnElement(elementName
);
137 RemoveConfirmationView removeConfirmationView
= menuOptions
139 waitAMomentPopUp
= removeConfirmationView
140 .clickOnRemoteAndLocalButton();
141 Common
.waitTillElementIsNotPresent(
142 waitAMomentPopUp
.getWaitAMomentTextElement(), 100);
143 }catch(NoSuchElementException e
){
149 public static FileListView
uploadFile(String elementName
,
150 FileListView fileListView
) throws InterruptedException
{
151 fileListView
.clickOnUploadButton();
152 UploadFilesView uploadFilesView
= fileListView
153 .clickOnFilesElementUploadFile();
154 uploadFilesView
.clickOnFileName(elementName
);
155 FileListView fileListViewAfterUploadFile
= uploadFilesView
156 .clickOnUploadButton();
157 //TO DO. detect when the file is successfully uploaded
159 return fileListViewAfterUploadFile
;