Example usage for org.openqa.selenium.remote RemoteWebDriver RemoteWebDriver

List of usage examples for org.openqa.selenium.remote RemoteWebDriver RemoteWebDriver

Introduction

In this page you can find the example usage for org.openqa.selenium.remote RemoteWebDriver RemoteWebDriver.

Prototype

public RemoteWebDriver(URL remoteAddress, Capabilities capabilities) 

Source Link

Usage

From source file:com.zaizi.automation.alfresco.core.info.TestCaseProperties.java

License:Open Source License

public static WebDriver gridDriver(String browser, String operatingSystem) throws MalformedURLException {
    if (driver != null) {
        closeDriver(driver);/*  w  w  w.ja  va  2  s .c  om*/
    }
    if ("Firefox".equals(browser) && "MAC".equals(operatingSystem)) {
        DesiredCapabilities capability = DesiredCapabilities.firefox();
        capability.setBrowserName("firefox");
        capability.setCapability("ignoreZoomSetting", true);
        capability.setPlatform(Platform.MAC);
        capability.setVersion("ANY");
        capability.setCapability("nativeEvents", false);
        driver = new RemoteWebDriver(new URL(FFNODEURL), capability);
    } else if ("Firefox".equals(browser) && "VISTA".equals(operatingSystem)) {
        DesiredCapabilities capability = DesiredCapabilities.firefox();
        capability.setBrowserName("firefox");
        capability.setCapability("ignoreZoomSetting", true);
        capability.setPlatform(Platform.VISTA);
        capability.setVersion("ANY");
        capability.setCapability("nativeEvents", false);
        driver = new RemoteWebDriver(new URL(FFNODEURL), capability);
    } else if ("Firefox".equals(browser) && "WINDOWS".equals(operatingSystem)) {
        DesiredCapabilities capability = DesiredCapabilities.firefox();
        capability.setBrowserName("firefox");
        capability.setCapability("ignoreZoomSetting", true);
        capability.setPlatform(Platform.WINDOWS);
        capability.setVersion("ANY");
        capability.setCapability("nativeEvents", false);
        driver = new RemoteWebDriver(new URL(FFNODEURL), capability);
    } else if ("Chrome".equals(browser) && "VISTA".equals(operatingSystem)) {
        DesiredCapabilities capability = DesiredCapabilities.chrome();
        capability.setBrowserName("chrome");
        capability.setCapability("ignoreZoomSetting", true);
        capability.setPlatform(Platform.VISTA);
        capability.setVersion("ANY");
        capability.setCapability("nativeEvents", false);
        driver = new RemoteWebDriver(new URL(CHROMENODEURL), capability);
    } else if ("Chrome".equals(browser) && "MAC".equals(operatingSystem)) {
        DesiredCapabilities capability = DesiredCapabilities.chrome();
        capability.setBrowserName("chrome");
        capability.setCapability("ignoreZoomSetting", true);
        capability.setPlatform(Platform.MAC);
        capability.setVersion("ANY");
        capability.setCapability("nativeEvents", false);
        driver = new RemoteWebDriver(new URL(CHROMENODEURL), capability);
    } else if ("Chrome".equals(browser) && "WINDOWS".equals(operatingSystem)) {
        DesiredCapabilities capability = DesiredCapabilities.chrome();
        capability.setBrowserName("chrome");
        capability.setCapability("ignoreZoomSetting", true);
        capability.setPlatform(Platform.WINDOWS);
        capability.setVersion("ANY");
        capability.setCapability("nativeEvents", false);
        driver = new RemoteWebDriver(new URL(CHROMENODEURL), capability);
    } else if ("IE".equals(browser) && "VISTA".equals(operatingSystem)) {
        DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
        capability.setBrowserName("internet explorer");
        capability.setCapability("ignoreZoomSetting", true);
        capability.setPlatform(Platform.VISTA);
        capability.setVersion("ANY");
        capability.setCapability("nativeEvents", false);
        capability.setCapability("name", "Remote File Upload using Selenium 2's FileDetectors");
        driver = new RemoteWebDriver(new URL(IENODEURL), capability);
    } else if ("IE".equals(browser) && "WINDOWS".equals(operatingSystem)) {
        DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
        capability.setBrowserName("internet explorer");
        capability.setCapability("ignoreZoomSetting", true);
        capability.setPlatform(Platform.WINDOWS);
        capability.setVersion("ANY");
        capability.setCapability("nativeEvents", false);
        driver = new RemoteWebDriver(new URL(IENODEURL), capability);
    } else if ("Safari".equals(browser) && "MAC".equals(operatingSystem)) {
        DesiredCapabilities capability = DesiredCapabilities.safari();
        capability.setBrowserName("safari");
        capability.setCapability("ignoreZoomSetting", true);
        capability.setPlatform(Platform.MAC);
        capability.setVersion("ANY");
        capability.setCapability("nativeEvents", false);
        driver = new RemoteWebDriver(new URL(IENODEURL), capability);
    }
    return driver;
}

