运行 使用 selenium 网格的 selenium 测试用例时出现错误?

Getting error while running the selenium test cases with 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);
        }

运行 程序出现以下错误:

Unable to create new remote session. desired capabilities = Capabilities [{browserName=chrome, version=, platform=WINDOWS}], required capabilities = Capabilities [{}] []1

这是您问题的答案:

Windows 平台

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

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

  3. 启动 Selenium 网格节点并将其注册到集线器:

    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. 这是自己的工作代码集,经过稍微改动以适合我的本地 Windows 8 框作为 localhost:4444 设置:

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

如果这对你有帮助,请告诉我。