From a63cb2a022069537fca82f916b052124f1bb77aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gro=C3=9Fmann?= Date: Mon, 20 Nov 2023 10:02:09 +0100 Subject: [PATCH 1/4] Fixed creating a remote webdriver, added timeout configs --- .../mms/tic/testframework/common/Testerra.java | 2 ++ .../webdrivermanager/DesktopWebDriverFactory.java | 15 +++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/eu/tsystems/mms/tic/testframework/common/Testerra.java b/core/src/main/java/eu/tsystems/mms/tic/testframework/common/Testerra.java index c9cc9aece..1f4090ec7 100644 --- a/core/src/main/java/eu/tsystems/mms/tic/testframework/common/Testerra.java +++ b/core/src/main/java/eu/tsystems/mms/tic/testframework/common/Testerra.java @@ -77,6 +77,8 @@ public enum Properties implements IProperties { 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), + WEBDRIVER_TIMEOUT_REMOTE_READ("webdriver.timeouts.remote.read.seconds", 90), + WEBDRIVER_TIMEOUT_REMOTE_CONNECTION("webdriver.timeouts.remote.connection.seconds", 10), PERF_TEST("tt.perf.test", false), PERF_GENERATE_STATISTICS("tt.perf.generate.statistics", false), /** diff --git a/driver-ui-desktop/src/main/java/eu/tsystems/mms/tic/testframework/webdrivermanager/DesktopWebDriverFactory.java b/driver-ui-desktop/src/main/java/eu/tsystems/mms/tic/testframework/webdrivermanager/DesktopWebDriverFactory.java index 9861f63ad..63cd57b79 100644 --- a/driver-ui-desktop/src/main/java/eu/tsystems/mms/tic/testframework/webdrivermanager/DesktopWebDriverFactory.java +++ b/driver-ui-desktop/src/main/java/eu/tsystems/mms/tic/testframework/webdrivermanager/DesktopWebDriverFactory.java @@ -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; @@ -323,10 +326,14 @@ private WebDriver startNewWebDriverSession(DesktopWebDriverRequest request, Sess if (capabilities == null) { throw new SystemException("Cannot start browser session with empty browser options"); } - webDriver = RemoteWebDriver.builder() - .address(seleniumUrl) - .addAlternative(capabilities) - .build(); + ClientConfig clientConfig = ClientConfig + .defaultConfig() + .readTimeout(Duration.ofSeconds(Testerra.Properties.WEBDRIVER_TIMEOUT_REMOTE_READ.asLong())) + .connectionTimeout(Duration.ofSeconds(Testerra.Properties.WEBDRIVER_TIMEOUT_REMOTE_CONNECTION.asLong())) + .baseUrl(seleniumUrl); + CommandExecutor commandExecutor = new HttpCommandExecutor(clientConfig); + webDriver = new RemoteWebDriver(commandExecutor, capabilities); + ((RemoteWebDriver) webDriver).setFileDetector(new LocalFileDetector()); sessionContext.setNodeUrl(seleniumUrl); } else { From 092456692df017c0e7fa85a041405a34a502d4c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gro=C3=9Fmann?= Date: Mon, 20 Nov 2023 10:39:04 +0100 Subject: [PATCH 2/4] Added new timeout configs to doc --- .../eu/tsystems/mms/tic/testframework/common/Testerra.java | 4 ++-- docs/src/docs/properties/property-attributes.adoc | 2 ++ docs/src/docs/properties/webdriver-props.adoc | 2 ++ .../webdrivermanager/DesktopWebDriverFactory.java | 4 ++-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/eu/tsystems/mms/tic/testframework/common/Testerra.java b/core/src/main/java/eu/tsystems/mms/tic/testframework/common/Testerra.java index 1f4090ec7..34fecaffe 100644 --- a/core/src/main/java/eu/tsystems/mms/tic/testframework/common/Testerra.java +++ b/core/src/main/java/eu/tsystems/mms/tic/testframework/common/Testerra.java @@ -77,8 +77,8 @@ public enum Properties implements IProperties { 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), - WEBDRIVER_TIMEOUT_REMOTE_READ("webdriver.timeouts.remote.read.seconds", 90), - WEBDRIVER_TIMEOUT_REMOTE_CONNECTION("webdriver.timeouts.remote.connection.seconds", 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), /** diff --git a/docs/src/docs/properties/property-attributes.adoc b/docs/src/docs/properties/property-attributes.adoc index 49b353ad7..5707d55e6 100644 --- a/docs/src/docs/properties/property-attributes.adoc +++ b/docs/src/docs/properties/property-attributes.adoc @@ -23,6 +23,8 @@ :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_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 diff --git a/docs/src/docs/properties/webdriver-props.adoc b/docs/src/docs/properties/webdriver-props.adoc index 9bc4ccf4a..42384c7ab 100644 --- a/docs/src/docs/properties/webdriver-props.adoc +++ b/docs/src/docs/properties/webdriver-props.adoc @@ -41,5 +41,7 @@ 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_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. |=== diff --git a/driver-ui-desktop/src/main/java/eu/tsystems/mms/tic/testframework/webdrivermanager/DesktopWebDriverFactory.java b/driver-ui-desktop/src/main/java/eu/tsystems/mms/tic/testframework/webdrivermanager/DesktopWebDriverFactory.java index 63cd57b79..4cc7a2c7f 100644 --- a/driver-ui-desktop/src/main/java/eu/tsystems/mms/tic/testframework/webdrivermanager/DesktopWebDriverFactory.java +++ b/driver-ui-desktop/src/main/java/eu/tsystems/mms/tic/testframework/webdrivermanager/DesktopWebDriverFactory.java @@ -328,8 +328,8 @@ private WebDriver startNewWebDriverSession(DesktopWebDriverRequest request, Sess } ClientConfig clientConfig = ClientConfig .defaultConfig() - .readTimeout(Duration.ofSeconds(Testerra.Properties.WEBDRIVER_TIMEOUT_REMOTE_READ.asLong())) - .connectionTimeout(Duration.ofSeconds(Testerra.Properties.WEBDRIVER_TIMEOUT_REMOTE_CONNECTION.asLong())) + .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); From 14e0d69b952326db97c940d5c84f5e435295c946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gro=C3=9Fmann?= Date: Mon, 20 Nov 2023 10:51:08 +0100 Subject: [PATCH 3/4] Changed the name of the session retry prop and added it to doc --- .../java/eu/tsystems/mms/tic/testframework/common/Testerra.java | 2 +- docs/src/docs/properties/property-attributes.adoc | 1 + docs/src/docs/properties/webdriver-props.adoc | 1 + .../testframework/webdrivermanager/DesktopWebDriverFactory.java | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/eu/tsystems/mms/tic/testframework/common/Testerra.java b/core/src/main/java/eu/tsystems/mms/tic/testframework/common/Testerra.java index 34fecaffe..f9ed7039a 100644 --- a/core/src/main/java/eu/tsystems/mms/tic/testframework/common/Testerra.java +++ b/core/src/main/java/eu/tsystems/mms/tic/testframework/common/Testerra.java @@ -76,7 +76,7 @@ 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), diff --git a/docs/src/docs/properties/property-attributes.adoc b/docs/src/docs/properties/property-attributes.adoc index 5707d55e6..abf220e60 100644 --- a/docs/src/docs/properties/property-attributes.adoc +++ b/docs/src/docs/properties/property-attributes.adoc @@ -23,6 +23,7 @@ :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 diff --git a/docs/src/docs/properties/webdriver-props.adoc b/docs/src/docs/properties/webdriver-props.adoc index 42384c7ab..f219f4a2a 100644 --- a/docs/src/docs/properties/webdriver-props.adoc +++ b/docs/src/docs/properties/webdriver-props.adoc @@ -41,6 +41,7 @@ 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. |=== diff --git a/driver-ui-desktop/src/main/java/eu/tsystems/mms/tic/testframework/webdrivermanager/DesktopWebDriverFactory.java b/driver-ui-desktop/src/main/java/eu/tsystems/mms/tic/testframework/webdrivermanager/DesktopWebDriverFactory.java index 4cc7a2c7f..a665f324e 100644 --- a/driver-ui-desktop/src/main/java/eu/tsystems/mms/tic/testframework/webdrivermanager/DesktopWebDriverFactory.java +++ b/driver-ui-desktop/src/main/java/eu/tsystems/mms/tic/testframework/webdrivermanager/DesktopWebDriverFactory.java @@ -269,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); From 47c694b6d0fb2d03a80c6c37c3225ad744a81393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gro=C3=9Fmann?= Date: Mon, 20 Nov 2023 10:55:08 +0100 Subject: [PATCH 4/4] Cleanup --- .../DesktopWebDriverFactory.java | 10 +- .../webdrivermanager/HttpClientFactory.java | 123 ------------------ 2 files changed, 6 insertions(+), 127 deletions(-) delete mode 100644 driver-ui-desktop/src/main/java/eu/tsystems/mms/tic/testframework/webdrivermanager/HttpClientFactory.java diff --git a/driver-ui-desktop/src/main/java/eu/tsystems/mms/tic/testframework/webdrivermanager/DesktopWebDriverFactory.java b/driver-ui-desktop/src/main/java/eu/tsystems/mms/tic/testframework/webdrivermanager/DesktopWebDriverFactory.java index a665f324e..fe708a467 100644 --- a/driver-ui-desktop/src/main/java/eu/tsystems/mms/tic/testframework/webdrivermanager/DesktopWebDriverFactory.java +++ b/driver-ui-desktop/src/main/java/eu/tsystems/mms/tic/testframework/webdrivermanager/DesktopWebDriverFactory.java @@ -318,14 +318,16 @@ 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"); } + // 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())) diff --git a/driver-ui-desktop/src/main/java/eu/tsystems/mms/tic/testframework/webdrivermanager/HttpClientFactory.java b/driver-ui-desktop/src/main/java/eu/tsystems/mms/tic/testframework/webdrivermanager/HttpClientFactory.java deleted file mode 100644 index d348ca14c..000000000 --- a/driver-ui-desktop/src/main/java/eu/tsystems/mms/tic/testframework/webdrivermanager/HttpClientFactory.java +++ /dev/null @@ -1,123 +0,0 @@ - -package eu.tsystems.mms.tic.testframework.webdrivermanager; - -/* - * Testerra - * - * (C) 2020, Eric Kubenka, T-Systems Multimedia Solutions GmbH, Deutsche Telekom AG - * - * Deutsche Telekom AG and all other contributors / - * copyright owners license this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this - * file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -import org.openqa.selenium.remote.http.ClientConfig; -import org.openqa.selenium.remote.http.HttpClient; - -import java.time.Duration; - -/** - * This Client Factory allows us to reduces timeouts of 3 HOURS to our custom timeouts. - * This will help, to avoid blocking selenium commands. - *

- * Date: 21.11.2019 - * Time: 09:43 - * - * @author Eric Kubenka - */ -class HttpClientFactory implements HttpClient.Factory { - - /** TODO: Delete or re-implement - * This class was used to set a custom timeout for sending commands to browser sessions. Selenium 3 has a default of 120 minutes. This was reduced to 2 minutes. - * - * For using in Selenium 4 this class has to re-implement because Selenium 4 uses HttpClient of Java 11. - * Selenium 4 has the following default timeouts: connectionTimeout=10sec, readTimeout=180 sec, seems to be ok - */ - - private final Duration factoryConnectionTimeout = Duration.ofSeconds(120); // Kill, when connect does not succeed in this timeout - private final Duration factoryReadTimeout = factoryConnectionTimeout; // Kill hanging / stuck selenium commands after this timeout. - -// private final ConnectionPool pool = new ConnectionPool(); - - // TODO: Just a placeholder - @Override - public HttpClient createClient(ClientConfig config) { - return null; - } - -// @Override -// public HttpClient.Builder builder() { -// -// // this code is copied from OkHttpClient.Factory .. and modified in timeout configuration. -// return new HttpClient.Builder() { -// -// @Override -// public HttpClient createClient(URL url) { -// -// connectionTimeout = factoryConnectionTimeout; -// readTimeout = factoryReadTimeout; -// -// okhttp3.OkHttpClient.Builder client = new okhttp3.OkHttpClient.Builder() -// .connectionPool(pool) -// .followRedirects(true) -// .followSslRedirects(true) -// .proxy(proxy) -// .readTimeout(readTimeout.toMillis(), MILLISECONDS) -// .connectTimeout(connectionTimeout.toMillis(), MILLISECONDS); -// -// String info = url.getUserInfo(); -// if (!Strings.isNullOrEmpty(info)) { -// String[] parts = info.split(":", 2); -// String user = parts[0]; -// String pass = parts.length > 1 ? parts[1] : null; -// -// String credentials = Credentials.basic(user, pass); -// -// client.authenticator((route, response) -> { -// if (response.request().header("Authorization") != null) { -// return null; // Give up, we've already attempted to authenticate. -// } -// -// return response.request().newBuilder() -// .header("Authorization", credentials) -// .build(); -// }); -// } -// -// client.addNetworkInterceptor(chain -> { -// Request request = chain.request(); -// Response response = chain.proceed(request); -// return response.code() == 408 -// ? response.newBuilder().code(500).message("Server-Side Timeout").build() -// : response; -// }); -// -// return new org.openqa.selenium.remote.internal.OkHttpClient(client.build(), url); -// } -// }; -// } -// -// @Override -// public HttpClient createClient(URL url) { -// -// return builder().createClient(url); -// } -// -// @Override -// public void cleanupIdleClients() { -// -// pool.evictAll(); -// } -}