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
.*;
25 import java
.io
.IOException
;
27 import java
.text
.SimpleDateFormat
;
28 import java
.util
.Calendar
;
29 import java
.util
.Date
;
30 import java
.util
.concurrent
.TimeUnit
;
31 import org
.apache
.commons
.io
.FileUtils
;
32 import org
.openqa
.selenium
.By
;
33 import org
.openqa
.selenium
.NoSuchElementException
;
34 import org
.openqa
.selenium
.OutputType
;
35 import org
.openqa
.selenium
.TimeoutException
;
36 import org
.openqa
.selenium
.remote
.DesiredCapabilities
;
37 import org
.openqa
.selenium
.remote
.RemoteWebDriver
;
38 import org
.openqa
.selenium
.support
.ui
.WebDriverWait
;
39 import io
.appium
.java_client
.android
.AndroidDriver
;
40 import io
.appium
.java_client
.android
.AndroidElement
;
44 static int waitingTime
= 30;
48 protected AndroidDriver
setUpCommonDriver () throws Exception
{
49 File rootPath
= new File(System
.getProperty("user.dir"));
50 File appDir
= new File(rootPath
,"src/test/resources");
51 File app
= new File(appDir
,"ownCloud.apk");
52 DesiredCapabilities capabilities
= new DesiredCapabilities();
53 capabilities
.setCapability("platformName", "Android");
54 capabilities
.setCapability("deviceName", "test");
55 capabilities
.setCapability("app", app
.getAbsolutePath());
56 capabilities
.setCapability("appPackage", "com.owncloud.android");
57 capabilities
.setCapability("appActivity",
58 ".ui.activity.FileDisplayActivity");
59 capabilities
.setCapability("appWaitActivity",
60 ".authentication.AuthenticatorActivity");
61 driver
= new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),
63 driver
.manage().timeouts().implicitlyWait(waitingTime
,
65 wait
= new WebDriverWait(driver
, waitingTime
, 50);
70 protected boolean waitForTextPresent(String text
, AndroidElement element
)
71 throws InterruptedException
{
72 for (int second
= 0;;second
++){
73 if (second
>= waitingTime
)
76 if (text
.equals(element
.getText()))
78 } catch (Exception e
){
86 protected boolean isElementPresent(AndroidElement element
, By by
) {
88 element
.findElement(by
);
90 } catch (NoSuchElementException e
) {
95 public static boolean isElementPresent(AndroidElement element
) {
97 element
.isDisplayed();
98 } catch (NoSuchElementException e
){
104 //pollingTime in milliseconds
105 public static void waitTillElementIsNotPresent (AndroidElement element
,
106 int pollingTime
) throws Exception
{
107 for (int time
= 0;;time
+= pollingTime
){
108 if (time
>= waitingTime
* 1000) //convert to milliseconds
111 element
.isDisplayed();
112 } catch (NoSuchElementException e
){
115 Thread
.sleep(pollingTime
);
117 throw new TimeoutException();
120 protected void takeScreenShotOnFailed (String testName
)
122 File file
= ((RemoteWebDriver
) driver
)
123 .getScreenshotAs(OutputType
.FILE
);
124 SimpleDateFormat dt1
= new SimpleDateFormat("yyyy-MM-dd");
125 Date today
= Calendar
.getInstance().getTime();
126 String screenShotName
= "ScreenShots/" + dt1
.format(today
) + "/"
128 FileUtils
.copyFile(file
, new File(screenShotName
));
131 protected void assertIsInFileListView() throws InterruptedException
{
132 assertTrue(waitForTextPresent("ownCloud", (AndroidElement
) driver
133 .findElementByAndroidUIAutomator("new UiSelector()"
134 + ".resourceId(\"android:id/action_bar_title\")")));
135 assertTrue(isElementPresent((AndroidElement
) driver
136 .findElementByAndroidUIAutomator("new UiSelector()"
137 + ".description(\"Upload\")")));
140 protected void assertIsNotInFileListView() throws InterruptedException
{
141 AndroidElement fileElement
;
142 assertTrue(waitForTextPresent("ownCloud", (AndroidElement
) driver
143 .findElementByAndroidUIAutomator("new UiSelector()"
144 + ".resourceId(\"android:id/action_bar_title\")")));
146 fileElement
= (AndroidElement
) driver
147 .findElementByAndroidUIAutomator("new UiSelector()"
148 + ".description(\"Upload\")");
149 } catch (NoSuchElementException e
) {
152 assertNull(fileElement
);
155 protected void assertIsPasscodeRequestView() throws InterruptedException
{
156 assertTrue(waitForTextPresent("ownCloud", (AndroidElement
) driver
157 .findElementByAndroidUIAutomator("new UiSelector()"
158 + ".resourceId(\"android:id/action_bar_title\")")));
159 assertTrue(((AndroidElement
) driver
.findElementByAndroidUIAutomator(
160 "new UiSelector().text(\"Please, insert your pass code\")"))
165 protected void assertIsInSettingsView() throws InterruptedException
{
166 assertTrue(waitForTextPresent("Settings", (AndroidElement
) driver
167 .findElementByAndroidUIAutomator("new UiSelector()"
168 + ".resourceId(\"android:id/action_bar_title\")")));