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:influent.selenium.tests.BrowserParameterizedTest.java

License:MIT License

private void initializeRemote(BROWSER browser, URI host) throws MalformedURLException {
    switch (browser) {
    case FIREFOX:
        this.driver = new RemoteWebDriver(host.toURL(), DesiredCapabilities.firefox());
        break;/*from   www .ja  v a  2  s. c o  m*/
    case CHROME:
        // need to set a property for the chrome webdriver
        System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "\\chromedriver.exe");
        this.driver = new RemoteWebDriver(host.toURL(), DesiredCapabilities.chrome());
        break;
    case IE:
        // need to set a property for the internet explorer webdriver
        System.setProperty("webdriver.ie.driver", System.getProperty("user.dir") + "\\IEDriverServer.exe");
        this.driver = new RemoteWebDriver(host.toURL(), DesiredCapabilities.internetExplorer());
        break;
    default:
        this.driver = null;
        break;
    }
}

From source file:info.magnolia.integrationtests.uitest.AbstractMagnoliaUITest.java

License:Open Source License

/**
 * Returns a new {@link WebDriver} to be used for all tests.
 *
 * If a system property {@link #SELENIUM_SERVER_HOST_NAME} was provided with a hostname a {@link RemoteWebDriver} will be
 * returned, otherwise the default {@link FirefoxDriver}.
 *///w w  w  . ja va 2s .c  o  m
protected WebDriver getNewWebDriver() {
    // Set the download dir which might be overwritten in subclasses
    firefoxProfile.setPreference("browser.download.dir", getDownloadDir());

    // Set our custom profile as desired capabilities
    capabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);

    // If a vmHostName was supplied then we're executing the tests in a Virtual Machine
    String vmHostName = System.getProperty(SELENIUM_SERVER_HOST_NAME);
    if (StringUtils.isNotBlank(vmHostName)) {
        try {
            URL seleniumServerUrl = new URL(String.format("http://%s:4444/wd/hub", vmHostName));
            return new RemoteWebDriver(seleniumServerUrl, capabilities);
        } catch (MalformedURLException e) {
            log.error("VM hostname was set [{}] but couldn't setup URL", vmHostName, e);
        }
    }

    return new FirefoxDriver(capabilities);
}

From source file:io.ddavison.conductor.Locomotive.java

License:Open Source License

