Search in sources :

Example 1 with GeckoDriverService

use of org.openqa.selenium.firefox.GeckoDriverService in project acceptance-test-harness by jenkinsci.

the class FallbackConfig method createWebDriver.

private WebDriver createWebDriver(TestCleaner cleaner, TestName testName) throws IOException {
    String browser = getBrowser();
    String display = getBrowserDisplay();
    switch(browser) {
        case "firefox":
            setDriverPropertyIfMissing("geckodriver", GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY);
            GeckoDriverService.Builder builder = new GeckoDriverService.Builder();
            if (display != null) {
                builder.withEnvironment(Collections.singletonMap("DISPLAY", display));
            }
            GeckoDriverService service = builder.build();
            return new FirefoxDriver(service, buildFirefoxOptions(testName));
        case "firefox-container":
            return createContainerWebDriver(cleaner, "selenium/standalone-firefox-debug:3.141.59", buildFirefoxOptions(testName));
        case "chrome-container":
            return createContainerWebDriver(cleaner, "selenium/standalone-chrome-debug:3.141.59", new ChromeOptions());
        case "ie":
        case "iexplore":
        case "iexplorer":
            return new InternetExplorerDriver();
        case "chrome":
            Map<String, String> prefs = new HashMap<String, String>();
            prefs.put(LANGUAGE_SELECTOR, "en");
            ChromeOptions options = new ChromeOptions();
            options.setExperimentalOption("prefs", prefs);
            if (isCaptureHarEnabled()) {
                options.setAcceptInsecureCerts(true);
                options.setProxy(createSeleniumProxy(testName.get()));
            }
            setDriverPropertyIfMissing("chromedriver", ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY);
            return new ChromeDriver(options);
        case "safari":
            return new SafariDriver();
        case "htmlunit":
            return new HtmlUnitDriver(true);
        case "saucelabs":
        case "saucelabs-firefox":
            DesiredCapabilities caps = DesiredCapabilities.firefox();
            caps.setCapability("version", "29");
            caps.setCapability("platform", "Windows 7");
            caps.setCapability("name", testName.get());
            if (isCaptureHarEnabled()) {
                caps.setCapability(CapabilityType.PROXY, createSeleniumProxy(testName.get()));
            }
            // if running inside Jenkins, expose build ID
            String tag = System.getenv("BUILD_TAG");
            if (tag != null)
                caps.setCapability("build", tag);
            return new SauceLabsConnection().createWebDriver(caps);
        case "phantomjs":
            DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
            capabilities.setCapability(LANGUAGE_SELECTOR, "en");
            capabilities.setCapability(LANGUAGE_SELECTOR_PHANTOMJS, "en");
            return new PhantomJSDriver(capabilities);
        case "remote-webdriver-firefox":
            String u = System.getenv("REMOTE_WEBDRIVER_URL");
            if (StringUtils.isBlank(u)) {
                throw new Error("remote-webdriver-firefox requires REMOTE_WEBDRIVER_URL to be set");
            }
            return new RemoteWebDriver(// http://192.168.99.100:4444/wd/hub
            new URL(u), buildFirefoxOptions(testName));
        case "remote-webdriver-chrome":
            u = System.getenv("REMOTE_WEBDRIVER_URL");
            if (StringUtils.isBlank(u)) {
                throw new Error("remote-webdriver-chrome requires REMOTE_WEBDRIVER_URL to be set");
            }
            return new RemoteWebDriver(// http://192.168.99.100:4444/wd/hub
            new URL(u), DesiredCapabilities.chrome());
        default:
            throw new Error("Unrecognized browser type: " + browser);
    }
}
Also used : PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) HashMap(java.util.HashMap) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) CommandBuilder(org.jenkinsci.utils.process.CommandBuilder) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) URL(java.net.URL) SafariDriver(org.openqa.selenium.safari.SafariDriver) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) GeckoDriverService(org.openqa.selenium.firefox.GeckoDriverService) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) SauceLabsConnection(org.jenkinsci.test.acceptance.utils.SauceLabsConnection)

Aggregations

URL (java.net.URL)1 HashMap (java.util.HashMap)1 SauceLabsConnection (org.jenkinsci.test.acceptance.utils.SauceLabsConnection)1 CommandBuilder (org.jenkinsci.utils.process.CommandBuilder)1 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)1 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)1 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)1 GeckoDriverService (org.openqa.selenium.firefox.GeckoDriverService)1 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)1 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)1 PhantomJSDriver (org.openqa.selenium.phantomjs.PhantomJSDriver)1 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)1 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)1 SafariDriver (org.openqa.selenium.safari.SafariDriver)1