From source file:core.Starter.java

License:Apache License

/**
* Start the requested web driver/*w w  w. ja  va2s .co  m*/
*/
private static void setupDriver() {

    if (parseArgs.getChromeDriverPath() != null) {

        String path_to_chromedriver = parseArgs.getChromeDriverPath();

        service = new ChromeDriverService.Builder().usingDriverExecutable(new File(path_to_chromedriver))
                .usingAnyFreePort().build();

        try {
            service.start();
        } catch (IOException e) {
            Debug.printError("ERROR: unable to load Chrome server. \n" + e.getMessage());
            HaltHandler.quit_nok();
        }

        // disable the built-in Chrome XSS filter
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability("chrome.switches",
                Arrays.asList("--disable-xss-auditor", "--disable-extensions"));

        if (parseArgs.getProxyInfo() != null)
            capabilities.setCapability("chrome.switches",
                    Arrays.asList("--proxy-server=" + parseArgs.getProxyInfo()));

        driver = new RemoteWebDriver(service.getUrl(), capabilities);

        usedBrowser = "Google Chrome";
    } else if (parseArgs.getEnabledIE()) {
        IE_enabled = true;

        if (parseArgs.getProxyInfo() != null) {
            String proxy_conf = parseArgs.getProxyInfo();

            org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
            proxy.setHttpProxy(proxy_conf).setFtpProxy(proxy_conf).setSslProxy(proxy_conf);
            DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
            cap.setCapability(CapabilityType.PROXY, proxy);
            driver = new InternetExplorerDriver(cap);
        } else {
            String path_to_IEdriver = parseArgs.getIEDriverPath();

            File file = new File(path_to_IEdriver);
            System.setProperty("webdriver.ie.driver", file.getAbsolutePath());

            driver = new InternetExplorerDriver();
        }

        usedBrowser = "Internet Explorer";
    } else {

        if (parseArgs.getProxyInfo() != null) {
            String proxy_conf = parseArgs.getProxyInfo();

            org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
            proxy.setHttpProxy(proxy_conf).setFtpProxy(proxy_conf).setSslProxy(proxy_conf);
            DesiredCapabilities cap = new DesiredCapabilities();
            cap.setCapability(CapabilityType.PROXY, proxy);
            driver = new FirefoxDriver(cap);
        } else {
            driver = new FirefoxDriver();
        }

        usedBrowser = "Mozilla Firefox";
    }
}

From source file:de.dentrassi.pm.testing.TestSuite.java

License:Open Source License

protected static RemoteWebDriver createSauce(final Platform os, final String browser, final String version)
        throws MalformedURLException {
    final DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, browser);
    if (version != null) {
        capabilities.setCapability(CapabilityType.VERSION, version);
    }// ww  w .  j ava2  s. c o  m
    capabilities.setCapability(CapabilityType.PLATFORM, os);
    capabilities.setCapability("name", "Package Drone Main Test");

    final RemoteWebDriver driver = new RemoteWebDriver(new URL(
            String.format("http://%s:%s@ondemand.saucelabs.com:80/wd/hub", SAUCE_USER_NAME, SAUCE_ACCESS_KEY)),
            capabilities);

    driver.setFileDetector(new LocalFileDetector());

    return driver;
}

From source file:de.iteratec.iteraplan.webtests.poc.WebDriverManager.java

License:Open Source License

