Search in sources :

Example 1 with SauceLabsConnection

use of org.jenkinsci.test.acceptance.utils.SauceLabsConnection 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)

Example 2 with SauceLabsConnection

use of org.jenkinsci.test.acceptance.utils.SauceLabsConnection in project acceptance-test-harness by jenkinsci.

the class FallbackConfig method createWebDriver.

private WebDriver createWebDriver(TestName testName) throws IOException {
    String browser = System.getenv("BROWSER");
    if (browser == null)
        browser = "firefox";
    browser = browser.toLowerCase(Locale.ENGLISH);
    String display = getBrowserDisplay();
    switch(browser) {
        case "firefox":
            FirefoxProfile profile = new FirefoxProfile();
            profile.setAlwaysLoadNoFocusLib(true);
            profile.setPreference(LANGUAGE_SELECTOR, "en");
            // Config screen with many plugins can cause FF to complain JS takes too long to complete - set longer timeout
            profile.setPreference(DOM_MAX_SCRIPT_RUN_TIME, (int) getElasticTime().seconds(600));
            profile.setPreference(DOM_MAX_CHROME_SCRIPT_RUN_TIME, (int) getElasticTime().seconds(600));
            FirefoxBinary binary = new FirefoxBinary();
            if (display != null) {
                binary.setEnvironmentProperty("DISPLAY", display);
            }
            return new FirefoxDriver(binary, profile);
        case "ie":
        case "iexplore":
        case "iexplorer":
            return new InternetExplorerDriver();
        case "chrome":
            ChromeOptions options = new ChromeOptions();
            options.setExperimentalOption("prefs", Collections.singletonMap(LANGUAGE_SELECTOR, "en"));
            ChromeDriverService.Builder builder = new ChromeDriverService.Builder();
            if (display != null) {
                builder.withEnvironment(Collections.singletonMap("DISPLAY", display));
            }
            return new ChromeDriver(builder.build(), 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 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), DesiredCapabilities.firefox());
        default:
            throw new Error("Unrecognized browser type: " + browser);
    }
}
Also used : PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) ChromeDriverService(org.openqa.selenium.chrome.ChromeDriverService) URL(java.net.URL) SafariDriver(org.openqa.selenium.safari.SafariDriver) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FirefoxBinary(org.openqa.selenium.firefox.FirefoxBinary) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) SauceLabsConnection(org.jenkinsci.test.acceptance.utils.SauceLabsConnection)

Aggregations

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