Example usage for org.openqa.selenium Platform ANDROID

List of usage examples for org.openqa.selenium Platform ANDROID

Introduction

In this page you can find the example usage for org.openqa.selenium Platform ANDROID.

Prototype

Platform ANDROID

To view the source code for org.openqa.selenium Platform ANDROID.

Click Source Link

Usage

From source file:com.agomezmoron.appiumhandler.AppiumHandledDriver.java

License:Open Source License

/**
 * It checks if it's an Android platform.
 * @param desiredCapabilities to check if the SO is iOS.
 * @return true if it's an iOS testing.//from   w  w w  .  j a v  a  2s .c om
 */
private static boolean isAndroid(Capabilities desiredCapabilities) {
    return is(desiredCapabilities, Platform.ANDROID.name());
}

From source file:com.atanas.kanchev.testframework.appium.tests.android.native_app_tests.AndroidContextTest.java

License:Apache License

@BeforeClass
public static void beforeClass() throws Exception {
    File appDir = new File(
            "src/test/java/com/atanas/kanchev/testframework/appium/tests/android/native_app_tests");
    File app = new File(appDir, "ApiDemos-debug.apk");

    APPIUM_DRIVER_FACTORY.buildDefaultService().startServer();

    APPIUM_DRIVER_FACTORY.setCap(MobileCapabilityType.BROWSER_NAME, "")
            .setCap(MobileCapabilityType.APP, app.getAbsoluteFile())
            .setCap(MobileCapabilityType.DEVICE_NAME, "8adea98f")
            .setCap(MobileCapabilityType.PLATFORM_VERSION, "6.0.1")
            .setCap(MobileCapabilityType.PLATFORM, Platform.ANDROID)

            .setCap(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 120)
            .setCap(MobileCapabilityType.FULL_RESET, false).setCap(MobileCapabilityType.NO_RESET, true)
            .setCap(AndroidMobileCapabilityType.ANDROID_DEVICE_READY_TIMEOUT, 10)
            .setCap(AndroidMobileCapabilityType.ENABLE_PERFORMANCE_LOGGING, true);
}

From source file:com.atanas.kanchev.testframework.appium.tests.android.native_app_tests.IntentTest.java

License:Apache License

@BeforeClass
public static void beforeClass() throws Exception {

    File appDir = new File(
            "src/test/java/com/atanas/kanchev/testframework/appium/tests/android/native_app_tests");
    File app = new File(appDir, "IntentExample.apk");

    APPIUM_DRIVER_FACTORY.buildDefaultService().startServer();

    APPIUM_DRIVER_FACTORY.setCap(MobileCapabilityType.APP, app.getAbsoluteFile())
            .setCap(MobileCapabilityType.DEVICE_NAME, "8adea98f")
            .setCap(MobileCapabilityType.PLATFORM, Platform.ANDROID);
}

From source file:com.google.android.testing.nativedriver.common.AndroidCapabilities.java

License:Apache License

/**
 * Returns a {@code DesiredCapabilities} object that matches the AND. Users
 * of AND generally do not need to call this method directly.
 *//*from w  ww . j a va  2 s .  c  o m*/
public static DesiredCapabilities get() {
    return new DesiredCapabilities("android native", "2.2", Platform.ANDROID);
}

From source file:com.htmlhifive.pitalium.core.io.FileNameFormatterTest.java

License:Apache License

/**
 * selendroid?//from www  .  j  a  va 2  s.c  o m
 */
@Test
public void testFormat_selendroid() throws Exception {
    PtlCapabilities capabilities = new PtlCapabilities(new HashMap<String, Object>());
    capabilities.setPlatform(Platform.ANDROID);
    capabilities.setBrowserName("");
    capabilities.setCapability("deviceName", "ASUS Pad");
    capabilities.setCapability("platformVersion", "4.0.3");
    capabilities.setCapability("automationName", "Selendroid");

    PersistMetadata metadata = new PersistMetadata("testId", "testClass", "testMethod", "scId",
            new IndexDomSelector(SelectorType.TAG_NAME, "body", 1), null, capabilities);

    FileNameFormatter formatter = new FileNameFormatter(
            "{platformName}_{platformVersion}_{browserName}_{version}_{screenArea}.png");
    String result = formatter.format(metadata);
    assertThat(result, is("testMethod_scId_ANDROID_4.0.3_Selendroid_TAG_NAME_body_[1].png"));
}

From source file:com.htmlhifive.pitalium.core.selenium.PtlWebDriverFactory.java

License:Apache License

