Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/remote webdriver #370

Merged
merged 4 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ public enum Properties implements IProperties {
BASEURL("tt.baseurl", null),
WEBDRIVER_TIMEOUT_SECONDS_PAGELOAD("webdriver.timeouts.seconds.pageload", 120),
WEBDRIVER_TIMEOUT_SECONDS_SCRIPT("webdriver.timeouts.seconds.script", 120),
WEBDRIVER_TIMEOUT_SECONDS_RETRY("webdriver.timeouts.seconds.retry", 10),
SELENIUM_WEBDRIVER_CREATE_RETRY("tt.selenium.webdriver.create.retry", 10),
SELENIUM_REMOTE_TIMEOUT_READ("tt.selenium.remote.timeout.read", 90),
SELENIUM_REMOTE_TIMEOUT_CONNECTION("tt.selenium.remote.timeout.connection", 10),
PERF_TEST("tt.perf.test", false),
PERF_GENERATE_STATISTICS("tt.perf.generate.statistics", false),
/**
Expand Down
3 changes: 3 additions & 0 deletions docs/src/docs/properties/property-attributes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
:wdm_timeouts_window_switch: tt.wdm.timeouts.seconds.window.switch.duration
:webdriver_timeouts_seconds_pageload: webdriver.timeouts.seconds.pageload
:webdriver_timeouts_seconds_script: webdriver.timeouts.seconds.script
:selenium_webdriver_create_retry: tt.selenium.webdriver.create.retry
:selenium_remote_timeout_read: tt.selenium.remote.timeout.read
:selenium_remote_timeout_connection: tt.selenium.remote.timeout.connection

// pagefactory
:page_factory_loops: tt.page.factory.loops
Expand Down
3 changes: 3 additions & 0 deletions docs/src/docs/properties/webdriver-props.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,8 @@ This setting overrides the following two properties.
(`driver.manage().timeouts().pageLoadTimeout()`)
| {webdriver_timeouts_seconds_script} | 120 | Defines the Selenium timeout for execution of async scripts in seconds. +
(`driver.manage().timeouts().setScriptTimeout()`)
| {selenium_webdriver_create_retry} | 10 | Waiting time in seconds for a retry of creating a webdriver session in case the first attempt fails.
| {selenium_remote_timeout_connection} | 10 | Defines the read timeout in seconds for a remote webdriver session.
| {selenium_remote_timeout_read} | 90 | Defines the connection timeout in seconds for a remote webdriver session.
|===

Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerOptions;
import org.openqa.selenium.remote.AbstractDriverOptions;
import org.openqa.selenium.remote.CommandExecutor;
import org.openqa.selenium.remote.HttpCommandExecutor;
import org.openqa.selenium.remote.LocalFileDetector;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.http.ClientConfig;
import org.openqa.selenium.safari.SafariDriver;
import org.openqa.selenium.safari.SafariOptions;
import org.openqa.selenium.support.events.EventFiringWebDriver;
Expand Down Expand Up @@ -266,7 +269,7 @@ private WebDriver newWebDriver(DesktopWebDriverRequest desktopWebDriverRequest,
try {
newDriver = startNewWebDriverSession(desktopWebDriverRequest, sessionContext);
} catch (final SetupException e) {
int ms = Testerra.Properties.WEBDRIVER_TIMEOUT_SECONDS_RETRY.asLong().intValue() * 1000;
int ms = Testerra.Properties.SELENIUM_WEBDRIVER_CREATE_RETRY.asLong().intValue() * 1000;
log().error(String.format("Error starting WebDriver. Trying again in %d seconds", (ms / 1000)), e);
TimerUtils.sleep(ms);
newDriver = startNewWebDriverSession(desktopWebDriverRequest, sessionContext);
Expand Down Expand Up @@ -315,18 +318,24 @@ private WebDriver startNewWebDriverSession(DesktopWebDriverRequest request, Sess
try {
if (request.getServerUrl().isPresent()) {
final URL seleniumUrl = request.getServerUrl().get();
// The old HttpClientFactory reduced timeouts of Selenium 3 because of very long timeouts
// Selenium 4 uses JDK 11 HttpClient: connectionTimeout=10sec, readTimeout=180 sec, seems to be ok
// see {@link org.openqa.selenium.remote.http.ClientConfig#defaultConfig()}
// final HttpCommandExecutor httpCommandExecutor = new HttpCommandExecutor(new HashMap<>(), seleniumUrl, new HttpClientFactory());

Capabilities capabilities = request.getCapabilities();
if (capabilities == null) {
throw new SystemException("Cannot start browser session with empty browser options");
}
webDriver = RemoteWebDriver.builder()
.address(seleniumUrl)
.addAlternative(capabilities)
.build();
// Selenium default timeouts are
// read timeout: 180 sec
// connection timeout: 10 sec
// see {@link org.openqa.selenium.remote.http.ClientConfig#defaultConfig()}
// Testerra: read timeout reduced to 90 sec
ClientConfig clientConfig = ClientConfig
.defaultConfig()
.readTimeout(Duration.ofSeconds(Testerra.Properties.SELENIUM_REMOTE_TIMEOUT_READ.asLong()))
.connectionTimeout(Duration.ofSeconds(Testerra.Properties.SELENIUM_REMOTE_TIMEOUT_CONNECTION.asLong()))
.baseUrl(seleniumUrl);
CommandExecutor commandExecutor = new HttpCommandExecutor(clientConfig);
webDriver = new RemoteWebDriver(commandExecutor, capabilities);

((RemoteWebDriver) webDriver).setFileDetector(new LocalFileDetector());
sessionContext.setNodeUrl(seleniumUrl);
} else {
Expand Down

This file was deleted.