/**
 * Returns the webdriver instance/*  w w w .j ava 2s.co m*/
 * @return webdriver instance
 */
public WebDriver getDriver() {
    if (browser_capabilities == null) {
        LOGGER.error("You need capabilities first!");
        return null;
    } else if (driver == null) {
        try {
            Capabilities capabilities = new DesiredCapabilities(browser_capabilities);
            driver = new RemoteWebDriver(
                    new URL("http://" + selenium_hub_url + ":" + selenium_hub_port + "/wd/hub"), capabilities);
            driver.manage().timeouts().implicitlyWait(WAIT_TIMEOUT, TimeUnit.SECONDS);
            driver.manage().window().maximize();
            driver = new Augmenter().augment(driver); //the driver can now take Screenshots
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } finally {
            LOGGER.info("Returning the instance of webdriver");
        }
    }
    return driver;
}

From source file:de.knowwe.uitest.UITestUtils.java

License:Open Source License

public static RemoteWebDriver setUp(String browser, String testClassName, Platform os, WikiTemplate template,
        String testName, boolean devMode) throws IOException, InterruptedException {

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, browser);
    String chromeBinary = System.getProperty("knowwe.chrome.binary");
    if (chromeBinary != null) {
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.setBinary(chromeBinary);
        capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
    }//from  w ww . j a v  a2s  .c  om

    RemoteWebDriver driver;
    if (devMode) {
        driver = new RemoteWebDriver(new URL("http://localhost:9515"), capabilities);
    } else {
        capabilities.setCapability("name", testClassName);
        capabilities.setCapability("platform", os);
        driver = new RemoteWebDriver(
                new URL("http://d3web:8c7e5a48-56dd-4cde-baf0-b17f83803044@ondemand.saucelabs.com:80/wd/hub"),
                capabilities);
    }
    driver.manage().window().setSize(new Dimension(1024, 768));
    driver.get(UITestUtils.getKnowWEUrl(template, "Main", devMode));
    if (!UITestUtils.isLoggedIn(driver, template)) {
        UITestUtils.logIn(driver, "UiTest", "fyyWWyVeHzzHfkUMZxUQ?3nDBPbTT6", NORMAL_PAGE, template);
    }
    driver.get(getKnowWEUrl(template, testName, devMode));
    if (!pageExists(template, driver)) {
        createDummyPage(template, driver);
    }
    return driver;
}

From source file:de.learnlib.alex.learning.entities.webdrivers.RemoteDriverConfig.java

License:Apache License

@Override
public WebDriver createDriver() throws Exception {
    final URL remoteURL = new URL(System.getProperty("webdriver.remote.url"));

    final DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setPlatform(platform);//from w w  w .jav  a  2s.  c om
    capabilities.setBrowserName(browser);

    switch (browser) {
    case "chrome":
        final ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.setHeadless(headless);
        capabilities.merge(chromeOptions);
        break;
    case "firefox":
        final FirefoxOptions firefoxOptions = new FirefoxOptions();
        firefoxOptions.setHeadless(headless);
        capabilities.merge(firefoxOptions);
        break;
    default:
        break;
    }

    if (!version.trim().equals("")) {
        capabilities.setVersion(version);
    }

    final WebDriver driver = new RemoteWebDriver(remoteURL, capabilities);
    manage(driver);
    return driver;
}

From source file:de.ppi.selenium.browser.DefaultWebDriverFactory.java

License:Apache License

