org.openqa.selenium.json.JsonException:应该读取一个START\u映射,但应该是:END。通过节点执行测试时读取的最后0个字符

org.openqa.selenium.json.JsonException:应该读取一个START\u映射,但应该是:END。通过节点执行测试时读取的最后0个字符,selenium,selenium-webdriver,webdriver,selenium-grid,Selenium,Selenium Webdriver,Webdriver,Selenium Grid,我是硒的新手,并开始学习它。但是硒网格不适合我。使用的服务器版本是selenium-server-standalone-3.14.0.jar。使用命令,集线器和节点正在运行。 将节点添加到hub的代码是在Eclipse中使用TestNG编写的。代码如下: ChromeOptions options = new ChromeOptions(); options.setCapability(CapabilityType.PLATFORM_NAME, Platform.WIN10);

我是硒的新手,并开始学习它。但是硒网格不适合我。使用的服务器版本是selenium-server-standalone-3.14.0.jar。使用命令,集线器和节点正在运行。 将节点添加到hub的代码是在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/");
>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/
运行测试时,出现以下错误,并且未创建会话:

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-DWebdriver.chrome.driver=C:\SWs\chromedriver\u win32\chromedriver.exe-jar selenium-server-standalone-3.14.0.jar-role node-hub

浏览器详细信息: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 v3.14.0中提供,与提交相关。错误应该是:

Cannot coerce something that is not a number to a number: " + type
尽管您使用的是Selenium v3.14.0二进制文件,但您似乎在使用不推荐使用的函数

根据
文档能力类型,名称
不是有效配置,您需要将其更改为
平台

在使用Selenium v3.14.0二进制文件的Windows 8系统上,以下是仅执行perfecto的解决方案:

  • 代码块:

    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网格节点启动命令存在问题。按如下方式使用命令:

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/");
>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/
  • 要为ChromeDriver和Chrome注册Selenium网格节点,您需要通过ChromeDriver的绝对路径,如下所示:

    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/");
    
    >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/
    
    >java-DWebdriver.chrome.driver=C:\\path\\to\\chromedriver.exe-jar selenium-server-standalone-3.14.0.jar-角色节点-hub http://:4444/grid/register/
    

我今天遇到了这个错误,在搜索解决方案时,我在这个页面上找到了它

集线器和节点已在我的计算机中启动并运行。 我尝试在浏览器中访问。这导致了以下错误: JsonException:应读取开始映射,但应具有:结束。读取的最后0个字符:

然后发现上面的网址我用的是不正确的。相反,我需要使用


在GitHub上找到解决方案:

感谢您提供解决方案。尝试使用与此处指定的代码完全相同的代码。但这对我不起作用。正如你在帖子中所说,“平台”不起作用。错误为[RemoteTestNG]检测到TestNG版本6.14.2失败:test1 org.openqa.selenium.SessionNotCreatedException:无法创建新服务:ChromeDriverService构建信息:版本:'3.14.0',修订版:'aacccce0',时间:'2018-08-02T20:13:22.693Z'系统信息:主机:'N315',ip:'192.xxx.x',os.name:'Windows 10',os.arch:'amd64',os.version:'10.0',java.version:'9.0.1'驱动程序信息:Driver.version:unknown我之前已经在评论中要求您使用启动Selenium Grid Hub和Selenium Grid Node时使用的命令更新问题。另外还提供ChromeDriver和Chrome浏览器版本的详细信息。请更新问题check@muzirisrd-检查我的更新答案,让我知道我已经这样做了。请查找获得的输出18:28:40.368信息[selfregisteringmote.registerToHub]-将节点注册到中心:18:28:40.821信息[selfregisteringmote.registerToHub]-节点已注册到中心,并准备使用用于启动Selenium网格中心和Selenium网格节点的命令更新问题。此外,还提供ChromeDriver和Chrome浏览器版本详细信息。java-jar selenium-server-standalone-3.14.0.jar-role hub java-DWebdriver.Chrome.driver=“ChromeDriver\u win32\ChromeDriver.exe”-jar selenium-server-standalone-3.14.0.jar-角色节点-中心浏览器详细信息:Chrome 69 ChromeDriver 2.42.591088