6d592179bbf1a038d2aa4b3485ccdd0b838602a5
[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.NoSuchElementException;
26 import org.openqa.selenium.ScreenOrientation;
27 import org.openqa.selenium.remote.RemoteWebElement;
28
29 import io.appium.java_client.android.AndroidDriver;
30 import io.appium.java_client.android.AndroidElement;
31
32 import org.openqa.selenium.support.ui.ExpectedConditions;
33 import org.openqa.selenium.support.ui.WebDriverWait;
34
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;
46
47 public class Actions {
48
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);
54 if(!isTrusted){
55 WebDriverWait wait = new WebDriverWait(driver, 30);
56 //sometimes the certificate has been already accept
57 //and it doesn't appear again
58 try {
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) {
67
68 }
69
70 }
71 loginForm.typeUserName(user);
72 loginForm.typePassword(password);
73 //TODO. Assert related to check the connection?
74 return loginForm.clickOnConnectButton();
75 }
76
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();
83 //TODO. assert here
84 return waitAMomentPopUp;
85 }
86
87
88 public static AndroidElement scrollTillFindElement (String elementName,
89 AndroidElement element, AndroidDriver driver) {
90 AndroidElement fileElement;
91
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);
97 }
98 try {
99 fileElement = (AndroidElement) driver
100 .findElementByName(elementName);
101 } catch (NoSuchElementException e) {
102 fileElement = null;
103 }
104 return fileElement;
105 }
106
107
108 public static void deleteAccount (FileListView fileListView) {
109 MenuList menulist = fileListView.clickOnMenuButton();
110 SettingsView settingView = menulist.clickOnSettingsButton();
111 deleteAccount(settingView);
112 }
113
114 public static void deleteAccount (SettingsView settingsView) {
115 settingsView.tapOnAccountElement(1, 1000);
116 settingsView.clickOnDeleteAccountElement();
117 }
118
119 public static void clickOnMainLayout(AndroidDriver driver){
120 driver.tap(1, 0, 0, 1);
121 }
122
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;
128 try{
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
138 .clickOnRemove();;
139 waitAMomentPopUp = removeConfirmationView
140 .clickOnRemoteAndLocalButton();
141 Common.waitTillElementIsNotPresent(
142 waitAMomentPopUp.getWaitAMomentTextElement(), 100);
143 }catch(NoSuchElementException e){
144 fileElement=null;
145 }
146 return fileElement;
147 }
148
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
158 Thread.sleep(15000);
159 return fileListViewAfterUploadFile;
160 }
161
162
163 }