Search in sources :

Example 1 with Timeouts

use of org.openqa.selenium.WebDriver.Timeouts in project vividus by vividus-framework.

the class WebDriverFactoryTests method testGetRemoteWebDriverFirefoxDriver.

@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("{%n  \"acceptInsecureCerts\" : true,%n" + "  \"browserName\" : \"firefox\",%n" + "  \"moz:debuggerAddress\" : true,%n" + "  \"moz:firefoxOptions\" : {%n" + "    \"prefs\" : {%n" + "      \"startup.homepage_welcome_url.additional\" : \"about:blank\"%n" + "    }%n  }%n}");
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) TestLogger(com.github.valfirst.slf4jtest.TestLogger) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) URL(java.net.URL) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Timeouts(org.openqa.selenium.WebDriver.Timeouts) Map(java.util.Map) URI(java.net.URI) LoggingEvent.info(com.github.valfirst.slf4jtest.LoggingEvent.info) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Capabilities(org.openqa.selenium.Capabilities) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Browser(org.openqa.selenium.remote.Browser) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) Mockito.mock(org.mockito.Mockito.mock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) CsvSource(org.junit.jupiter.params.provider.CsvSource) WrapsDriver(org.openqa.selenium.WrapsDriver) Mock(org.mockito.Mock) WebDriver(org.openqa.selenium.WebDriver) JsonUtils(org.vividus.util.json.JsonUtils) Mockito.lenient(org.mockito.Mockito.lenient) TextFormattingWebDriver(org.vividus.selenium.driver.TextFormattingWebDriver) CapabilityType(org.openqa.selenium.remote.CapabilityType) HasCapabilities(org.openqa.selenium.HasCapabilities) IProxy(org.vividus.proxy.IProxy) FieldUtils(org.apache.commons.lang3.reflect.FieldUtils) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Options(org.openqa.selenium.WebDriver.Options) IPropertyParser(org.vividus.util.property.IPropertyParser) MalformedURLException(java.net.MalformedURLException) Mockito.when(org.mockito.Mockito.when) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) TestLoggerFactoryExtension(com.github.valfirst.slf4jtest.TestLoggerFactoryExtension) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Assertions(org.junit.jupiter.api.Assertions) TestLoggerFactory(com.github.valfirst.slf4jtest.TestLoggerFactory) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) Timeouts(org.openqa.selenium.WebDriver.Timeouts) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with Timeouts

use of org.openqa.selenium.WebDriver.Timeouts in project vividus by vividus-framework.

the class WebDriverFactoryTests method testGetRemoteWebDriverIEDriver.

@Test
void testGetRemoteWebDriverIEDriver() throws MalformedURLException {
    mockCapabilities(remoteWebDriver);
    setRemoteDriverUrl();
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
    desiredCapabilities.setBrowserName(Browser.IE.browserName());
    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();
}
Also used : Timeouts(org.openqa.selenium.WebDriver.Timeouts) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) URL(java.net.URL) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with Timeouts

use of org.openqa.selenium.WebDriver.Timeouts in project vividus by vividus-framework.

the class TimeoutConfigurerTests method testSetPageLoadTimeout.

@Test
void testSetPageLoadTimeout() {
    Timeouts timeouts = mock(Timeouts.class);
    timeoutConfigurer.configurePageLoadTimeout(DURATION_PAGE_LOAD_TIMEOUT, timeouts);
    verify(timeouts).pageLoadTimeout(DURATION_PAGE_LOAD_TIMEOUT.getSeconds(), TimeUnit.SECONDS);
}
Also used : Timeouts(org.openqa.selenium.WebDriver.Timeouts) Test(org.junit.jupiter.api.Test)

Example 4 with Timeouts

use of org.openqa.selenium.WebDriver.Timeouts in project vividus by vividus-framework.

the class TimeoutConfigurerTests method testSetTimeoutsWithExceptionAtPageLoadTimeoutSetting.

@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);
}
Also used : UnsupportedCommandException(org.openqa.selenium.UnsupportedCommandException) Timeouts(org.openqa.selenium.WebDriver.Timeouts) Test(org.junit.jupiter.api.Test)

Example 5 with Timeouts

use of org.openqa.selenium.WebDriver.Timeouts in project vividus by vividus-framework.

the class WebDriverFactoryTests method mockTimeouts.

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;
}
Also used : ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) Options(org.openqa.selenium.WebDriver.Options) Timeouts(org.openqa.selenium.WebDriver.Timeouts)

Aggregations

Timeouts (org.openqa.selenium.WebDriver.Timeouts)20 Test (org.junit.jupiter.api.Test)14 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 Options (org.openqa.selenium.WebDriver.Options)9 URL (java.net.URL)6 Arrays (java.util.Arrays)6 List (java.util.List)6 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)6 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)6 Mock (org.mockito.Mock)6 Mockito.never (org.mockito.Mockito.never)6 Mockito.verify (org.mockito.Mockito.verify)6 Mockito.when (org.mockito.Mockito.when)6 LoggingEvent.info (com.github.valfirst.slf4jtest.LoggingEvent.info)5 TestLogger (com.github.valfirst.slf4jtest.TestLogger)5 TestLoggerFactory (com.github.valfirst.slf4jtest.TestLoggerFactory)5 TestLoggerFactoryExtension (com.github.valfirst.slf4jtest.TestLoggerFactoryExtension)5 MalformedURLException (java.net.MalformedURLException)5 URI (java.net.URI)5