public Locomotive() {
    final Properties props = new Properties();
    try {/*from   w w  w. ja v a 2 s  . c  o  m*/
        props.load(getClass().getResourceAsStream("/default.properties"));
    } catch (IOException e) {
        logFatal("Couldn't load in default properties");
    } catch (Exception e) {
    }

    /**
     * Order of overrides:
     * <ol>
     *     <li>Test</li>
     *     <li>JVM Arguments</li>
     *     <li>Default properties</li>
     * </ol>
     */
    final Config testConfiguration = getClass().getAnnotation(Config.class);

    configuration = new LocomotiveConfig(testConfiguration, props);

    DesiredCapabilities capabilities;

    Capabilities extraCapabilities;
    try {
        extraCapabilities = configuration.capabilities().newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        e.printStackTrace();
        logFatal(e.getMessage());
        System.exit(1);
        return;
    }

    baseUrl = configuration.url();

    log.debug(String.format(
            "\n=== Configuration ===\n" + "\tURL:     %s\n" + "\tBrowser: %s\n" + "\tHub:     %s\n"
                    + "\tBase url: %s\n",
            configuration.url(), configuration.browser().moniker, configuration.hub(),
            configuration.baseUrl()));

    boolean isLocal = StringUtils.isEmpty(configuration.hub());

    switch (configuration.browser()) {
    case CHROME:
        capabilities = DesiredCapabilities.chrome();
        capabilities.merge(extraCapabilities);
        if (isLocal)
            try {
                driver = new ChromeDriver(capabilities);
            } catch (Exception x) {
                x.printStackTrace();
                logFatal(
                        "Also see https://github.com/conductor-framework/conductor/wiki/WebDriver-Executables");
                System.exit(1);
            }
        break;
    case FIREFOX:
        capabilities = DesiredCapabilities.firefox();
        capabilities.merge(extraCapabilities);
        if (isLocal)
            try {
                driver = new FirefoxDriver(capabilities);
            } catch (Exception x) {
                x.printStackTrace();
                logFatal(
                        "Also see https://github.com/conductor-framework/conductor/wiki/WebDriver-Executables");
                System.exit(1);
            }
        break;
    case INTERNET_EXPLORER:
        capabilities = DesiredCapabilities.internetExplorer();
        capabilities.merge(extraCapabilities);
        if (isLocal)
            try {
                driver = new InternetExplorerDriver(capabilities);
            } catch (Exception x) {
                x.printStackTrace();
                logFatal(
                        "Also see https://github.com/conductor-framework/conductor/wiki/WebDriver-Executables");
                System.exit(1);
            }
        break;
    case EDGE:
        capabilities = DesiredCapabilities.edge();
        capabilities.merge(extraCapabilities);
        if (isLocal)
            try {
                driver = new EdgeDriver(capabilities);
            } catch (Exception x) {
                x.printStackTrace();
                logFatal(
                        "Also see https://github.com/conductor-framework/conductor/wiki/WebDriver-Executables");
                System.exit(1);
            }
        break;
    case SAFARI:
        capabilities = DesiredCapabilities.safari();
        capabilities.merge(extraCapabilities);
        if (isLocal)
            try {
                driver = new SafariDriver(capabilities);
            } catch (Exception x) {
                x.printStackTrace();
                logFatal(
                        "Also see https://github.com/conductor-framework/conductor/wiki/WebDriver-Executables");
                System.exit(1);
            }
        break;
    case PHANTOMJS:
        capabilities = DesiredCapabilities.phantomjs();
        capabilities.merge(extraCapabilities);
        if (isLocal)
            try {
                driver = new PhantomJSDriver(capabilities);
            } catch (Exception x) {
                x.printStackTrace();
                logFatal(
                        "Also see https://github.com/conductor-framework/conductor/wiki/WebDriver-Executables");
                System.exit(1);
            }
        break;
    default:
        System.err.println("Unknown browser: " + configuration.browser());
        return;
    }

    if (!isLocal)
        // they are using a hub.
        try {
            capabilities.merge(extraCapabilities);
            driver = new RemoteWebDriver(new URL(configuration.hub()), capabilities); // just override the driver.
        } catch (Exception x) {
            logFatal("Couldn't connect to hub: " + configuration.hub());
            x.printStackTrace();
            return;
        }

    actions = new Actions(driver);

    if (StringUtils.isNotEmpty(baseUrl))
        driver.navigate().to(baseUrl);
}

From source file:io.github.blindio.prospero.core.browserdrivers.BrowserDriverFactory.java

License:Apache License

/**
 * builds a WebDriver object for the correct Browser based upon the property
 * 'browser'/*w  w w.  j  av a  2s  .  co  m*/
 * 
 * @param siteURL
 * @return
 */