/**
 * ??{@link PtlWebDriverFactory}?????/*from w  w  w.  j a va 2 s  .  co m*/
 * 
 * @param capabilities Capability??
 * @return {@link PtlWebDriverFactory}?
 */
public static PtlWebDriverFactory getInstance(PtlCapabilities capabilities) {
    PtlTestConfig config = PtlTestConfig.getInstance();
    EnvironmentConfig environmentConfig = config.getEnvironment();
    TestAppConfig testAppConfig = config.getTestAppConfig();

    String browserName = Strings.nullToEmpty(capabilities.getBrowserName()).toLowerCase(Locale.ENGLISH);

    // IE
    if ("internet explorer".equals(browserName)) {
        String version = Strings.nullToEmpty(capabilities.getVersion());
        if (version.startsWith("7")) {
            return new PtlInternetExplorer7DriverFactory(environmentConfig, testAppConfig, capabilities);
        }
        if (version.startsWith("8")) {
            return new PtlInternetExplorer8DriverFactory(environmentConfig, testAppConfig, capabilities);
        }

        return new PtlInternetExplorerDriverFactory(environmentConfig, testAppConfig, capabilities);
    }

    // Edge
    if ("microsoftedge".equals(browserName)) {
        return new PtlEdgeDriverFactory(environmentConfig, testAppConfig, capabilities);
    }

    // Android
    if (capabilities.getPlatform() == Platform.ANDROID) {
        // Selendroid (Android 2.3+)
        String automationName = (String) capabilities.getCapability("automationName");
        if (automationName != null && "selendroid".equalsIgnoreCase(automationName)) {
            return new PtlSelendroidDriverFactory(environmentConfig, testAppConfig, capabilities);
        }

        // Default (Android 4.2+)
        return new PtlAndroidDriverFactory(environmentConfig, testAppConfig, capabilities);
    }

    // Chrome
    if ("chrome".equals(browserName)) {
        return new PtlChromeWebDriverFactory(environmentConfig, testAppConfig, capabilities);
    }

    // Safari
    if ("safari".equals(browserName)) {
        // MacOSX
        if (capabilities.getPlatform() == Platform.MAC) {
            return new PtlSafariDriverFactory(environmentConfig, testAppConfig, capabilities);
        }

        String deviceName = capabilities.getDeviceName();
        if (Strings.isNullOrEmpty(deviceName)) {
            throw new TestRuntimeException("\"deviceName\" is required for iOS devices");
        }
        if (deviceName.contains("iPad")) {
            return new PtlIPadDriverFactory(environmentConfig, testAppConfig, capabilities);
        }
        if (deviceName.contains("iPhone")) {
            return new PtlIPhoneDriverFactory(environmentConfig, testAppConfig, capabilities);
        }

        throw new TestRuntimeException("Unknown deviceName \"" + deviceName + "\"");
    }

    // Other
    return new PtlFirefoxWebDriverFactory(environmentConfig, testAppConfig, capabilities);
}

From source file:com.playphone.alex.ListViewXpathDemo.java

License:Apache License

public void setupAppium() throws MalformedURLException {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability(MobileCapabilityType.PLATFORM_NAME, Platform.ANDROID);
    File app = new File("app-list-view.apk");
    caps.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
    caps.setCapability(MobileCapabilityType.DEVICE_NAME, Platform.ANDROID);
    driver = new AndroidDriver<>(new URL("http://localhost:4723/wd/hub"), caps);
}

From source file:org.cerberus.engine.execution.impl.SeleniumServerService.java

License:Open Source License

