Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用selenium网格运行selenium测试用例时出错?_Selenium_Selenium Grid - Fatal编程技术网

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

使用selenium网格运行selenium测试用例时出错?,selenium,selenium-grid,Selenium,Selenium Grid,我的浏览器调用代码如下所示: else if(browserName.equals("chrome")) { System.setProperty("webdriver.chrome.driver", "/home/selenium-drivers/chromedriver"); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabili

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

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);
        }
运行程序时出现以下错误:

无法创建新的远程会话。所需功能=功能[{browserName=chrome,版本=,平台=WINDOWS}],所需功能=功能[{}] []


以下是你问题的答案:

Windows平台
  • 启动Selenium网格中心。确认日志消息:

    14:25:50.350 INFO - Selenium Grid hub is up and running
    
  • 打开网格控制台URL(在我的例子中)并观察控制台

  • 启动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
    
  • 请查看节点注册日志:

    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
    
  • 下面是我自己的工作代码集,经过一些扭曲,以适合我的本地Windows 8框,如
    localhost:4444
    settings:

    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();
    
  • 我得到的结果如下:

    Title is : Google
    PASSED: test1
    
    ===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 0
    ===============================================
    

  • 让我知道这是否对您有帮助。

    您是否成功启动了集线器和节点?@Dev是的。我收到了控制台消息“08:40:54.801信息-节点已注册到集线器并准备好使用”。您能告诉我如何启动集线器和节点的命令吗?Thanks@Dev我正在通过Jenkins运行hub,并且我正在为节点“java-jar selenium-server-standalone-3.4.0.jar-role node-hub”使用的命令检查网格控制台,如果您看到节点注册器已经完成了上述所有步骤,但是“org.openqa.selenium.SessionNotCreatedException:无法创建新的远程会话。所需功能=功能[{browserName=chrome,版本=,平台=WINDOWS}],所需功能=功能[{}]构建信息:版本:'3.0.1',版本:'1969d75',时间:'2016-10-18 09:49:13-0700'系统信息:主机:'arima-latitude-3460',ip:'127.0.1.1',os.name:'Linux',os.arch:'amd64',os.version:'3.13.0-117-generic',java.version:'1.8.0131'驱动程序信息:Driver.version:RemoteWebDriver“此错误。您的操作系统是Linux,因此必须相应地进行某些更改。1.
    chromedriver的路径
    (Linux类型绝对路径&不带扩展名).2.将
    Platform.WINDOWS
    更改为
    Platform.LINUX
    3.传递准确的IP和端口,而不是
    http://localhost:4444/wd/hub
    我已经在代码中更改了这一点,现在在本地机器上运行程序时工作正常,但在云上运行代码时仍然会出现相同的错误。让我们来看看。