【问题标题】:org.openqa.selenium.remote.internal.ApacheHttpClient is deprecated in Selenium 3.14.0 - What should be used instead?org.openqa.selenium.remote.internal.ApacheHttpClient 在 Selenium 3.14.0 中已弃用 - 应该改用什么?
【发布时间】:2019-07-21 08:25:59
【问题描述】:

我目前正在使用 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());

【问题讨论】:

    标签: java selenium selenium-webdriver webdriver okhttp


    【解决方案1】:

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

    这在 Selenium Java CHANGELOG 3.11.0 版本中有所提及,您也可以在源代码中看到它。

    【讨论】:

      【解决方案2】:

      几个事实:

      • Java RemoteWebDriver 客户端使用 CommandExecutor 将命令发送到 RemoteWebDriver。默认情况下,RemoteWebDriver 使用 HttpCommandExecutor,它使用 Apache HttpClient 库来发送命令。
      • 根据 CHANGELOG
        • Selenium v​​2.45.0 中的HttpCommandExecutor 中没有HttpClient 的实现细节。
        • 随着 Selenium v​​3.11 的推出,Selenium Grid 改用 OkHttp 而不是 Apache HttpClient
        • 随着 Selenium v​​3.141.0 的发布,Apache HttpClient 已从 selenium-server-standalone 中删除,这极大地 减小了 selenium 服务器分发包的大小。
        • 甚至apache-backed httpclient 也被删除了。

      【讨论】:

      • 这是有趣的背景信息,但不是问题所问的......问题是什么取代了 Apache HttpClient
      • 因为这个我的集线器启动命令,它注册了一些自定义 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 客户端 jar 文件作为额外的 jar?
      猜你喜欢
      • 2014-01-09
      • 1970-01-01
      • 1970-01-01
      • 2013-09-01
      • 1970-01-01
      • 2019-08-28
      • 2010-09-17
      • 1970-01-01
      • 2019-03-11
      相关资源
      最近更新 更多