@Override
public void startServer(TestCaseExecution tCExecution) throws CerberusException {
    //message used for log purposes 
    String logPrefix = "[" + tCExecution.getTest() + " - " + tCExecution.getTestCase() + "] ";

    try {/* w  w w.  jav  a  2s.  c  o  m*/

        LOG.info(logPrefix + "Start Selenium Server");

        /**
         * Set Session
         */
        LOG.debug(logPrefix + "Setting the session.");
        String system = tCExecution.getApplicationObj().getSystem();

        /**
         * Get the parameters that will be used to set the servers
         * (selenium/appium) If timeout has been defined at the execution
         * level, set the selenium & appium wait element with this value,
         * else, take the one from parameter
         */
        Integer cerberus_selenium_pageLoadTimeout, cerberus_selenium_implicitlyWait,
                cerberus_selenium_setScriptTimeout, cerberus_selenium_wait_element,
                cerberus_appium_wait_element;

        if (!tCExecution.getTimeout().isEmpty()) {
            cerberus_selenium_wait_element = Integer.valueOf(tCExecution.getTimeout());
            cerberus_appium_wait_element = Integer.valueOf(tCExecution.getTimeout());
        } else {
            cerberus_selenium_wait_element = this.getTimeoutSetInParameterTable(system,
                    "cerberus_selenium_wait_element", 90000, logPrefix);
            cerberus_appium_wait_element = this.getTimeoutSetInParameterTable(system,
                    "cerberus_appium_wait_element", 90000, logPrefix);
            ;
        }
        cerberus_selenium_pageLoadTimeout = this.getTimeoutSetInParameterTable(system,
                "cerberus_selenium_pageLoadTimeout", 90000, logPrefix);
        cerberus_selenium_implicitlyWait = this.getTimeoutSetInParameterTable(system,
                "cerberus_selenium_implicitlyWait", 0, logPrefix);
        cerberus_selenium_setScriptTimeout = this.getTimeoutSetInParameterTable(system,
                "cerberus_selenium_setScriptTimeout", 90000, logPrefix);

        LOG.debug(logPrefix + "TimeOut defined on session : " + cerberus_selenium_wait_element);

        Session session = new Session();
        session.setCerberus_selenium_implicitlyWait(cerberus_selenium_implicitlyWait);
        session.setCerberus_selenium_pageLoadTimeout(cerberus_selenium_pageLoadTimeout);
        session.setCerberus_selenium_setScriptTimeout(cerberus_selenium_setScriptTimeout);
        session.setCerberus_selenium_wait_element(cerberus_selenium_wait_element);
        session.setCerberus_appium_wait_element(cerberus_appium_wait_element);
        session.setHost(tCExecution.getSeleniumIP());
        session.setPort(tCExecution.getPort());
        tCExecution.setSession(session);
        LOG.debug(logPrefix + "Session is set.");

        /**
         * SetUp Capabilities
         */
        LOG.debug(logPrefix + "Set Capabilities");
        DesiredCapabilities caps = this.setCapabilities(tCExecution);
        session.setDesiredCapabilities(caps);
        LOG.debug(logPrefix + "Set Capabilities - retreived");

        /**
         * SetUp Driver
         */
        LOG.debug(logPrefix + "Set Driver");
        WebDriver driver = null;
        AppiumDriver appiumDriver = null;
        if (tCExecution.getApplicationObj().getType().equalsIgnoreCase("GUI")) {
            if (caps.getPlatform().is(Platform.ANDROID)) {
                appiumDriver = new AndroidDriver(new URL("http://" + tCExecution.getSession().getHost() + ":"
                        + tCExecution.getSession().getPort() + "/wd/hub"), caps);
                driver = (WebDriver) appiumDriver;
            } else if (caps.getPlatform().is(Platform.MAC)) {
                appiumDriver = new IOSDriver(new URL("http://" + tCExecution.getSession().getHost() + ":"
                        + tCExecution.getSession().getPort() + "/wd/hub"), caps);
                driver = (WebDriver) appiumDriver;
            } else {
                driver = new RemoteWebDriver(new URL("http://" + tCExecution.getSession().getHost() + ":"
                        + tCExecution.getSession().getPort() + "/wd/hub"), caps);
            }
        } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase("APK")) {
            appiumDriver = new AndroidDriver(new URL("http://" + tCExecution.getSession().getHost() + ":"
                    + tCExecution.getSession().getPort() + "/wd/hub"), caps);
            driver = (WebDriver) appiumDriver;
        } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase("IPA")) {
            appiumDriver = new IOSDriver(new URL("http://" + tCExecution.getSession().getHost() + ":"
                    + tCExecution.getSession().getPort() + "/wd/hub"), caps);
            driver = (WebDriver) appiumDriver;
        } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase("FAT")) {
            sikuliService.doSikuliAction(session, "openApp", null,
                    tCExecution.getCountryEnvironmentParameters().getIp());
        }

        /**
         * Defining the timeout at the driver level. Only in case of not
         * Appium Driver (see
         * https://github.com/vertigo17/Cerberus/issues/754)
         */
        if (driver != null && appiumDriver == null) {
            driver.manage().timeouts().pageLoadTimeout(cerberus_selenium_pageLoadTimeout,
                    TimeUnit.MILLISECONDS);
            driver.manage().timeouts().implicitlyWait(cerberus_selenium_implicitlyWait, TimeUnit.MILLISECONDS);
            driver.manage().timeouts().setScriptTimeout(cerberus_selenium_setScriptTimeout,
                    TimeUnit.MILLISECONDS);
        }
        tCExecution.getSession().setDriver(driver);
        tCExecution.getSession().setAppiumDriver(appiumDriver);

        /**
         * If Gui application, maximize window Get IP of Node in case of
         * remote Server
         */
        if (tCExecution.getApplicationObj().getType().equalsIgnoreCase("GUI")
                && !caps.getPlatform().equals(Platform.ANDROID)) {
            driver.manage().window().maximize();
            getIPOfNode(tCExecution);

            /**
             * If screenSize is defined, set the size of the screen.
             */
            if (!tCExecution.getScreenSize().equals("")) {
                Integer screenWidth = Integer.valueOf(tCExecution.getScreenSize().split("\\*")[0]);
                Integer screenLength = Integer.valueOf(tCExecution.getScreenSize().split("\\*")[1]);
                setScreenSize(driver, screenWidth, screenLength);
            }
            tCExecution.setScreenSize(getScreenSize(driver));
        }
        tCExecution.getSession().setStarted(true);

    } catch (CerberusException exception) {
        LOG.error(logPrefix + exception.toString());
        throw new CerberusException(exception.getMessageError());
    } catch (MalformedURLException exception) {
        LOG.error(logPrefix + exception.toString());
        MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_URL_MALFORMED);
        mes.setDescription(mes.getDescription().replace("%URL%",
                tCExecution.getSession().getHost() + ":" + tCExecution.getSession().getPort()));
        throw new CerberusException(mes);
    } catch (UnreachableBrowserException exception) {
        LOG.error(logPrefix + exception.toString());
        MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_SELENIUM_COULDNOTCONNECT);
        mes.setDescription(mes.getDescription().replace("%SSIP%", tCExecution.getSeleniumIP()));
        mes.setDescription(mes.getDescription().replace("%SSPORT%", tCExecution.getSeleniumPort()));
        throw new CerberusException(mes);
    } catch (Exception exception) {
        LOG.error(logPrefix + exception.toString());
        MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);
        mes.setDescription(mes.getDescription().replace("%MES%", exception.toString()));
        throw new CerberusException(mes);
    }
}

