f10e7aa3c6ea1f352cce13d18ed96caffea4e240
[pub/Android/ownCloud.git] / automationTest / src / test / java / com / owncloud / android / test / ui / models / FileListView.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.models;
22
23 import java.util.List;
24
25 import io.appium.java_client.android.AndroidDriver;
26 import io.appium.java_client.android.AndroidElement;
27 import io.appium.java_client.android.AndroidKeyCode;
28 import io.appium.java_client.pagefactory.AndroidFindBy;
29 import io.appium.java_client.pagefactory.AppiumFieldDecorator;
30
31 import org.openqa.selenium.NoSuchElementException;
32 import org.openqa.selenium.support.CacheLookup;
33 import org.openqa.selenium.support.PageFactory;
34 import org.openqa.selenium.Point;
35
36 import com.owncloud.android.test.ui.actions.Actions;
37
38 public class FileListView {
39 final AndroidDriver driver;
40
41 @AndroidFindBy(uiAutomator = "new UiSelector()"
42 + ".description(\"More options\")")
43 private AndroidElement menuButton;
44
45 @CacheLookup
46 @AndroidFindBy(id = "com.owncloud.android:id/list_root")
47 private AndroidElement filesLayout;
48
49 @CacheLookup
50 @AndroidFindBy(uiAutomator = "new UiSelector()"
51 + ".resourceId(\"android:id/action_bar_title\")")
52 private AndroidElement titleText;
53
54 @AndroidFindBy(id = "android:id/progress_circular")
55 private AndroidElement progressCircular;
56
57 @CacheLookup
58 @AndroidFindBy(uiAutomator = "new UiSelector()"
59 + ".description(\"New folder\")")
60 private AndroidElement newFolderButton;
61
62 @CacheLookup
63 @AndroidFindBy(uiAutomator = "new UiSelector().description(\"Upload\")")
64 private AndroidElement uploadButton;
65
66 private AndroidElement waitAMomentText;
67
68 @AndroidFindBy(id = "com.owncloud.android:id/ListItemLayout")
69 private List<AndroidElement> listItemLayout;
70
71 @AndroidFindBy(id = "com.owncloud.android:id/list_root")
72 private AndroidElement listRootLayout;
73
74 @AndroidFindBy(name = "Files")
75 private AndroidElement filesElementUploadFile;
76
77 @CacheLookup
78 @AndroidFindBy(uiAutomator = "new UiSelector()"
79 + ".description(\"List Layout\")")
80 private AndroidElement listLayout;
81
82 private AndroidElement fileElement;
83
84 private AndroidElement fileElementLayout;
85
86 private static String localFileIndicator =
87 "com.owncloud.android:id/localFileIndicator";
88 private static String favoriteFileIndicator =
89 "com.owncloud.android:id/favoriteIcon";
90 private static String sharedElementIndicator =
91 "com.owncloud.android:id/sharedIcon";
92
93
94 public FileListView (AndroidDriver driver) {
95 this.driver = driver;
96 PageFactory.initElements(new AppiumFieldDecorator(driver), this);
97 }
98
99 public MenuList clickOnMenuButton () {
100 //if the menu option is not in the actionBar, it is opening again
101 try {
102 menuButton.click();
103 } catch (NoSuchElementException e){
104 driver.sendKeyEvent(AndroidKeyCode.MENU);
105 }
106 MenuList menuList = new MenuList (driver);
107 return menuList;
108 }
109
110 public SettingsView getSettingsView () {
111 SettingsView settingsView = new SettingsView(driver);
112 return settingsView;
113 }
114
115 public NewFolderPopUp clickOnNewFolderButton () {
116 newFolderButton.click();
117 NewFolderPopUp newFolderPopUp = new NewFolderPopUp(driver);
118 return newFolderPopUp;
119 }
120
121 public void clickOnUploadButton () {
122 uploadButton.click();
123 }
124
125 public UploadFilesView clickOnFilesElementUploadFile () {
126 filesElementUploadFile.click();
127 UploadFilesView uploadFilesView = new UploadFilesView(driver);
128 return uploadFilesView;
129 }
130
131 public AndroidElement getTitleTextElement () {
132 return titleText;
133 }
134
135 public AndroidElement getUploadButton () {
136 return uploadButton;
137 }
138
139 public AndroidElement getWaitAMomentTextElement () {
140 return waitAMomentText;
141 }
142
143 public AndroidElement getListRootElement () {
144 return listRootLayout;
145 }
146
147 public List<AndroidElement> getListItemLayout () {
148 return listItemLayout;
149 }
150
151 public AndroidElement getFileElement () {
152 return fileElement;
153 }
154
155 public ElementMenuOptions longPressOnElement (String elementName) {
156 scrollTillFindElement(elementName).tap(1, 1000);
157 //fileElement.tap(1, 1000);
158 ElementMenuOptions menuOptions = new ElementMenuOptions(driver);
159 return menuOptions;
160 }
161
162 public AndroidElement scrollTillFindElement (String elementName) {
163 fileElement = Actions
164 .scrollTillFindElement (elementName,filesLayout,driver);
165 try {
166 fileElementLayout = (AndroidElement) driver
167 .findElementByAndroidUIAutomator("new UiSelector()"
168 + ".description(\"LinearLayout-"+ elementName +"\")");
169 } catch (NoSuchElementException e) {
170 fileElementLayout = null;
171 }
172 return fileElement;
173 }
174
175 public AndroidElement getFileElementLayout () {
176 return fileElementLayout;
177 }
178
179 public AndroidElement getProgressCircular () {
180 return progressCircular;
181 }
182
183 public static String getLocalFileIndicator() {
184 return localFileIndicator;
185 }
186
187 public static String getFavoriteFileIndicator() {
188 return favoriteFileIndicator;
189 }
190
191 public static String getSharedElementIndicator() {
192 return sharedElementIndicator;
193 }
194 public void pulldownToRefresh () throws InterruptedException {
195 Point listLocation = listLayout.getLocation();
196 driver.swipe(listLocation.getX(),listLocation.getY(),
197 listLocation.getX(),listLocation.getY()+1000, 5000);
198 }
199
200
201 }