X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/ba1470a9884507fa57b2b01fdb9c601f52587b83..a52fc9424444400d4c774b76cf9f59ba43f9dc12:/automationTest/src/test/java/androidtest/tests/Common.java diff --git a/automationTest/src/test/java/androidtest/tests/Common.java b/automationTest/src/test/java/androidtest/tests/Common.java index 7bf21bdc..aeab97d6 100644 --- a/automationTest/src/test/java/androidtest/tests/Common.java +++ b/automationTest/src/test/java/androidtest/tests/Common.java @@ -1,41 +1,48 @@ package androidtest.tests; +import static org.junit.Assert.*; import java.io.File; +import java.io.IOException; import java.net.URL; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; import java.util.concurrent.TimeUnit; - +import org.apache.commons.io.FileUtils; import org.openqa.selenium.By; import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.OutputType; import org.openqa.selenium.TimeoutException; import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.support.ui.WebDriverWait; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.android.AndroidElement; -import junit.framework.TestCase; -public class Common extends TestCase{ +public class Common{ AndroidDriver driver; static int waitingTime = 30; - + WebDriverWait wait; - - protected void setUpCommonDriver () throws Exception { + + protected AndroidDriver setUpCommonDriver () throws Exception { File rootPath = new File(System.getProperty("user.dir")); File appDir = new File(rootPath,"src/test/resources"); File app = new File(appDir,"ownCloud.apk"); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("platformName", "Android"); - capabilities.setCapability("deviceName", "Device"); + capabilities.setCapability("deviceName", "test"); capabilities.setCapability("app", app.getAbsolutePath()); - capabilities.setCapability("app-package", "com.owncloud.android"); - capabilities.setCapability("app-activity", ".ui.activity.FileDisplayActivity"); + capabilities.setCapability("appPackage", "com.owncloud.android"); + capabilities.setCapability("appActivity", ".ui.activity.FileDisplayActivity"); capabilities.setCapability("appWaitActivity", ".authentication.AuthenticatorActivity"); driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); driver.manage().timeouts().implicitlyWait(waitingTime, TimeUnit.SECONDS); wait = new WebDriverWait(driver, waitingTime, 50); + return driver; } - + protected boolean waitForTextPresent(String text, AndroidElement element) throws InterruptedException{ for (int second = 0;;second++){ if (second >= waitingTime) @@ -44,13 +51,13 @@ public class Common extends TestCase{ if (text.equals(element.getText())) break; } catch (Exception e){ - + } Thread.sleep(1000); } return true; } - + protected boolean isElementPresent(AndroidElement element, By by) { try { element.findElement(by); @@ -59,7 +66,7 @@ public class Common extends TestCase{ return false; } } - + protected boolean isElementPresent(AndroidElement element) { try{ element.isDisplayed(); @@ -68,7 +75,7 @@ public class Common extends TestCase{ } return true; } - + //pollingTime in milliseconds public static void waitTillElementIsNotPresent (AndroidElement element, int pollingTime) throws Exception { for (int time = 0;;time += pollingTime){ @@ -83,5 +90,39 @@ public class Common extends TestCase{ } throw new TimeoutException(); } + + protected void takeScreenShotOnFailed (String testName) throws IOException { + File file = ((RemoteWebDriver) driver).getScreenshotAs(OutputType.FILE); + SimpleDateFormat dt1 = new SimpleDateFormat("yyyy-MM-dd"); + Date today = Calendar.getInstance().getTime(); + String screenShotName = "ScreenShots/" + dt1.format(today) + "/" + testName + ".png"; + FileUtils.copyFile(file, new File(screenShotName)); + } + + protected void assertIsInMainView() throws InterruptedException { + assertTrue(waitForTextPresent("ownCloud", (AndroidElement) driver.findElementByAndroidUIAutomator("new UiSelector().resourceId(\"android:id/action_bar_title\")"))); + assertTrue(isElementPresent((AndroidElement) driver.findElementByAndroidUIAutomator("new UiSelector().description(\"Upload\")"))); + } + + protected void assertIsNotInMainView() throws InterruptedException { + AndroidElement fileElement; + assertTrue(waitForTextPresent("ownCloud", (AndroidElement) driver.findElementByAndroidUIAutomator("new UiSelector().resourceId(\"android:id/action_bar_title\")"))); + try { + fileElement = (AndroidElement) driver.findElementByAndroidUIAutomator("new UiSelector().description(\"Upload\")"); + } catch (NoSuchElementException e) { + fileElement = null; + } + assertNull(fileElement); + } + protected void assertIsPasscodeRequestView() throws InterruptedException { + assertTrue(waitForTextPresent("ownCloud", (AndroidElement) driver.findElementByAndroidUIAutomator("new UiSelector().resourceId(\"android:id/action_bar_title\")"))); + assertTrue(((AndroidElement) driver.findElementByAndroidUIAutomator("new UiSelector().text(\"Please, insert your pass code\")")).isDisplayed()); + + } + + protected void assertIsInSettingsView() throws InterruptedException { + assertTrue(waitForTextPresent("Settings", (AndroidElement) driver.findElementByAndroidUIAutomator("new UiSelector().resourceId(\"android:id/action_bar_title\")"))); + } + }