From source file:org.cerberus.service.engine.impl.SeleniumServerService.java

License:Open Source License

@Override
public void startServer(TestCaseExecution tCExecution) throws CerberusException {
    //message used for log purposes 
    String testCaseDescription = "[" + tCExecution.getTest() + " - " + tCExecution.getTestCase() + "]";
    try {//from   w  w  w .  ja  v  a  2s.c om

        /**
         * SetUp Capabilities
         */
        MyLogger.log(SeleniumServerService.class.getName(), Level.DEBUG,
                testCaseDescription + "Set Capabilities");
        DesiredCapabilities caps = this.setCapabilities(tCExecution);

        /**
         * SetUp Driver
         */
        MyLogger.log(SeleniumServerService.class.getName(), Level.DEBUG, testCaseDescription + "Set Driver");
        WebDriver driver = null;
        AppiumDriver appiumDriver = null;
        if (tCExecution.getApplication().getType().equalsIgnoreCase("GUI")) {
            if (caps.getPlatform().is(Platform.ANDROID)) {

                appiumDriver = new AppiumDriver(new URL("http://" + tCExecution.getSession().getHost() + ":"
                        + tCExecution.getSession().getPort() + "/wd/hub"), caps);
                driver = (WebDriver) appiumDriver;
            } else {
                driver = new RemoteWebDriver(new URL("http://" + tCExecution.getSession().getHost() + ":"
                        + tCExecution.getSession().getPort() + "/wd/hub"), caps);
            }
        } else if (tCExecution.getApplication().getType().equalsIgnoreCase("APK")) {
            appiumDriver = new AppiumDriver(new URL("http://" + tCExecution.getSession().getHost() + ":"
                    + tCExecution.getSession().getPort() + "/wd/hub"), caps);
            driver = (WebDriver) appiumDriver;
        } else if (tCExecution.getApplication().getType().equalsIgnoreCase("IPA")) {
            appiumDriver = new AppiumDriver(new URL("http://" + tCExecution.getSession().getHost() + ":"
                    + tCExecution.getSession().getPort() + "/wd/hub"), caps);
            driver = (WebDriver) appiumDriver;
        }

        tCExecution.getSession().setDriver(driver);
        tCExecution.getSession().setAppiumDriver(appiumDriver);

        /**
         * If Gui application, maximize window Get IP of Node in case of
         * remote Server
         */
        if (tCExecution.getApplication().getType().equalsIgnoreCase("GUI")
                && !caps.getPlatform().equals(Platform.ANDROID)) {
            driver.manage().window().maximize();
            getIPOfNode(tCExecution);

            /**
             * If screenSize is defined, set the size of the screen.
             */
            if (!tCExecution.getScreenSize().equals("")) {
                Integer screenWidth = Integer.valueOf(tCExecution.getScreenSize().split("\\*")[0]);
                Integer screenLength = Integer.valueOf(tCExecution.getScreenSize().split("\\*")[1]);
                setScreenSize(driver, screenWidth, screenLength);
            }
            tCExecution.setScreenSize(getScreenSize(driver));
        }
        tCExecution.getSession().setStarted(true);

    } catch (CerberusException exception) {
        MyLogger.log(Selenium.class.getName(), Level.ERROR, exception.toString());
        throw new CerberusException(exception.getMessageError());
    } catch (MalformedURLException exception) {
        MyLogger.log(Selenium.class.getName(), Level.ERROR, exception.toString());
        MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_URL_MALFORMED);
        mes.setDescription(mes.getDescription().replace("%URL%",
                tCExecution.getSession().getHost() + ":" + tCExecution.getSession().getPort()));
        throw new CerberusException(mes);
    } catch (UnreachableBrowserException exception) {
        MyLogger.log(Selenium.class.getName(), Level.ERROR, exception.toString());
        MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_SELENIUM_COULDNOTCONNECT);
        mes.setDescription(mes.getDescription().replace("%SSIP%", tCExecution.getSeleniumIP()));
        mes.setDescription(mes.getDescription().replace("%SSPORT%", tCExecution.getSeleniumPort()));
        throw new CerberusException(mes);
    } catch (Exception exception) {
        MyLogger.log(Selenium.class.getName(), Level.ERROR, exception.toString());
        MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);
        mes.setDescription(mes.getDescription().replace("%MES%", exception.toString()));
        throw new CerberusException(mes);
    }
}

