在Selenium 3.14.0中,org.openqa.selenium.remote.internal.ApacheHttpClient已经被弃用 - 应该使用什么代替它?

8

我目前正在使用Selenium 3.14.0库,其中 org.openqa.selenium.remote.internal.ApacheHttpClient 已被弃用且没有其他信息。应该使用哪个替代品?

该类已在下一个版本3.141.59中删除。

我正在使用EdgeDriver服务如下:

final int connectionTimeout = 2 * 60 * 1000;
final int socketTimeout = 10 * 60 * 1000; // 10 minute timeout
final ApacheHttpClient.Factory clientFactory = new ApacheHttpClient.Factory(
    new HttpClientFactory(connectionTimeout, socketTimeout));

...

edgeDriverService = new EdgeDriverService.Builder()
                        .usingDriverExecutable(edgeDriver)
                        .usingAnyFreePort()
                        .build();
edgeDriverService.start();
HttpCommandExecutor executor = new HttpCommandExecutor(
    new HashMap<>(), edgeDriverService.getUrl(), clientFactory);
WebDriver driver = new RemoteWebDriver(executor, new EdgeOptions());
2个回答

11

HTTP客户端已切换为okhttp: http://square.github.io/okhttp/

这在Selenium Java版本3.11.0的CHANGELOG中提到,并且您还可以在源代码中看到它。


0

一些事实:

  • Java RemoteWebDriver客户端使用CommandExecutorRemoteWebDriver发送命令。默认情况下,RemoteWebDriver使用HttpCommandExecutor,它使用Apache HttpClient库发送命令。
  • 根据CHANGELOG
    • HttpClient实现细节从Selenium v2.45.0开始就不在HttpCommandExecutor中了。
    • 随着Selenium v3.11的推出,Selenium Grid开始使用OkHttp而不是Apache HttpClient
    • 进一步地,在发布Selenium v3.141.0时,Apache HttpClient被从selenium-server-standalone中删除,这极大地减小了selenium服务器分发包的大小。
    • 甚至apache-backed httpclient也被删除了。

9
这是有趣的背景信息,但不是问题所问的...问题是什么替代了Apache HttpClient。 - Corey Goldberg
因此,我的hub start命令注册了一些自定义servlet并使用自定义jar(java -cp selenium-server-standalone-3.141.0.jar;mycustom.jar org.openqa.grid.selenium.GridLauncherV3 -role hub -port 4444 -servlets com.myservlet -timeout 1800),但会抛出一个错误,说“Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient”。我们是否应该在上述命令中包含apache client jar文件作为额外的jar? - sjethvani

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接