Package jp.vmi.selenium.webdriver

Source Code of jp.vmi.selenium.webdriver.RemoteWebDriverFactory

package jp.vmi.selenium.webdriver;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static jp.vmi.selenium.webdriver.DriverOptions.DriverOption.*;

/**
* Factory of {@link RemoteWebDriver}.
*/
public class RemoteWebDriverFactory extends WebDriverFactory {

    private static final Logger log = LoggerFactory.getLogger(RemoteWebDriverFactory.class);

    @Override
    public WebDriver newInstance(DriverOptions driverOptions) {
        DesiredCapabilities caps = DesiredCapabilities.htmlUnit();
        setupProxy(caps, driverOptions);
        caps.merge(driverOptions.getCapabilities());
        if (driverOptions.has(REMOTE_BROWSER)) {
            String browser = driverOptions.get(REMOTE_BROWSER);
            caps.setBrowserName(browser);
            log.info("Remote browser: {}", browser);
            if ("firefox".equalsIgnoreCase(browser))
                FirefoxDriverFactory.setDriverSpecificCapabilities(caps, driverOptions, true);
        }
        if (driverOptions.has(REMOTE_PLATFORM)) {
            String platform = driverOptions.get(REMOTE_PLATFORM);
            caps.setCapability(CapabilityType.PLATFORM, platform);
            log.info("Remote platform: {}", platform);
        }
        if (driverOptions.has(REMOTE_VERSION)) {
            String version = driverOptions.get(REMOTE_VERSION);
            caps.setCapability(CapabilityType.VERSION, version);
            log.info("Remote version: {}", version);
        }
        URL url;
        if (driverOptions.has(REMOTE_URL)) {
            try {
                url = new URL(driverOptions.get(REMOTE_URL));
            } catch (MalformedURLException e) {
                throw new IllegalArgumentException("Invalid --remote-url: " + e.getMessage());
            }
        } else {
            throw new IllegalArgumentException("Require --remote-url to know where to connect to");
        }
        log.info("Remote URL: {}", url);
        RemoteWebDriver driver = new RemoteWebDriver(url, caps);
        log.info("Session ID: " + driver.getSessionId());
        setInitialWindowSize(driver, driverOptions);
        return driver;
    }
}
TOP

Related Classes of jp.vmi.selenium.webdriver.RemoteWebDriverFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.