c2349c48fda1fd2ee717b2a90b90a228dfba4e1c
[pub/Android/ownCloud.git] / automationTest / src / test / java / com / owncloud / android / test / ui / actions / Actions.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.actions;
22
23 import java.util.HashMap;
24
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;
47
48 public class Actions {
49
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);
55 if(!isTrusted){
56 WebDriverWait wait = new WebDriverWait(driver, 30);
57 //sometimes the certificate has been already accept
58 //and it doesn't appear again
59 try {
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) {
68
69 }
70
71 }
72 loginForm.typeUserName(user);
73 loginForm.typePassword(password);
74 //TODO. Assert related to check the connection?
75 return loginForm.clickOnConnectButton();
76 }
77
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();
84 //TODO. assert here
85 return waitAMomentPopUp;
86 }
87
88
89 public static AndroidElement scrollTillFindElement (String elementName,
90 AndroidElement element, AndroidDriver driver) {
91 AndroidElement fileElement;
92
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);
98 }
99 try {
100 fileElement = (AndroidElement) driver
101 .findElementByName(elementName);
102 } catch (NoSuchElementException e) {
103 fileElement = null;
104 }
105 return fileElement;
106 }
107
108
109 public static void deleteAccount (FileListView fileListView) {
110 MenuList menulist = fileListView.clickOnMenuButton();
111 SettingsView settingView = menulist.clickOnSettingsButton();
112 deleteAccount(settingView);
113 }
114
115 public static void deleteAccount (SettingsView settingsView) {
116 settingsView.tapOnAccountElement(1, 1000);
117 settingsView.clickOnDeleteAccountElement();
118 }
119
120 public static void clickOnMainLayout(AndroidDriver driver){
121 driver.tap(1, 0, 0, 1);
122 }
123
124
125 public static AndroidElement deleteElement(String elementName,
126 FileListView fileListView, AndroidDriver driver) throws Exception{
127 AndroidElement fileElement;
128 WaitAMomentPopUp waitAMomentPopUp;
129 try{
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
139 .clickOnRemove();;
140 waitAMomentPopUp = removeConfirmationView
141 .clickOnRemoteAndLocalButton();
142 Common.waitTillElementIsNotPresent(
143 waitAMomentPopUp.getWaitAMomentTextElement(), 100);
144 }catch(NoSuchElementException e){
145 fileElement=null;
146 }
147 return fileElement;
148 }
149
150 public static AndroidElement shareLinkElementByGmail(String elementName,
151 FileListView fileListView, AndroidDriver driver, Common common)
152 throws Exception{
153 try{
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()))));
172
173 }catch(NoSuchElementException e){
174 return null;
175 }
176 return (AndroidElement) fileListView.getFileElementLayout()
177 .findElement(By.id(FileListView.getSharedElementIndicator()));
178 }
179
180 public static AndroidElement shareLinkElementByCopyLink(String elementName,
181 FileListView fileListView, AndroidDriver driver, Common common)
182 throws Exception{
183 try{
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(),
192 driver).click();
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){
200 return null;
201 }
202 return (AndroidElement) fileListView.getFileElementLayout()
203 .findElement(By.id(FileListView.getSharedElementIndicator()));
204 }
205
206
207 public static void unshareLinkElement(String elementName,
208 FileListView fileListView, AndroidDriver driver, Common common)
209 throws Exception{
210 try{
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())
224 ),100);
225 }catch(NoSuchElementException e){
226
227 }
228 }
229
230
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
240 Thread.sleep(15000);
241 return fileListViewAfterUploadFile;
242 }
243
244
245 }