org.openqa.selenium.WebDriver.Timeouts Java Examples

The following examples show how to use org.openqa.selenium.WebDriver.Timeouts. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebDriverFactoryTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
@Test
void testGetWebDriverWithWebDriverTypeAndBinaryPathConfiguration()
{
    mockCapabilities((HasCapabilities) driver);
    WebDriverType webDriverType = mock(WebDriverType.class);
    when(webDriverType.isBinaryPathSupported()).thenReturn(Boolean.TRUE);
    webDriverFactory.setWebDriverType(webDriverType);
    lenient().when(propertyParser.getPropertyValue("web.driver." + webDriverType + ".driver-executable-path"))
            .thenReturn(PATH);
    lenient().when(propertyParser.getPropertyValue(String.format(BINARY_PATH_PROPERTY_FORMAT, webDriverType)))
            .thenReturn(PATH);
    DesiredCapabilities desiredCapabilities = mock(DesiredCapabilities.class);
    when(webDriverType.getWebDriver(eq(new DesiredCapabilities()),
            argThat(config -> Optional.of(PATH).equals(config.getBinaryPath())
                    && Optional.of(PATH).equals(config.getDriverExecutablePath())))).thenReturn(driver);
    Timeouts timeouts = mockTimeouts(driver);
    assertEquals(driver,
            ((WrapsDriver) webDriverFactory.getWebDriver(desiredCapabilities)).getWrappedDriver());
    verify(timeoutConfigurer).configure(timeouts);
    assertLogger();
}
 
Example #2
Source File: WebDriverFactoryTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
@Test
void testGetWebDriverWithWebDriverTypeAndCommandLineArgumentsConfiguration()
{
    mockCapabilities((HasCapabilities) driver);
    WebDriverType webDriverType = mock(WebDriverType.class);
    when(webDriverType.isCommandLineArgumentsSupported()).thenReturn(Boolean.TRUE);
    webDriverFactory.setWebDriverType(webDriverType);
    lenient().when(propertyParser.getPropertyValue(String.format(BINARY_PATH_PROPERTY_FORMAT, webDriverType)))
            .thenReturn(null);
    lenient().when(
            propertyParser.getPropertyValue(String.format(COMMAND_LINE_ARGUMENTS_PROPERTY_FORMAT, webDriverType)))
            .thenReturn(ARGS);
    DesiredCapabilities desiredCapabilities = mock(DesiredCapabilities.class);
    when(webDriverType.getWebDriver(eq(new DesiredCapabilities()),
            argThat(config -> Arrays.equals(new String[] { ARG_1, ARG_2 }, config.getCommandLineArguments()))))
            .thenReturn(driver);
    Timeouts timeouts = mockTimeouts(driver);
    assertEquals(driver,
            ((WrapsDriver) webDriverFactory.getWebDriver(desiredCapabilities)).getWrappedDriver());
    verify(timeoutConfigurer).configure(timeouts);
    assertLogger();
}
 
Example #3
Source File: WebDriverFactoryTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
@Test
void testGetWebDriverWithWebDriverTypeAndExperimentalOptionsConfiguration()
{
    mockCapabilities((HasCapabilities) driver);
    WebDriverType webDriverType = mock(WebDriverType.class);
    webDriverFactory.setWebDriverType(webDriverType);
    lenient().when(propertyParser.getPropertyValue(String.format(BINARY_PATH_PROPERTY_FORMAT, webDriverType)))
            .thenReturn(null);
    lenient().when(
            propertyParser.getPropertyValue(String.format(EXPERIMENTAL_OPTIONS_PROPERTY_FORMAT, webDriverType)))
            .thenReturn("{\"mobileEmulation\": {\"deviceName\": \"iPhone 8\"}}");
    DesiredCapabilities desiredCapabilities = mock(DesiredCapabilities.class);
    when(webDriverType.getWebDriver(eq(new DesiredCapabilities()),
            argThat(config ->  Map.of("mobileEmulation", Map.of("deviceName", "iPhone 8"))
                    .equals(config.getExperimentalOptions())))).thenReturn(driver);
    Timeouts timeouts = mockTimeouts(driver);
    assertEquals(driver,
            ((WrapsDriver) webDriverFactory.getWebDriver(desiredCapabilities)).getWrappedDriver());
    verify(timeoutConfigurer).configure(timeouts);
    assertLogger();
}
 
