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
.testSuites
;
23 import static org
.junit
.Assert
.*;
26 import java
.io
.IOException
;
28 import java
.text
.SimpleDateFormat
;
29 import java
.util
.Calendar
;
30 import java
.util
.Date
;
31 import java
.util
.concurrent
.TimeUnit
;
33 import org
.apache
.commons
.io
.FileUtils
;
34 import org
.openqa
.selenium
.By
;
35 import org
.openqa
.selenium
.NoSuchElementException
;
36 import org
.openqa
.selenium
.OutputType
;
37 import org
.openqa
.selenium
.TimeoutException
;
38 import org
.openqa
.selenium
.remote
.DesiredCapabilities
;
39 import org
.openqa
.selenium
.remote
.RemoteWebDriver
;
40 import org
.openqa
.selenium
.support
.ui
.WebDriverWait
;
42 import io
.appium
.java_client
.android
.AndroidDriver
;
43 import io
.appium
.java_client
.android
.AndroidElement
;
47 static int waitingTime
= 30;
49 public WebDriverWait wait
;
51 protected AndroidDriver
setUpCommonDriver () throws Exception
{
52 File rootPath
= new File(System
.getProperty("user.dir"));
53 File appDir
= new File(rootPath
,"src/test/resources");
54 File app
= new File(appDir
,"ownCloud.apk");
55 DesiredCapabilities capabilities
= new DesiredCapabilities();
56 capabilities
.setCapability("platformName", "Android");
57 capabilities
.setCapability("deviceName", "test");
58 capabilities
.setCapability("app", app
.getAbsolutePath());
59 capabilities
.setCapability("appPackage", "com.owncloud.android");
60 capabilities
.setCapability("appActivity",
61 ".ui.activity.FileDisplayActivity");
62 capabilities
.setCapability("appWaitActivity",
63 ".authentication.AuthenticatorActivity");
64 driver
= new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),
66 driver
.manage().timeouts().implicitlyWait(waitingTime
,
68 wait
= new WebDriverWait(driver
, waitingTime
, 50);
73 protected boolean waitForTextPresent(String text
, AndroidElement element
)
74 throws InterruptedException
{
75 for (int second
= 0;;second
++){
76 if (second
>= waitingTime
)
79 if (text
.equals(element
.getText()))
81 } catch (Exception e
){
89 protected boolean isElementPresent(AndroidElement element
, By by
) {
91 element
.findElement(by
);
93 } catch (NoSuchElementException e
) {
98 public static boolean isElementPresent(AndroidElement element
) {
100 element
.isDisplayed();
101 } catch (NoSuchElementException e
){
107 //pollingTime in milliseconds
108 public static void waitTillElementIsNotPresent (AndroidElement element
,
109 int pollingTime
) throws Exception
{
110 for (int time
= 0;time
<= waitingTime
* 1000;time
+= pollingTime
){
112 element
.isDisplayed();
113 } catch (NoSuchElementException e
){
116 Thread
.sleep(pollingTime
);
118 throw new TimeoutException();
121 public static void waitTillElementIsNotPresentWithoutTimeout (
122 AndroidElement element
,int pollingTime
)
123 throws InterruptedException
{
124 for (int time
= 0;time
<= waitingTime
* 1000;time
+= pollingTime
){
126 element
.isDisplayed();
127 } catch (NoSuchElementException e
){
130 Thread
.sleep(pollingTime
);
134 protected void takeScreenShotOnFailed (String testName
)
136 File file
= ((RemoteWebDriver
) driver
)
137 .getScreenshotAs(OutputType
.FILE
);
138 SimpleDateFormat dt1
= new SimpleDateFormat("yyyy-MM-dd");
139 Date today
= Calendar
.getInstance().getTime();
140 String screenShotName
= "ScreenShots/" + dt1
.format(today
) + "/"
142 FileUtils
.copyFile(file
, new File(screenShotName
));
145 protected void assertIsInFileListView() throws InterruptedException
{
146 assertTrue(waitForTextPresent("ownCloud", (AndroidElement
) driver
147 .findElementByAndroidUIAutomator("new UiSelector()"
148 + ".resourceId(\"android:id/action_bar_title\")")));
149 assertTrue(isElementPresent((AndroidElement
) driver
150 .findElementByAndroidUIAutomator("new UiSelector()"
151 + ".description(\"Upload\")")));
154 protected void assertIsNotInFileListView() throws InterruptedException
{
155 AndroidElement fileElement
;
156 assertTrue(waitForTextPresent("ownCloud", (AndroidElement
) driver
157 .findElementByAndroidUIAutomator("new UiSelector()"
158 + ".resourceId(\"android:id/action_bar_title\")")));
160 fileElement
= (AndroidElement
) driver
161 .findElementByAndroidUIAutomator("new UiSelector()"
162 + ".description(\"Upload\")");
163 } catch (NoSuchElementException e
) {
166 assertNull(fileElement
);
169 protected void assertIsPasscodeRequestView() throws InterruptedException
{
170 assertTrue(waitForTextPresent("ownCloud", (AndroidElement
) driver
171 .findElementByAndroidUIAutomator("new UiSelector()"
172 + ".resourceId(\"android:id/action_bar_title\")")));
173 assertTrue(((AndroidElement
) driver
.findElementByAndroidUIAutomator(
174 "new UiSelector().text(\"Please, insert your pass code\")"))
179 protected void assertIsInSettingsView() throws InterruptedException
{
180 assertTrue(waitForTextPresent("Settings", (AndroidElement
) driver
181 .findElementByAndroidUIAutomator("new UiSelector()"
182 + ".resourceId(\"android:id/action_bar_title\")")));