Skip to main content

Affected Selenium java client versions

The problem happens as Selenium since version 4.14.0 switched to the standard JDK http client which automatically does HTTP/2

Open JDK issue: https://bugs.openjdk.org/browse/JDK-8335181

Client side

Specify http version when creating WebDriver

DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("digitalai:accessKey", ACCESS_KEY);
dc.setCapability(CapabilityType.BROWSER_NAME, "chrome");
// In this snippet it's assumed that existing code already uses DesiredCapabilities,
// in new code capabilities can be set via the corresponding builder method

RemoteWebDriverBuilder builder = RemoteWebDriver
.builder()
.address("https://cloud.example.com/wd/hub")
.config(ClientConfig.defaultConfig().version(HttpClient.Version.HTTP_1_1.name()));
dc.asMap().forEach(builder::setCapability);
driver = builder.build();

Override Selenium HttpClient implementation

Add a class like the following to your test project

import com.google.auto.service.AutoService;
import java.net.http.HttpClient.Version;
import org.openqa.selenium.remote.http.ClientConfig;
import org.openqa.selenium.remote.http.HttpClient;
import org.openqa.selenium.remote.http.HttpClientName;

@AutoService(HttpClient.Factory.class)
@HttpClientName("digital.ai.http11")
public class DigitalAiHttp11ClientFactory implements HttpClient.Factory {
private HttpClient.Factory delegate;

@Override
public HttpClient createClient(ClientConfig config) {
if (config.version() == null) {
config = config.version(Version.HTTP_1_1.name());
}
if (delegate == null) {
delegate = HttpClient.Factory.create("jdk-http-client");
}
return delegate.createClient(config);
}

@Override
public void cleanupIdleClients() {
if (delegate != null) {
delegate.cleanupIdleClients();
}
}
}

and then make use of it by setting the system property webdriver.http.factory to the assigned name digital.ai.http11

The property can be set either in code System.setProperty() or via the build tools

For example in Gradle it can be set with code like the following

test {
systemProperty "webdriver.http.factory", "digital.ai.http11"
}

and then tests can continue to use the RemoteWebDriver constructor

driver = new RemoteWebDriver(new URL("https://cloud.example.com/wd/hub"), dc);

Backend configuration

Increase keepalive_requests in Region Proxy (Linux or Mac)

in the region-proxy machine create a file

  • in Linux - /etc/nginx/static_rules_keepavlie.conf

  • in Mac - config/nginx-conf/static_rules_keepavlie.conf under the Proxy installation folder

with the following contents

keepalive_requests 5000;

and then restart the regional-proxy service.

The default value is 1000, the new value should be higher and depends on the test duration.