使用硒网格运行硒测试案例时出错?

时间:2017-05-18 07:28:16

标签: selenium selenium-grid

我的浏览器调用代码如下:

else if(browserName.equals("chrome")) {
            System.setProperty("webdriver.chrome.driver", "/home/selenium-drivers/chromedriver");
            DesiredCapabilities capabilities = DesiredCapabilities.chrome();
            capabilities.setPlatform(Platform.LINUX);
            URL url_hub = new URL("http://my-remote-server-ip:4444/wd/hub");
            driver = new RemoteWebDriver(url_hub, capabilities);
            driver.manage().window().maximize();
            driver.get(url);
        }

运行程序时出现以下错误:

  

无法创建新的远程会话。 desired capabilities = Capabilities [{browserName = chrome,version =,platform = WINDOWS}],required capabilities = Capabilities [{}]   [grid -console] 1

1 个答案:

答案 0 :(得分:1)

以下是您的问题的答案:

Windows平台

  1. 启动Selenium Grid Hub。确认日志消息:

    14:25:50.350 INFO - Selenium Grid hub is up and running
    
  2. 打开网格控制台网址(在我的情况下为http://localhost:4444/grid/console)并观察控制台。

  3. 启动Selenium Grid Node&将其注册到Hub:

    java -Dwebdriver.chrome.driver=C:\Utility\BrowserDrivers\chromedriver.exe -jar C:\Utility\selenium-server-standalone\selenium-server-standalone-3.4.0.jar -role node -hub http://localhost:4444/grid/register
    
  4. 注意节点注册日志:

    14:33:12.354 INFO - Selenium Grid node is up and ready to register to the hub
    14:33:12.409 INFO - Starting auto registration thread. Will try to register every 5000 ms.
    14:33:12.409 INFO - Registering the node to the hub: http://localhost:4444/grid/register
    14:33:12.756 INFO - The node is registered to the hub and ready to use
    
  5. 以下是我自己的一组代码扭曲了一点,以适合localhost:4444设置的本地Windows 8框:

    System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
    DesiredCapabilities cap = DesiredCapabilities.chrome();
    cap.setBrowserName("chrome");
    cap.setPlatform(Platform.WINDOWS);
    URL url = new URL("http://localhost:4444/wd/hub");
    WebDriver driver = new RemoteWebDriver(url, cap);
    driver.get("http://google.com/");
    System.out.println("Title is : "+driver.getTitle());
    driver.quit();
    
  6. 我得到一个结果:

    Title is : Google
    PASSED: test1
    
    ===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 0
    ===============================================
    
  7. 如果这有助于您,请告诉我。