From source file:org.cerberus.service.engine.impl.SeleniumServerService.java

License:Open Source License

private DesiredCapabilities setCapabilities(TestCaseExecution tCExecution) throws CerberusException {
    DesiredCapabilities caps = new DesiredCapabilities();
    for (SessionCapabilities cap : tCExecution.getSession().getCapabilities()) {
        if (!cap.getValue().equals("")) {
            if (tCExecution.getApplication().getType().equalsIgnoreCase("GUI")) {
                if (cap.getCapability().equalsIgnoreCase("browser")) {
                    caps = this.setCapabilityBrowser(caps, cap.getValue(), tCExecution);
                } else {
                    caps.setCapability(cap.getCapability(), cap.getValue());
                }//w ww . j  a v a 2 s  .  c  o  m
                if (caps.getPlatform().is(Platform.ANDROID)) {
                    caps = new DesiredCapabilities();
                    caps.setCapability("deviceName", "Android");
                    caps.setCapability("platformName", "Android");
                    caps.setCapability(CapabilityType.PLATFORM, Platform.ANDROID);
                    caps.setCapability("app", "Chrome");
                    caps.setCapability("browserName", "");
                    caps.setCapability("automationName", "Appium");
                }
            }
        }
        if (tCExecution.getApplication().getType().equalsIgnoreCase("APK")) {
            caps.setCapability(CapabilityType.BROWSER_NAME, "");
            caps.setCapability("deviceName", "Android");
            caps.setCapability("automationName", "Appium");
            caps.setCapability("platformName", "Android");
            caps.setCapability("autoWebview", true);
        }
        if (tCExecution.getApplication().getType().equalsIgnoreCase("IPA")) {
            caps.setCapability(CapabilityType.BROWSER_NAME, "");
            caps.setCapability("deviceName", "iPhone 5s");
            caps.setCapability("automationName", "Appium");
            caps.setCapability("platformName", "iOS");
            caps.setCapability("platformVersion", "9.1");
            caps.setCapability("autoWebview", true);

        }

    }
    /**
     * If android app, set app capability with the link where is stored the
     * apk
     */
    if (tCExecution.getApplication().getType().equalsIgnoreCase("APK")
            || tCExecution.getApplication().getType().equalsIgnoreCase("IPA")) {
        File app = new File(tCExecution.getCountryEnvironmentParameters().getIp());
        caps.setCapability("app", tCExecution.getCountryEnvironmentParameters().getIp());
    }
    return caps;
}