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..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,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), /** diff --git a/docs/src/docs/properties/property-attributes.adoc b/docs/src/docs/properties/property-attributes.adoc index 49b353ad7..abf220e60 100644 --- a/docs/src/docs/properties/property-attributes.adoc +++ b/docs/src/docs/properties/property-attributes.adoc @@ -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 diff --git a/docs/src/docs/properties/webdriver-props.adoc b/docs/src/docs/properties/webdriver-props.adoc index 9bc4ccf4a..f219f4a2a 100644 --- a/docs/src/docs/properties/webdriver-props.adoc +++ b/docs/src/docs/properties/webdriver-props.adoc @@ -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. |=== 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..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 @@ -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; @@ -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); @@ -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 { 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(); -// } -}