Java Code Examples for org.openqa.selenium.remote.DesiredCapabilities#android()

The following examples show how to use org.openqa.selenium.remote.DesiredCapabilities#android() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SearchOnAndroidTest.java    From Selenium-WebDriver-3-Practical-Guide-Second-Edition with MIT License 6 votes vote down vote up
@BeforeTest
public void setUp() throws Exception {

    // Set the desired capabilities for Android Device
    DesiredCapabilities caps = DesiredCapabilities.android();
    caps.setCapability("deviceOrientation", "portrait");
    caps.setCapability("platformVersion", "8.1");
    caps.setCapability("platformName", "Android");
    caps.setCapability("browserName", "Chrome");

    // Create an instance of AndroidDriver for testing on Android platform
    // connect to the local Appium server running on a different machine
    // We will use WebElement type for testing the Web application
    driver = new AndroidDriver<WebElement>(new URL(
            "http://192.168.0.101:4723/wd/hub"), caps);
    driver.get("http://demo-store.seleniumacademy.com/");
}
 
Example 2
Source File: SauceLabsWebDriverHelper.java    From rice with Educational Community License v2.0 4 votes vote down vote up
/**
 * <p>
 * Saucelabs setUp.
 * </p><p>
 * Creates a {@link org.openqa.selenium.remote.RemoteWebDriver} instance with the DesiredCapabilities as configured
 * using the JVM arguments described as SAUCE_ Constants in this class.  After setUp the WebDriver can be accessed via
 * {@see #getDriver}.  You'll also need {@see #getSessionId} for when you call {@see #tearDown}
 * </p>
 *
 * @param className class name of the test being setup as a String
 * @param testName test name of the test being setup as a String
 * @throws Exception
 */
public void setUp(String className, String testName) throws Exception {
    if (System.getProperty(REMOTE_DRIVER_SAUCELABS_PROPERTY) == null) { // dup guard so WebDriverUtils doesn't have to be used.
        return;
    }

    if (System.getProperty(SAUCE_USER_PROPERTY) == null || System.getProperty(SAUCE_KEY_PROPERTY) == null) {
        Assert.fail("-D" + SAUCE_USER_PROPERTY + " and -D" + SAUCE_KEY_PROPERTY + " must be set to saucelabs user and access key.");
    }

    DesiredCapabilities capabilities = null;
    if ("ff".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) {
        capabilities = DesiredCapabilities.firefox();
    } else if ("ie".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY)))  {
        capabilities = DesiredCapabilities.internetExplorer();
        capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
            System.getProperty(SAUCE_IE_INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS_PROPERTY, "true"));
    } else if ("chrome".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY)))  {
        capabilities = DesiredCapabilities.chrome();
    } else if ("opera".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY)))  {
        capabilities = DesiredCapabilities.opera();
    } else if ("android".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY)))  {
        capabilities = DesiredCapabilities.android();
    } else if ("safari".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY)))  {
        capabilities = DesiredCapabilities.safari();
    } else if ("ipad".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY)))  {
        capabilities = DesiredCapabilities.ipad();
    } else if ("iphone".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY)))  {
        capabilities = DesiredCapabilities.iphone();
    } else {
        capabilities = DesiredCapabilities.firefox();
    }

    String version = System.getProperty(SAUCE_VERSION_PROPERTY);
    if (version == null || "0".equals(version)) { // Blank or 0 leaves version blank for use with chrome

        if (!"chrome".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) {
            throw new RuntimeException("Blank or 0 version for a browser not chrome " + System.getProperty(SAUCE_BROWSER_PROPERTY));
        }

        capabilities.setCapability("version", ""); // saucelabs requires blank for chrome (latest version)
    } else {
        capabilities.setCapability("version", version); // saucelabs requires blank for chrome (latest version)
    }

    capabilities.setCapability("platform", System.getProperty(SAUCE_PLATFORM_PROPERTY, Platform.UNIX.toString()).replaceAll("_", " "));
    capabilities.setCapability("idle-timeout", Integer.parseInt(System.getProperty(SAUCE_IDLE_TIMEOUT_SECONDS_PROPERTY, "180")));
    capabilities.setCapability("max-duration", Integer.parseInt(System.getProperty(SAUCE_MAX_DURATION_SECONDS_PROPERTY, "600")));
    capabilities.setCapability("name",  className + "." + testName + "-" + AutomatedFunctionalTestUtils.DTS);
    capabilities.setCapability("disable-popup-handler", System.getProperty(SAUCE_POPUP_PROPERTY, "false"));
    capabilities.setCapability("public", System.getProperty(SAUCE_SHARE_PROPERTY, "public restricted"));

    System.out.println("Requesting Saucelabs RemoteWebDriver with DesiredCapabilities of " + capabilities.toString());

    this.driver = new RemoteWebDriver(
            new URL("http://" + authentication.getUsername() + ":" + authentication.getAccessKey() + "@ondemand.saucelabs.com:80/wd/hub"),
            capabilities);
    this.sessionId = ((RemoteWebDriver)driver).getSessionId().toString();

    System.out.println("SauceLabs job can be viewed at https://saucelabs.com/jobs/" + this.sessionId);
}