Example #4
Source File: WebDriverFactoryTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
void testGetRemoteWebDriverFirefoxDriver() throws MalformedURLException
{
    mockCapabilities(remoteWebDriver);
    setRemoteDriverUrl();
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities(new FirefoxOptions());
    when(remoteWebDriverFactory.getRemoteWebDriver(eq(URL.toURL()), argThat(caps ->
    {
        Map<String, Object> options = (Map<String, Object>) caps.getCapability(FirefoxOptions.FIREFOX_OPTIONS);
        Map<String, Object> prefs = (Map<String, Object>) options.get("prefs");
        return "about:blank".equals(prefs.get("startup.homepage_welcome_url.additional"))
                && "firefox".equals(caps.getBrowserName());
    }))).thenReturn(remoteWebDriver);
    Timeouts timeouts = mockTimeouts(remoteWebDriver);
    assertEquals(remoteWebDriver,
            ((WrapsDriver) webDriverFactory.getRemoteWebDriver(desiredCapabilities)).getWrappedDriver());
    verify(timeoutConfigurer).configure(timeouts);
    assertLogger();
}
 
Example #5
Source File: WebDriverFactoryTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
@Test
void testGetRemoteWebDriverIEDriver() throws Exception
{
    mockCapabilities(remoteWebDriver);
    setRemoteDriverUrl();
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
    desiredCapabilities.setBrowserName(BrowserType.IEXPLORE);
    when(remoteWebDriverFactory.getRemoteWebDriver(any(URL.class), any(DesiredCapabilities.class)))
            .thenReturn(remoteWebDriver);
    Timeouts timeouts = mockTimeouts(remoteWebDriver);
    desiredCapabilities.setCapability(InternetExplorerDriver.NATIVE_EVENTS, false);
    assertEquals(remoteWebDriver,
            ((WrapsDriver) webDriverFactory.getRemoteWebDriver(desiredCapabilities)).getWrappedDriver());
    verify(timeoutConfigurer).configure(timeouts);
    assertLogger();
}
 
Example #6
Source File: DriverManager.java    From Selenium-Foundation with Apache License 2.0 5 votes vote down vote up
/**
 * Set configured timeout intervals in the specified driver.
 * 
 * @param driver driver object in which to configure timeout intervals
 * @param config configuration object that specifies timeout intervals
 */
public static void setDriverTimeouts(final WebDriver driver, final SeleniumConfig config) {
    Timeouts timeouts = driver.manage().timeouts();
    timeouts.setScriptTimeout(WaitType.SCRIPT.getInterval(config), TimeUnit.SECONDS);
    timeouts.implicitlyWait(WaitType.IMPLIED.getInterval(config), TimeUnit.SECONDS);
    timeouts.pageLoadTimeout(WaitType.PAGE_LOAD.getInterval(config), TimeUnit.SECONDS);
}
 
Example #7
Source File: TimeoutConfigurer.java    From vividus with Apache License 2.0 5 votes vote down vote up
private static void setTimeout(Timeouts timeouts, Consumer<Timeouts> consumer)
{
    try
    {
        consumer.accept(timeouts);
    }
    catch (WebDriverException e)
    {
        LOGGER.warn(e.getMessage());
    }
}
 
Example #8
Source File: WebDriverFactoryTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Test
void testGetWebDriverWithWebDriverTypeWOBinary() throws Exception
{
    mockCapabilities((HasCapabilities) driver);
    WebDriverConfiguration configuration = new WebDriverConfiguration();
    WebDriverType webDriverType = mock(WebDriverType.class);
    webDriverFactory.setWebDriverType(webDriverType);
    injectConfigurations(webDriverType, configuration);
    DesiredCapabilities desiredCapabilities = mock(DesiredCapabilities.class);
    when(webDriverType.getWebDriver(new DesiredCapabilities(), configuration)).thenReturn(driver);
    Timeouts timeouts = mockTimeouts(driver);
    assertEquals(driver, ((WrapsDriver) webDriverFactory.getWebDriver(desiredCapabilities)).getWrappedDriver());
    verify(timeoutConfigurer).configure(timeouts);
    assertLogger();
}
 
