Search in sources :

Example 51 with ChromeDriver

use of org.openqa.selenium.chrome.ChromeDriver in project syndesis-qe by syndesisio.

the class CustomWebDriverProvider method prepareChromeWebDriver.

/**
 * Method will prepare chrome driver with custom profile
 * @return
 */
private ChromeDriver prepareChromeWebDriver() {
    log.info("setting chrome profile");
    System.setProperty("webdriver.chrome.driver", findDriverPath());
    Map<String, Object> preferences = new Hashtable<String, Object>();
    preferences.put("profile.default_content_settings.popups", 0);
    preferences.put("download.prompt_for_download", "false");
    preferences.put("download.default_directory", DOWNLOAD_DIR);
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("prefs", preferences);
    options.addArguments("start-maximized", "--no-sandbox");
    return new ChromeDriver(options);
}
Also used : Hashtable(java.util.Hashtable) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Example 52 with ChromeDriver

use of org.openqa.selenium.chrome.ChromeDriver in project nutch by apache.

the class HttpWebClient method getDriverForPage.

public static WebDriver getDriverForPage(String url, Configuration conf) {
    WebDriver driver = null;
    DesiredCapabilities capabilities = null;
    long pageLoadWait = conf.getLong("page.load.delay", 3);
    try {
        String driverType = conf.get("selenium.driver", "firefox");
        switch(driverType) {
            case "firefox":
                String allowedHost = conf.get("selenium.firefox.allowed.hosts", "localhost");
                long firefoxBinaryTimeout = conf.getLong("selenium.firefox.binary.timeout", 45);
                boolean enableFlashPlayer = conf.getBoolean("selenium.firefox.enable.flash", false);
                int loadImage = conf.getInt("selenium.firefox.load.image", 1);
                int loadStylesheet = conf.getInt("selenium.firefox.load.stylesheet", 1);
                FirefoxProfile profile = new FirefoxProfile();
                FirefoxBinary binary = new FirefoxBinary();
                profile.setPreference(FirefoxProfile.ALLOWED_HOSTS_PREFERENCE, allowedHost);
                profile.setPreference("dom.ipc.plugins.enabled.libflashplayer.so", enableFlashPlayer);
                profile.setPreference("permissions.default.stylesheet", loadStylesheet);
                profile.setPreference("permissions.default.image", loadImage);
                binary.setTimeout(TimeUnit.SECONDS.toMillis(firefoxBinaryTimeout));
                driver = new FirefoxDriver(binary, profile);
                break;
            case "chrome":
                driver = new ChromeDriver();
                break;
            case "safari":
                driver = new SafariDriver();
                break;
            case "opera":
                driver = new OperaDriver();
                break;
            case "phantomjs":
                driver = new PhantomJSDriver();
                break;
            case "remote":
                String seleniumHubHost = conf.get("selenium.hub.host", "localhost");
                int seleniumHubPort = Integer.parseInt(conf.get("selenium.hub.port", "4444"));
                String seleniumHubPath = conf.get("selenium.hub.path", "/wd/hub");
                String seleniumHubProtocol = conf.get("selenium.hub.protocol", "http");
                String seleniumGridDriver = conf.get("selenium.grid.driver", "firefox");
                String seleniumGridBinary = conf.get("selenium.grid.binary");
                switch(seleniumGridDriver) {
                    case "firefox":
                        capabilities = DesiredCapabilities.firefox();
                        capabilities.setBrowserName("firefox");
                        capabilities.setJavascriptEnabled(true);
                        capabilities.setCapability("firefox_binary", seleniumGridBinary);
                        System.setProperty("webdriver.reap_profile", "false");
                        driver = new RemoteWebDriver(new URL(seleniumHubProtocol, seleniumHubHost, seleniumHubPort, seleniumHubPath), capabilities);
                        break;
                    case "phantomjs":
                        capabilities = DesiredCapabilities.phantomjs();
                        capabilities.setBrowserName("phantomjs");
                        capabilities.setJavascriptEnabled(true);
                        capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, seleniumGridBinary);
                        driver = new RemoteWebDriver(new URL(seleniumHubProtocol, seleniumHubHost, seleniumHubPort, seleniumHubPath), capabilities);
                        break;
                    default:
                        LOG.error("The Selenium Grid WebDriver choice {} is not available... defaulting to FirefoxDriver().", driverType);
                        driver = new RemoteWebDriver(new URL(seleniumHubProtocol, seleniumHubHost, seleniumHubPort, seleniumHubPath), DesiredCapabilities.firefox());
                        break;
                }
                break;
            default:
                LOG.error("The Selenium WebDriver choice {} is not available... defaulting to FirefoxDriver().", driverType);
                driver = new FirefoxDriver();
                break;
        }
        LOG.debug("Selenium {} WebDriver selected.", driverType);
        driver.manage().timeouts().pageLoadTimeout(pageLoadWait, TimeUnit.SECONDS);
        driver.get(url);
    } catch (Exception e) {
        if (e instanceof TimeoutException) {
            LOG.debug("Selenium WebDriver: Timeout Exception: Capturing whatever loaded so far...");
            return driver;
        }
        cleanUpDriver(driver);
        throw new RuntimeException(e);
    }
    return driver;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) OperaDriver(com.opera.core.systems.OperaDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) URL(java.net.URL) TimeoutException(org.openqa.selenium.TimeoutException) SafariDriver(org.openqa.selenium.safari.SafariDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FirefoxBinary(org.openqa.selenium.firefox.FirefoxBinary) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) TimeoutException(org.openqa.selenium.TimeoutException)