@Override
public WebDriver createWebDriver(Map<String, String> options, DesiredCapabilities capabilities)
        throws IOException {
    ClientProperties properties = new ClientProperties(options.get(CLIENT_PROPERTIES_KEY));

    WebDriver wd = null;/*  w w w  .j a  va2  s.c om*/
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities(capabilities);
    String browser = properties.getBrowser();

    if (properties.isUseGrid()) {
        RemoteWebDriver remoteWebDriver = new RemoteWebDriver(new URL(properties.getGridUrl()), capabilities);
        remoteWebDriver.setFileDetector(new LocalFileDetector());
        wd = remoteWebDriver;
    } else {
        if (browser == null || browser.equals("")) {
            throw new RuntimeException(
                    "Browser cannot be null. Please set 'browser' in client properties. Supported browser types: IE, Firefox, Chrome, Safari, HtmlUnit.");
        } else if (browser.equalsIgnoreCase("ie") || browser.equalsIgnoreCase("iexplore")
                || browser.equalsIgnoreCase("*iexplore")) {
            String webdriverIEDriver = properties.getWebDriverIEDriver();

            if (webdriverIEDriver != null) {
                System.setProperty("webdriver.ie.driver", webdriverIEDriver);
            }

            String browserVersion = properties.getBrowserVersion();

            if (browserVersion == null || browserVersion.equals("")) {
                throw new RuntimeException(
                        "When using IE as the browser, please set 'browser.version' in client properties");
            } else {
                if (browserVersion.startsWith("9")) {
                    desiredCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
                    desiredCapabilities.setCapability(
                            InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
                    wd = new InternetExplorerDriver(desiredCapabilities);
                } else {
                    wd = new InternetExplorerDriver(desiredCapabilities);
                }
            }
        } else if ((browser.equalsIgnoreCase("firefox") || browser.equalsIgnoreCase("*firefox"))) {
            final String ffProfileFolder = properties.getFirefoxProfileFolder();
            final String ffProfileFile = properties.getFirefoxProfileFile();
            final String path = properties.getFfBinaryPath();
            final FirefoxProfile ffp;
            if (ffProfileFolder != null) {
                ffp = new FirefoxProfile(new File(ffProfileFolder));
            } else {
                ffp = new FirefoxProfile();
            }

            if (ffProfileFile != null) {
                addPreferences(ffp, ffProfileFile);
            }

            addPreferences(ffp, properties);

            List<String> ffExtensions = properties.getFirefoxExtensions();
            if (ffExtensions != null && ffExtensions.size() > 0) {
                addExtensionsToFirefoxProfile(ffp, ffExtensions);
            }

            if (path != null) {
                FirefoxBinary fireFox = getFFBinary(path);
                wd = new FirefoxDriver(fireFox, ffp, desiredCapabilities);
            } else {
                wd = new FirefoxDriver(new FirefoxBinary(), ffp, desiredCapabilities);

            }
        } else if (browser.equalsIgnoreCase("chrome")) {

            final String webdriverChromeDriver = properties.getWebDriverChromeDriver();

            if (webdriverChromeDriver != null) {
                System.setProperty("webdriver.chrome.driver", webdriverChromeDriver);
            }

            final ChromeOptions chromeOptions = new ChromeOptions();
            final String chromeBinaryPath = properties.getChromeBinaryPath();
            if (chromeBinaryPath != null) {
                chromeOptions.setBinary(chromeBinaryPath);
            }

            if (properties.getAcceptedLanguages() != null) {

                final Map<String, Object> prefs = new HashMap<String, Object>();
                prefs.put("intl.accept_languages", properties.getAcceptedLanguages());
                chromeOptions.setExperimentalOption("prefs", prefs);
            }
            desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);

            wd = new ChromeDriver(desiredCapabilities);

        } else if (browser.equalsIgnoreCase("safari")) {
            wd = new SafariDriver(desiredCapabilities);
        } else if (browser.equalsIgnoreCase("htmlunit")) {
            final BrowserVersion browserVersion = BrowserVersion.FIREFOX_45;
            if (properties.getAcceptedLanguages() != null) {
                browserVersion.setBrowserLanguage(properties.getAcceptedLanguages().split(",")[0]);
            }
            wd = new HtmlUnitDriver(browserVersion);
            ((HtmlUnitDriver) wd).setJavascriptEnabled(true);
        } else if (browser.equalsIgnoreCase("phantomjs")) {
            final String webdriverPhantomJSDriver = properties.getWebDriverPhantomJSDriver();
            if (properties.getAcceptedLanguages() != null) {
                desiredCapabilities.setCapability("phantomjs.page.customHeaders.Accept-Language",
                        properties.getAcceptedLanguages());
            }

            if (webdriverPhantomJSDriver != null) {
                desiredCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
                        webdriverPhantomJSDriver);
                wd = new PhantomJSDriver(desiredCapabilities);
            } else {
                wd = new PhantomJSDriver(ResolvingPhantomJSDriverService.createDefaultService(),
                        desiredCapabilities);
            }
        } else {
            throw new IllegalArgumentException("Unsupported browser type: " + browser
                    + ". Supported browser types: IE, Firefox, Chrome, Safari, HtmlUnit, phantomjs.");
        }

        // move browser windows to specific position. It's useful for
        // debugging...
        final int browserInitPositionX = properties.getBrowserInitPositionX();
        final int browserInitPositionY = properties.getBrowserInitPositionY();
        if (browserInitPositionX != 0 || browserInitPositionY != 0) {
            wd.manage().window().setSize(new Dimension(1280, 1024));
            wd.manage().window().setPosition(new Point(browserInitPositionX, browserInitPositionY));
        }
        wd.manage().timeouts().implicitlyWait(properties.getAppearWaitTime(), TimeUnit.MILLISECONDS);
    }

    return wd;
}

