Skip to content

Commit 0d82249

Browse files
Merge pull request #370 from telekom/fix/remote-webdriver
Fix/remote webdriver
2 parents cca6bc7 + 47c694b commit 0d82249

File tree

5 files changed

+27
-133
lines changed

5 files changed

+27
-133
lines changed

core/src/main/java/eu/tsystems/mms/tic/testframework/common/Testerra.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ public enum Properties implements IProperties {
7676
BASEURL("tt.baseurl", null),
7777
WEBDRIVER_TIMEOUT_SECONDS_PAGELOAD("webdriver.timeouts.seconds.pageload", 120),
7878
WEBDRIVER_TIMEOUT_SECONDS_SCRIPT("webdriver.timeouts.seconds.script", 120),
79-
WEBDRIVER_TIMEOUT_SECONDS_RETRY("webdriver.timeouts.seconds.retry", 10),
79+
SELENIUM_WEBDRIVER_CREATE_RETRY("tt.selenium.webdriver.create.retry", 10),
80+
SELENIUM_REMOTE_TIMEOUT_READ("tt.selenium.remote.timeout.read", 90),
81+
SELENIUM_REMOTE_TIMEOUT_CONNECTION("tt.selenium.remote.timeout.connection", 10),
8082
PERF_TEST("tt.perf.test", false),
8183
PERF_GENERATE_STATISTICS("tt.perf.generate.statistics", false),
8284
/**

docs/src/docs/properties/property-attributes.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
:wdm_timeouts_window_switch: tt.wdm.timeouts.seconds.window.switch.duration
2424
:webdriver_timeouts_seconds_pageload: webdriver.timeouts.seconds.pageload
2525
:webdriver_timeouts_seconds_script: webdriver.timeouts.seconds.script
26+
:selenium_webdriver_create_retry: tt.selenium.webdriver.create.retry
27+
:selenium_remote_timeout_read: tt.selenium.remote.timeout.read
28+
:selenium_remote_timeout_connection: tt.selenium.remote.timeout.connection
2629

2730
// pagefactory
2831
:page_factory_loops: tt.page.factory.loops

docs/src/docs/properties/webdriver-props.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,8 @@ This setting overrides the following two properties.
4141
(`driver.manage().timeouts().pageLoadTimeout()`)
4242
| {webdriver_timeouts_seconds_script} | 120 | Defines the Selenium timeout for execution of async scripts in seconds. +
4343
(`driver.manage().timeouts().setScriptTimeout()`)
44+
| {selenium_webdriver_create_retry} | 10 | Waiting time in seconds for a retry of creating a webdriver session in case the first attempt fails.
45+
| {selenium_remote_timeout_connection} | 10 | Defines the read timeout in seconds for a remote webdriver session.
46+
| {selenium_remote_timeout_read} | 90 | Defines the connection timeout in seconds for a remote webdriver session.
4447
|===
4548

driver-ui-desktop/src/main/java/eu/tsystems/mms/tic/testframework/webdrivermanager/DesktopWebDriverFactory.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@
5252
import org.openqa.selenium.ie.InternetExplorerDriver;
5353
import org.openqa.selenium.ie.InternetExplorerOptions;
5454
import org.openqa.selenium.remote.AbstractDriverOptions;
55+
import org.openqa.selenium.remote.CommandExecutor;
56+
import org.openqa.selenium.remote.HttpCommandExecutor;
5557
import org.openqa.selenium.remote.LocalFileDetector;
5658
import org.openqa.selenium.remote.RemoteWebDriver;
59+
import org.openqa.selenium.remote.http.ClientConfig;
5760
import org.openqa.selenium.safari.SafariDriver;
5861
import org.openqa.selenium.safari.SafariOptions;
5962
import org.openqa.selenium.support.events.EventFiringWebDriver;
@@ -266,7 +269,7 @@ private WebDriver newWebDriver(DesktopWebDriverRequest desktopWebDriverRequest,
266269
try {
267270
newDriver = startNewWebDriverSession(desktopWebDriverRequest, sessionContext);
268271
} catch (final SetupException e) {
269-
int ms = Testerra.Properties.WEBDRIVER_TIMEOUT_SECONDS_RETRY.asLong().intValue() * 1000;
272+
int ms = Testerra.Properties.SELENIUM_WEBDRIVER_CREATE_RETRY.asLong().intValue() * 1000;
270273
log().error(String.format("Error starting WebDriver. Trying again in %d seconds", (ms / 1000)), e);
271274
TimerUtils.sleep(ms);
272275
newDriver = startNewWebDriverSession(desktopWebDriverRequest, sessionContext);
@@ -315,18 +318,24 @@ private WebDriver startNewWebDriverSession(DesktopWebDriverRequest request, Sess
315318
try {
316319
if (request.getServerUrl().isPresent()) {
317320
final URL seleniumUrl = request.getServerUrl().get();
318-
// The old HttpClientFactory reduced timeouts of Selenium 3 because of very long timeouts
319-
// Selenium 4 uses JDK 11 HttpClient: connectionTimeout=10sec, readTimeout=180 sec, seems to be ok
320-
// see {@link org.openqa.selenium.remote.http.ClientConfig#defaultConfig()}
321-
// final HttpCommandExecutor httpCommandExecutor = new HttpCommandExecutor(new HashMap<>(), seleniumUrl, new HttpClientFactory());
321+
322322
Capabilities capabilities = request.getCapabilities();
323323
if (capabilities == null) {
324324
throw new SystemException("Cannot start browser session with empty browser options");
325325
}
326-
webDriver = RemoteWebDriver.builder()
327-
.address(seleniumUrl)
328-
.addAlternative(capabilities)
329-
.build();
326+
// Selenium default timeouts are
327+
// read timeout: 180 sec
328+
// connection timeout: 10 sec
329+
// see {@link org.openqa.selenium.remote.http.ClientConfig#defaultConfig()}
330+
// Testerra: read timeout reduced to 90 sec
331+
ClientConfig clientConfig = ClientConfig
332+
.defaultConfig()
333+
.readTimeout(Duration.ofSeconds(Testerra.Properties.SELENIUM_REMOTE_TIMEOUT_READ.asLong()))
334+
.connectionTimeout(Duration.ofSeconds(Testerra.Properties.SELENIUM_REMOTE_TIMEOUT_CONNECTION.asLong()))
335+
.baseUrl(seleniumUrl);
336+
CommandExecutor commandExecutor = new HttpCommandExecutor(clientConfig);
337+
webDriver = new RemoteWebDriver(commandExecutor, capabilities);
338+
330339
((RemoteWebDriver) webDriver).setFileDetector(new LocalFileDetector());
331340
sessionContext.setNodeUrl(seleniumUrl);
332341
} else {

driver-ui-desktop/src/main/java/eu/tsystems/mms/tic/testframework/webdrivermanager/HttpClientFactory.java

Lines changed: 0 additions & 123 deletions
This file was deleted.

0 commit comments

Comments
 (0)