Example 53 with ChromeDriver

use of org.openqa.selenium.chrome.ChromeDriver in project BuildRadiator by BuildRadiator.

the class RadiatorWebDriverTest method sharedForAllTests.

@BeforeClass
public static void sharedForAllTests() {
    // Keep the WebDriver browser window open between tests
    DRIVER = new ChromeDriver();
    FWD = new FluentWebDriver(DRIVER);
}
Also used : FluentWebDriver(org.seleniumhq.selenium.fluent.FluentWebDriver) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Example 54 with ChromeDriver

use of org.openqa.selenium.chrome.ChromeDriver in project jmeter-plugins by undera.

the class ChromeDriverConfigTest method shouldQuitWebDriverAndStopServiceWhenQuitBrowserIsInvoked.

@Test
public void shouldQuitWebDriverAndStopServiceWhenQuitBrowserIsInvoked() throws Exception {
    ChromeDriver mockChromeDriver = mock(ChromeDriver.class);
    ChromeDriverService mockService = mock(ChromeDriverService.class);
    when(mockService.isRunning()).thenReturn(true);
    config.getServices().put(config.currentThreadName(), mockService);
    config.quitBrowser(mockChromeDriver);
    verify(mockChromeDriver).quit();
    assertThat(config.getServices(), is(Collections.<String, ChromeDriverService>emptyMap()));
    verify(mockService, times(1)).stop();
}
Also used : ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) ChromeDriverService(org.openqa.selenium.chrome.ChromeDriverService) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 55 with ChromeDriver

use of org.openqa.selenium.chrome.ChromeDriver in project jmeter-plugins by undera.

the class ChromeDriverConfigTest method shouldCreateChromeAndStartService.

@Test
public void shouldCreateChromeAndStartService() throws Exception {
    ChromeDriver mockChromeDriver = mock(ChromeDriver.class);
    whenNew(ChromeDriver.class).withParameterTypes(ChromeDriverService.class, Capabilities.class).withArguments(isA(ChromeDriverService.class), isA(Capabilities.class)).thenReturn(mockChromeDriver);
    ChromeDriverService.Builder mockServiceBuilder = mock(ChromeDriverService.Builder.class);
    whenNew(ChromeDriverService.Builder.class).withNoArguments().thenReturn(mockServiceBuilder);
    when(mockServiceBuilder.usingDriverExecutable(isA(File.class))).thenReturn(mockServiceBuilder);
    ChromeDriverService mockService = mock(ChromeDriverService.class);
    when(mockServiceBuilder.build()).thenReturn(mockService);
    final ChromeDriver browser = config.createBrowser();
    assertThat(browser, is(mockChromeDriver));
    verifyNew(ChromeDriver.class, times(1)).withArguments(isA(ChromeDriverService.class), isA(Capabilities.class));
    verify(mockServiceBuilder, times(1)).build();
    assertThat(config.getServices().size(), is(1));
    assertThat(config.getServices().values(), hasItem(mockService));
}
Also used : Capabilities(org.openqa.selenium.Capabilities) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) ChromeDriverService(org.openqa.selenium.chrome.ChromeDriverService) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)91 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)41 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)39 File (java.io.File)33 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)27 WebDriver (org.openqa.selenium.WebDriver)24 HashMap (java.util.HashMap)21 Before (org.junit.Before)13 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)13 URL (java.net.URL)11 FirefoxProfile (org.openqa.selenium.firefox.FirefoxProfile)11 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)11 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)11 Test (org.junit.Test)10 ChromeDriverService (org.openqa.selenium.chrome.ChromeDriverService)9 Actions (org.openqa.selenium.interactions.Actions)9 PhantomJSDriver (org.openqa.selenium.phantomjs.PhantomJSDriver)9 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)8 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)7 SafariDriver (org.openqa.selenium.safari.SafariDriver)7