From source file:douban.spider.DoubanLogin.java

/**
 * ?chrome??/*w w w  .j av  a  2 s  .c  o  m*/
 *
 * @return WebDriver
 */
public static WebDriver getWebDriver() {
    File file = new File("exe\\chromedriver.exe"); //chromediriver

    ChromeDriverService service = new ChromeDriverService.Builder().usingDriverExecutable(file)
            .usingAnyFreePort().build();
    try {
        service.start();
    } catch (IOException ex) {
        Logger.getLogger(DoubanMovieSpider.class.getName()).log(Level.SEVERE, null, ex);
    }
    WebDriver dr = new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome());
    dr.get("https://accounts.douban.com/login?source=movie");
    try {
        Thread.sleep(30000);
    } catch (InterruptedException ex) {
        Logger.getLogger(DoubanLogin.class.getName()).log(Level.SEVERE, null, ex);
    }
    return dr;
}

From source file:edu.samplu.admin.test.DocumentSearchURLParametersIT.java

License:Educational Community License

@Before
public void setUp() throws Exception {
    driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), DesiredCapabilities.firefox());
    // default to locally running dev sampleapp
    base = StringUtils.defaultIfEmpty(System.getProperty("remote.public.url"), "http://localhost:8080/kr-dev");
}

From source file:edu.samplu.common.SauceLabsWebDriverHelper.java

License:Educational Community License

/**
 * Saucelabs setup/*ww w  .j  a  v  a  2  s  .c o m*/
 * @param className
 * @param testName
 * @throws Exception
 */
public void setUp(String className, String testName) throws Exception {
    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,
                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", version);
    }

    capabilities.setCapability("platform",
            System.getProperty(SAUCE_PLATFORM_PROPERTY, Platform.UNIX.toString()).replaceAll("_", " "));
    capabilities.setCapability("idle-timeout", 180);
    capabilities.setCapability("max-duration", 480);
    capabilities.setCapability("name", className + "." + testName + "-" + ITUtil.DTS);
    capabilities.setCapability("disable-popup-handler", System.getProperty(SAUCE_POPUP_PROPERTY, "false"));
    capabilities.setCapability("public", System.getProperty(SAUCE_SHARE_PROPERTY, "share"));

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

    // TODO it would be better to do these at tear down, passing state could then be included in names, but requires more parameters
    try {
        String dir = determineSaveDir(className, testName);
        String resources = "mkdir " + dir + " ; cd " + dir + " ; \n"
                + curlSaveResourceString(className, testName, "selenium-server.log") + " ; \n"
                + curlSaveResourceString(className, testName, "video.flv") + " ; \n"
                + wgetnSaveResourceString(className, testName) + " ; \n" + "cd ../\n";
        System.out.println(resources);
        writeFile("SauceLabsResources" + dir + ".sh", resources);
    } catch (Exception e) {
        System.out.println("Exception while writing SauceLabsResources.sh " + e.getMessage());
        System.out.println(curlSaveResourceString(className, testName, "selenium-server.log"));
        System.out.println(curlSaveResourceString(className, testName, "video.flv"));
        //            System.out.println(curlSaveResourceString(className, testName, "XXXXscreenshot.png (where XXXX is a number between 0000 and 9999)")); // TODO
    }
}