org.openqa.selenium.json.JsonException: Expected to read a START_MAP but instead have: END. Last 0 characters read while executing tests through Node

纵然是瞬间 提交于 2019-12-24 04:40:56

问题


I am new to Selenium and started learning it. But the Selenium Grid is not working for me. The server version used is selenium-server-standalone-3.14.0.jar. Using command, the hub and node are running. The code for adding nodes to hub is written using TestNG in Eclipse. The code is as follows:

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/");

While running the test, the following error occurs and the sessions are not created:

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-

Hub Command:

java -jar selenium-server-standalone-3.14.0.jar -role hub

Node Command: 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/

Browser details : Chrome 69
ChromeDriver 2.42.591088

Anybody please help to resolve this issue, thanks in advance


回答1:


A bit suprised with the error:

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

As per Selenium 3.12.0 Windows org.openqa.selenium.json.JsonException: Cannot coerce something that is not a number to a number: STRING the fix should have been available in Selenium v3.14.0 with respect the the commit Allow the number coercer to implicitly coerce strings to numbers. The error should have been:

Cannot coerce something that is not a number to a number: " + type

Still as you are using Selenium v3.14.0 binaries it seems you are using the deprecated functions.

As per the documentation CapabilityType of PLATFORM_NAME is not a valid configuration and you need to change it as PLATFORM.

On my Windows 8 system with Selenium v3.14.0 binaries here is the solution which executes just perfecto:

  • Code Block:

    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();
        }
    }
    
  • Console Output:

    [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
    ===============================================
    

Update

As per your question update there is an issue with the Selenium Grid Node starting command you have used. Use the command as follows:

  • To register a Selenium Grid Node for ChromeDriver and Chrome you need to pass the absolute path of the ChromeDriver as follows:

    >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/
    



回答2:


I ran into this error today, and while searching for the solution I landed on this page.

The hub and the node are up and running in my machine. I tried accessing http://localhost:4444/grid/register/ in the browser. which has resulted into following error: JsonException: Expected to read a START_MAP but instead have: END. Last 0 characters read:

Then found that the above URL what I have used is incorrect. Instead I need to use http://localhost:4444/grid/console

Solution found here on GitHub: https://github.com/SeleniumHQ/selenium/issues/6446



来源:https://stackoverflow.com/questions/52830236/org-openqa-selenium-json-jsonexception-expected-to-read-a-start-map-but-instead

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!