add new testCases. prepare the test to have them into categories
[pub/Android/ownCloud.git] / automationTest / src / test / java / androidtest / tests / Common.java
index c457d20..aeab97d 100644 (file)
@@ -1,5 +1,6 @@
 package androidtest.tests;
 
+import static org.junit.Assert.*;
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
@@ -7,45 +8,41 @@ 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.WebDriver;
-import org.openqa.selenium.remote.Augmenter;
 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)
@@ -54,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);
@@ -69,7 +66,7 @@ public class Common extends TestCase{
                        return false;
                }
        }
-       
+
        protected boolean isElementPresent(AndroidElement element) {
                try{
                        element.isDisplayed();
@@ -78,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){        
@@ -93,7 +90,7 @@ 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");
@@ -102,4 +99,30 @@ public class Common extends TestCase{
                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\")")));
+       }
+
 }