Example #9
Source File: WebDriverFactoryTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Test
void testGetRemoteWebDriver() throws Exception
{
    mockCapabilities(remoteWebDriver);
    setRemoteDriverUrl();
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
    when(remoteWebDriverFactory.getRemoteWebDriver(URL.toURL(), desiredCapabilities)).thenReturn(remoteWebDriver);
    Timeouts timeouts = mockTimeouts(remoteWebDriver);
    assertEquals(remoteWebDriver,
            ((WrapsDriver) webDriverFactory.getRemoteWebDriver(desiredCapabilities)).getWrappedDriver());
    verify(timeoutConfigurer).configure(timeouts);
    assertLogger();
}
 
Example #10
Source File: WebDriverFactoryTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Test
void testGetRemoteWebDriverMarionetteDriver() throws Exception
{
    mockCapabilities(remoteWebDriver);
    setRemoteDriverUrl();
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
    desiredCapabilities.setBrowserName("marionette");
    when(remoteWebDriverFactory.getRemoteWebDriver(URL.toURL(), desiredCapabilities))
            .thenReturn(remoteWebDriver);
    Timeouts timeouts = mockTimeouts(remoteWebDriver);
    assertEquals(remoteWebDriver,
        ((WrapsDriver) webDriverFactory.getRemoteWebDriver(desiredCapabilities)).getWrappedDriver());
    verify(timeoutConfigurer).configure(timeouts);
    assertLogger();
}
 
Example #11
Source File: WebDriverFactoryTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
private void testGetRemoteWebDriverIsChrome(ChromeOptions chromeOptions) throws Exception
{
    mockCapabilities(remoteWebDriver);
    setRemoteDriverUrl();
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
    desiredCapabilities.setBrowserName(BrowserType.CHROME);
    desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
    when(remoteWebDriverFactory.getRemoteWebDriver(URL.toURL(), desiredCapabilities)).thenReturn(remoteWebDriver);
    Timeouts timeouts = mockTimeouts(remoteWebDriver);
    assertEquals(remoteWebDriver,
            ((WrapsDriver) webDriverFactory.getRemoteWebDriver(desiredCapabilities)).getWrappedDriver());
    verify(timeoutConfigurer).configure(timeouts);
    assertLogger();
}
 
Example #12
Source File: WebDriverFactoryTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
private static Timeouts mockTimeouts(WebDriver webDriver)
{
    Options options = mock(Options.class);
    when(webDriver.manage()).thenReturn(options);
    Timeouts timeouts = mock(Timeouts.class);
    when(options.timeouts()).thenReturn(timeouts);
    return timeouts;
}
 
Example #13
Source File: TimeoutConfigurerTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Test
void testSetTimeouts()
{
    Timeouts timeouts = mock(Timeouts.class);
    timeoutConfigurer.configure(timeouts);
    verify(timeouts).pageLoadTimeout(PAGE_LOAD_TIMEOUT, PAGE_LOAD_TIMEOUT_TIMEUNIT);
    verify(timeouts).setScriptTimeout(ASYNC_SCRIPT_TIMEOUT, ASYNC_SCRIPT_TIMEOUT_TIMEUNIT);
}
 
Example #14
Source File: TimeoutConfigurerTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Test
void testSetTimeoutsWithExceptionAtPageLoadTimeoutSetting()
{
    Timeouts timeouts = mock(Timeouts.class);
    UnsupportedCommandException exception = new UnsupportedCommandException("pagetimeout");
    when(timeouts.pageLoadTimeout(PAGE_LOAD_TIMEOUT, PAGE_LOAD_TIMEOUT_TIMEUNIT)).thenThrow(exception);
    timeoutConfigurer.configure(timeouts);
    verify(timeouts).setScriptTimeout(ASYNC_SCRIPT_TIMEOUT, ASYNC_SCRIPT_TIMEOUT_TIMEUNIT);
}
 
