gpt4 book ai didi

selenium - org.openqa.selenium.json.JsonException : Expected to read a START_MAP but instead have: END. 通过 Node 执行测试时读取的最后 0 个字符

转载 作者:行者123 更新时间:2023-12-04 01:51:24 64 4
gpt4 key购买 nike

我是 Selenium 的新手并开始学习它。但是 Selenium Grid 不适合我。使用的服务器版本是 selenium-server-standalone-3.14.0.jar。使用命令,集线器和节点正在运行。
将节点添加到集线器的代码是使用 Eclipse 中的 TestNG 编写的。代码如下:

ChromeOptions options = new ChromeOptions();
options.setCapability(CapabilityType.PLATFORM_NAME, Platform.WIN10);
options.setCapability(CapabilityType.BROWSER_NAME, "chrome");
driver = new RemoteWebDriver(new URL("http://192.xxx.x.xx:48807/wd/hub"), options); driver.get("https://www.amazon.in/");

运行测试时,出现以下错误并且未创建 session :
org.openqa.selenium.WebDriverException: Unable to parse remote response: 
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:111)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:212)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:130)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:143)
at grid.Node2.f(Node2.java:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:580)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:716)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:988)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.access$000(SuiteRunner.java:40)
at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:489)
at org.testng.internal.thread.ThreadUtil$1.call(ThreadUtil.java:52)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.openqa.selenium.json.JsonException: Expected to read a START_MAP but instead have: END. Last 0 characters read:
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-

集线器命令:
java -jar selenium-server-standalone-3.14.0.jar -role hub

节点命令:
java -DWebdriver.chrome.driver=C:\SWs\chromedriver_win32\chromedriver.exe -jar selenium-server-standalone-3.14.0.jar -role node -hub http://xxx.xxx.x.x:4444/grid/register/

浏览器详情:Chrome 69
ChromeDriver 2.42.591088

有人请帮忙解决这个问题,在此先感谢

最佳答案

对错误有点惊讶:

org.openqa.selenium.json.JsonException: Expected to read a START_MAP but instead have: END. Last 0 characters read

根据 Selenium 3.12.0 Windows org.openqa.selenium.json.JsonException: Cannot coerce something that is not a number to a number: STRING修复应该在 中可用 Selenium v3.14.0 关于提交 Allow the number coercer to implicitly coerce strings to numbers .错误应该是:
Cannot coerce something that is not a number to a number: " + type

仍然当您使用 Selenium v​​3.14.0 二进制文件时,您似乎正在使用已弃用的函数。

根据文档 能力类型 PLATFORM_NAME 不是有效配置,您需要将其更改为 PLATFORM .

在我的带有 Selenium v​​3.14.0 二进制文件的 Windows 8 系统上,这里是执行完美的解决方案:
  • 代码块:
    import java.net.MalformedURLException;
    import java.net.URL;

    import org.openqa.selenium.Platform;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeOptions;
    import org.openqa.selenium.remote.CapabilityType;
    import org.openqa.selenium.remote.RemoteWebDriver;
    import org.testng.annotations.Test;

    public class testChromeOnGrid_test
    {

    @Test
    public void test1() throws MalformedURLException
    {
    System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
    ChromeOptions options = new ChromeOptions();
    options.setCapability(CapabilityType.PLATFORM, Platform.WIN8);
    options.setCapability(CapabilityType.BROWSER_NAME, "chrome");
    WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), options);
    driver.get("http://google.com/");
    System.out.println("Title is : "+driver.getTitle());
    driver.quit();
    }
    }
  • 控制台输出:
    [RemoteTestNG] detected TestNG version 6.14.2
    Oct 16, 2018 3:00:57 PM org.openqa.selenium.remote.ProtocolHandshake createSession
    INFO: Detected dialect: OSS
    Title is : Google
    PASSED: test1

    ===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 0
    ===============================================


    ===============================================
    Default suite
    Total tests run: 1, Failures: 0, Skips: 0
    ===============================================


  • 更新

    根据您的问题更新,您使用的 Selenium Grid Node 启动命令存在问题。使用命令如下:
  • 要为 ChromeDriver 和 Chrome 注册 Selenium Grid 节点,您需要传递 ChromeDriver 的绝对路径,如下所示:
    >java -DWebdriver.chrome.driver=C:\\path\\to\\chromedriver.exe -jar selenium-server-standalone-3.14.0.jar -role node -hub http://<IP_GRID_HUB>:4444/grid/register/
  • 关于selenium - org.openqa.selenium.json.JsonException : Expected to read a START_MAP but instead have: END. 通过 Node 执行测试时读取的最后 0 个字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52830236/

    64 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com