private static WebDriver buildWebDriver() {
    WebDriver wd = null;
    Browser browser = getBrowserFromConfig();

    // TODO: this needs a lot more work with Capabilities
    if (browser == Browser.FIREFOX) {
        wd = new FirefoxDriver();
    }

    else if (browser == Browser.HTMLUNIT) {
        wd = new HtmlUnitDriver(true);
    }

    else if (browser == Browser.INTERNET_EXPLORER) {
        System.setProperty(IE_WEBDRIVER_SYS_OPTION, Config.getString(PropertiesConstants.DRIVER_LOCATION));

        wd = new InternetExplorerDriver();
    }

    else if (browser == Browser.CHROME) {
        System.setProperty(CHROME_WEBDRIVER_SYS_OPTION, Config.getString(PropertiesConstants.DRIVER_LOCATION));

        wd = new ChromeDriver();
    }

    else if (browser == Browser.ANDROID) {
        if (Config.containsKey(PropertiesConstants.REMOTE_WEBDRIVER_URL)) {
            try {
                wd = new RemoteWebDriver(new URL(Config.getString(PropertiesConstants.REMOTE_WEBDRIVER_URL)),
                        DesiredCapabilities.android());
            } catch (MalformedURLException mue) {
                throw new ProsperoParseException(mue);
            }
        } else {
            wd = new AndroidDriver();
        }
    }

    else if (browser == Browser.IPHONE || browser == Browser.IPAD) {
        DesiredCapabilities dc;
        if (browser == Browser.IPHONE) {
            dc = DesiredCapabilities.iphone();
        } else {
            dc = DesiredCapabilities.ipad();
        }

        try {
            wd = new RemoteWebDriver(
                    new URL(Config.getString(PropertiesConstants.REMOTE_WEBDRIVER_URL, DEFAULT_IWEBDRIVER_URL)),
                    dc);
        } catch (MalformedURLException mue) {
            throw new ProsperoParseException(mue);
        }
    }

    else if (browser == Browser.GHOSTDRIVER) {
        // TODO
        // Find open socket
        // ServerSocket sock = new ServerSocket(0);
        // int openPort = sock.getLocalPort();
        // sock.close();

        // String phantomjsServerStartCmd = "phantomjs";
        // Runtime.getRuntime().exec();

        String phantomJSExecutable = PhantomJSInstaller.getPhantomJS();
        DesiredCapabilities dCaps = new DesiredCapabilities();
        dCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomJSExecutable);
        dCaps.setJavascriptEnabled(true);
        dCaps.setCapability("takesScreenshot", false);
        wd = new PhantomJSDriver(dCaps);
    }

    if (browser.isWindowed() && Config.containsKey(PropertiesConstants.BROWSER_WIDTH)
            && Config.containsKey(PropertiesConstants.BROWSER_HEIGHT)) {
        wd.manage().window().setSize(getBrowserDimensions());
    }

    return wd;
}

From source file:io.github.bonigarcia.wdm.test.EusTest.java

License:Apache License

@Before
public void setupTest() throws MalformedURLException {
    DesiredCapabilities capability = DesiredCapabilities.chrome();
    driver = new RemoteWebDriver(new URL("http://localhost:8040/eus/v1"), capability);
}

From source file:io.github.bonigarcia.wdm.test.PerformanceRemoteTest.java

License:Apache License

@Before
public void setupTest() throws InterruptedException {
    ExecutorService executor = newFixedThreadPool(NUMBER_OF_BROWSERS);
    CountDownLatch latch = new CountDownLatch(NUMBER_OF_BROWSERS);

    for (int i = 0; i < NUMBER_OF_BROWSERS; i++) {
        executor.execute(() -> {/*from   w  ww  .ja va 2 s.c  o  m*/
            try {
                driverList.add(new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), chrome()));
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } finally {
                latch.countDown();
            }
        });
    }

    latch.await();
    executor.shutdown();
}

From source file:io.github.bonigarcia.wdm.test.RemoteTest.java

License:Apache License

@Before
public void setupTest() throws MalformedURLException {
    DesiredCapabilities capability = DesiredCapabilities.chrome();
    driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
}

From source file:io.github.bonigarcia.wdm.test.RemoteWebRtcFirefoxTest.java

License:Apache License

@Before
public void setupTest() throws MalformedURLException {
    DesiredCapabilities capability = DesiredCapabilities.firefox();
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("media.navigator.permission.disabled", true);
    profile.setPreference("media.navigator.streams.fake", true);
    capability.setCapability(FirefoxDriver.PROFILE, profile);
    driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
}

From source file:io.github.bonigarcia.wdm.test.SaucelabsTest.java

License:Apache License

@Before
public void setupTest() throws MalformedURLException {
    DesiredCapabilities caps = DesiredCapabilities.chrome();
    caps.setCapability("platform", "Windows 10");
    caps.setCapability("version", "52.0");

    driver = new RemoteWebDriver(new URL(URL), caps);
}

From source file:io.github.bonigarcia.wdm.test.WebRtcRemoteChromeTest.java

License:Apache License

@Before
public void setup() throws MalformedURLException {
    DesiredCapabilities capabilities = chrome();
    ChromeOptions options = new ChromeOptions();
    options.addArguments("--use-fake-ui-for-media-stream");
    options.addArguments("--use-fake-device-for-media-stream");
    capabilities.setCapability(CAPABILITY, options);

    driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
}