尝试双向对话,假设Postel法则在远端适用,并且使用ChromeDriver和Selenium退回到原始OSS JSON

下面是我用来初始化chrome webdriver的代码片段:

System.out.println("Initializing Chrome");
ChromeOptions options = new ChromeOptions();
//options.setBinary("C:/Program Files (x86)/Google/Chrome/Application");
options.addArguments("start-maximized");
options.setExperimentalOption("excludeSwitches",new String[]{"enable-automation"});
options.addArguments("--disable-extensions");
options.addArguments("--disable-infobars");
options.addArguments("--allow-running-insecure-content");
WDriver = new ChromeDriver(options);
//WDriver = new ChromeDriver();
WDriver.manage().timeouts().implicitlyWait(60,TimeUnit.SECONDS);
System.out.println("Chrome Initialization Complete");

但是似乎要打开两个chrome实例,这将显示在控制台上:

Initializing Chrome
Starting ChromeDriver 78.0.3904.70 (edb9c9f3de0247fd912a77b7f6cae7447f6d3ad5-refs/branch- 
heads/3904@{#800}) on port 12262
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious 
code.
Nov 04,2019 3:29:38 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session,assuming Postel's Law holds true on the remote end
log4j:WARN No appenders could be found for logger 
(org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
[1572910181.451][WARNING]: Timed out connecting to Chrome,retrying...
Nov 04,2019 3:29:43 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to original OSS JSON Wire Protocol.
[1572910186.002][WARNING]: Timed out connecting to Chrome,2019 3:29:48 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Chrome Initialization Complete

Chrome版本:78.0.3904.87

Chromedriver版本:chromedriver_78.0.3904.70

硒版本:3.141.59

虽然问题不是主要障碍,但它打开chrome的第二个实例会很烦人,它将在待机状态下占用内存。

干杯。

tldtc007 回答:尝试双向对话,假设Postel法则在远端适用,并且使用ChromeDriver和Selenium退回到原始OSS JSON

您需要注意以下几点:

此错误消息...

Nov 04,2019 3:29:38 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session,assuming Postel's Law holds true on the remote end

...表示 ChromeDriver 无法启动/产生新的 WebBrowser ,即 Chrome浏览器会话。

根据讨论Attempting bi-dialect session,assuming Postel's Law holds true on the remote end thread 'webdriver dispatcher' panicked at 'index out of bounds: the len is 0 but the index is 0 Selenium Client v3.0.0-beta3 出现了此问题,该客户端发布于 2016-09-01 14:57:03 -0700

西蒙在comment中提到:

  

根本原因是 ClassCastException 。现在,我们捕获该异常,记录我们尝试解析的内容,然后继续进行其他尝试以完成握手。此修复程序可在 Selenium Client v3.0.0-beta4中获得。

最合适的解决方案是: -将升级到当前的Version 3.141.59水平。

  

您可以在org.openqa.selenium.remote.ProtocolHandshake createSession INFORMATION: Attempting bi-dialect session with Selenium Grid

中找到详细的讨论

下一条错误消息...

Nov 04,2019 3:29:43 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to original OSS JSON Wire Protocol.
[1572910186.002][WARNING]: Timed out connecting to Chrome,retrying...
Nov 04,2019 3:29:48 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS

...还暗示您正在使用的 ChromeDriver / Chrome浏览器组合不是最新的组合,因为 ChromeDriver 的当前实现遵循 W3C ,初始日志如下;

Starting ChromeDriver 78.0.3904.70 (edb9c9f3de0247fd912a77b7f6cae7447f6d3ad5-refs/branch-heads/3904@{#800}) on port 9626
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Nov 05,2019 3:41:53 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C

解决方案

确保:

  • JDK 已升级到当前级别JDK 8u222
  • 已升级到当前级别Version 3.141.59
  • ChromeDriver 已更新为当前的ChromeDriver v78.0级别。
  • Chrome 已更新为当前的 Chrome版本78.0 级别。 (根据ChromeDriver v78.0 release notes
  • 通过您的 IDE
  • 清理您的项目工作区重建您的项目,并且仅具有必需的依赖项。
  • (仅适用于 WindowsOS )使用CCleaner工具清除执行 Test Suite 前后的所有操作系统琐事。
  • (仅仅LinuxOS Free Up and Release the Unused/Cached Memory in Ubuntu/Linux Mint在执行 Test Suite 之前和之后。
  • 如果您的基本 Web客户端版本太旧,则将其卸载并安装最新版本的 Web客户端 GA。
  • 进行系统重启
  • 非root用户用户的身份执行@Test
  • 始终在driver.quit()方法内调用tearDown(){},以优雅地关闭和销毁 WebDriver Web Client 实例。

参考

您可以在以下位置找到一些相关的讨论


Outro

根据此jar-download.com文章, Selenium v​​3.0.1 createSession() 文件中的ProtocolHandshake.java包含以下内容: >

public Result createSession(HttpClient client,Command command)
    throws IOException {
    // Avoid serialising the capabilities too many times. Things like profiles are expensive.

    Capabilities desired = (Capabilities) command.getParameters().get("desiredCapabilities");
    desired = desired == null ? new DesiredCapabilities() : desired;
    Capabilities required = (Capabilities) command.getParameters().get("requiredCapabilities");
    required = required == null ? new DesiredCapabilities() : required;

    String des = new BeanToJsonConverter().convert(desired);
    String req = new BeanToJsonConverter().convert(required);

    // Assume the remote end obeys the robustness principle.
    StringBuilder parameters = new StringBuilder("{");
    amendW3CParameters(parameters,des,req);
    parameters.append(",");
    amendOssParamters(parameters,req);
    parameters.append("}");
    LOG.info("Attempting bi-dialect session,assuming Postel's Law holds true on the remote end");
    Optional result = createSession(client,parameters);

    // Assume a fragile OSS webdriver implementation
    if (!result.isPresent()) {
      parameters = new StringBuilder("{");
      amendOssParamters(parameters,req);
      parameters.append("}");
      LOG.info("Falling back to original OSS JSON Wire Protocol.");
      result = createSession(client,parameters);
    }

    // Assume a fragile w3c implementation
    if (!result.isPresent()) {
      parameters = new StringBuilder("{");
      amendW3CParameters(parameters,req);
      parameters.append("}");
      LOG.info("Falling back to straight W3C remote end connection");
      result = createSession(client,parameters);
    }

    if (result.isPresent()) {
      Result toReturn = result.get();
      LOG.info(String.format("Detected dialect: %s",toReturn.dialect));
      return toReturn;
    }

    throw new SessionNotCreatedException(
      String.format(
        "Unable to create new remote session. " +
        "desired capabilities = %s,required capabilities = %s",desired,required));
}
本文链接:https://www.f2er.com/3163125.html

大家都在问