|
52 | 52 | import org.openqa.selenium.ie.InternetExplorerDriver; |
53 | 53 | import org.openqa.selenium.ie.InternetExplorerOptions; |
54 | 54 | import org.openqa.selenium.remote.AbstractDriverOptions; |
| 55 | +import org.openqa.selenium.remote.CommandExecutor; |
| 56 | +import org.openqa.selenium.remote.HttpCommandExecutor; |
55 | 57 | import org.openqa.selenium.remote.LocalFileDetector; |
56 | 58 | import org.openqa.selenium.remote.RemoteWebDriver; |
| 59 | +import org.openqa.selenium.remote.http.ClientConfig; |
57 | 60 | import org.openqa.selenium.safari.SafariDriver; |
58 | 61 | import org.openqa.selenium.safari.SafariOptions; |
59 | 62 | import org.openqa.selenium.support.events.EventFiringWebDriver; |
@@ -266,7 +269,7 @@ private WebDriver newWebDriver(DesktopWebDriverRequest desktopWebDriverRequest, |
266 | 269 | try { |
267 | 270 | newDriver = startNewWebDriverSession(desktopWebDriverRequest, sessionContext); |
268 | 271 | } 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; |
270 | 273 | log().error(String.format("Error starting WebDriver. Trying again in %d seconds", (ms / 1000)), e); |
271 | 274 | TimerUtils.sleep(ms); |
272 | 275 | newDriver = startNewWebDriverSession(desktopWebDriverRequest, sessionContext); |
@@ -315,18 +318,24 @@ private WebDriver startNewWebDriverSession(DesktopWebDriverRequest request, Sess |
315 | 318 | try { |
316 | 319 | if (request.getServerUrl().isPresent()) { |
317 | 320 | 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 | + |
322 | 322 | Capabilities capabilities = request.getCapabilities(); |
323 | 323 | if (capabilities == null) { |
324 | 324 | throw new SystemException("Cannot start browser session with empty browser options"); |
325 | 325 | } |
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 | + |
330 | 339 | ((RemoteWebDriver) webDriver).setFileDetector(new LocalFileDetector()); |
331 | 340 | sessionContext.setNodeUrl(seleniumUrl); |
332 | 341 | } else { |
|
0 commit comments