Example #15
Source File: TimeoutConfigurerTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Test
void testSetTimeoutsWithExceptionAtScriptTimeoutSetting()
{
    Timeouts timeouts = mock(Timeouts.class);
    UnsupportedCommandException exception = new UnsupportedCommandException("asynctimeout");
    when(timeouts.setScriptTimeout(ASYNC_SCRIPT_TIMEOUT, ASYNC_SCRIPT_TIMEOUT_TIMEUNIT)).thenThrow(exception);
    timeoutConfigurer.configure(timeouts);
    verify(timeouts).pageLoadTimeout(PAGE_LOAD_TIMEOUT, PAGE_LOAD_TIMEOUT_TIMEUNIT);
}
 
Example #16
Source File: RemoteDriverProtocol.java    From storm-crawler with Apache License 2.0 4 votes vote down vote up
@Override
public void configure(Config conf) {
    super.configure(conf);

    // see https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setJavascriptEnabled(true);

    String userAgentString = getAgentString(conf);

    // custom capabilities
    Map<String, Object> confCapabilities = (Map<String, Object>) conf
            .get("selenium.capabilities");
    if (confCapabilities != null) {
        Iterator<Entry<String, Object>> iter = confCapabilities.entrySet()
                .iterator();
        while (iter.hasNext()) {
            Entry<String, Object> entry = iter.next();
            Object val = entry.getValue();
            // substitute variable $useragent for the real value
            if (val instanceof String
                    && "$useragent".equalsIgnoreCase(val.toString())) {
                val = userAgentString;
            }
            capabilities.setCapability(entry.getKey(), val);
        }
    }

    // number of instances to create per connection
    // https://github.com/DigitalPebble/storm-crawler/issues/505
    int numInst = ConfUtils.getInt(conf, "selenium.instances.num", 1);

    // load adresses from config
    List<String> addresses = ConfUtils.loadListFromConf(
            "selenium.addresses", conf);
    if (addresses.size() == 0) {
        throw new RuntimeException("No value found for selenium.addresses");
    }
    try {
        for (String cdaddress : addresses) {
            for (int inst = 0; inst < numInst; inst++) {
                RemoteWebDriver driver = new RemoteWebDriver(new URL(
                        cdaddress), capabilities);
                Timeouts touts = driver.manage().timeouts();
                int implicitWait = ConfUtils.getInt(conf,
                        "selenium.implicitlyWait", 0);
                int pageLoadTimeout = ConfUtils.getInt(conf,
                        "selenium.pageLoadTimeout", -1);
                int setScriptTimeout = ConfUtils.getInt(conf,
                        "selenium.setScriptTimeout", 0);
                touts.implicitlyWait(implicitWait, TimeUnit.MILLISECONDS);
                touts.pageLoadTimeout(pageLoadTimeout,
                        TimeUnit.MILLISECONDS);
                touts.setScriptTimeout(setScriptTimeout,
                        TimeUnit.MILLISECONDS);
                drivers.add(driver);
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #17
Source File: AbstractDriver.java    From coteafs-selenium with Apache License 2.0 4 votes vote down vote up
private void manageTimeouts(final Consumer<Timeouts> timeouts) {
    timeouts.accept(getDriver().manage()
        .timeouts());
}
 
Example #18
Source File: TimeoutConfigurer.java    From vividus with Apache License 2.0 4 votes vote down vote up
@Override
public void configure(Timeouts timeouts)
{
    setTimeout(timeouts, t -> t.pageLoadTimeout(pageLoadTimeout, pageLoadTimeoutTimeUnit));
    setTimeout(timeouts, t -> t.setScriptTimeout(asyncScriptTimeout, asyncScriptTimeoutTimeUnit));
}
 
Example #19
Source File: ITimeoutConfigurer.java    From vividus with Apache License 2.0 votes vote down vote up
void configure(Timeouts timeouts);