网格无法连接到节点

时间:2018-05-21 11:51:58

标签: selenium selenium-webdriver selenium-grid

当我运行我的selenium代码时,我得到以下错误。有人可以帮我解决这个问题:

Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 129.633 sec <<< FAILURE!
GoogleTest(gridtest.GridTest)  Time elapsed: 128.291 sec  <<< FAILURE!
org.openqa.selenium.remote.UnreachableBrowserException: **Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.**
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T15:28:36.4Z'
System info: host: 'XXXXXX', ip: 'XXXXXX', os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.32-696.23.1.el6.x86_64', java.version: '1.8.0_77'
Driver info: driver.version: RemoteWebDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:607)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:217)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:140)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:153)
    at gridtest.GridTest.GoogleTest(GridTest.java:48)
**Caused by: org.apache.http.conn.ConnectTimeoutException: Connect to xxx.xxx.xxx.xxx:4444 [xxx.xxx.xxx.xxx/yyy.yyy.yyy.yyy, xxx.xxx.xxx.xxx/yyy.yyy.yyy.yyy] failed: Connection timed out**
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:157)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359)
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
    at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:138)
    at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:86)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:337)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:136)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:586)
    ... 38 more
Caused by: java.net.ConnectException: Connection timed out
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75)
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
    ... 53 more

以下是我的网格和节点配置。

我的Jenkins安装了Selenium插件。所以我的集线器在我的Jenkins机器上启动并运行。

主持人:xxx.xxx.xxx.xxx 港口:4444

现在从我的Node机器启动selenium服务器独立,角色为节点并注册了发髻

C:\Temp>java -jar selenium-server-standalone-3.12.0.jar -role node -hub http://xxx.xxx.xxx.xxx:4444/grid/register -port 17946

节点启动后,我可以在节点控制台中看到该节点已注册到Grid。 而且在Jenkins Selenium Grid中,我可以看到已注册的远程组件中连接的节点。

在Selenium Grid配置中,我还使用chrome配置了上述端口,并在节点匹配配置中启动了节点。

以下是我的简单代码:

System.out.println("I am in test");

        DesiredCapabilities capabilities = DesiredCapabilities.firefox();

        // say you use the redhat5 label to indicate RHEL5 and the amd64 label to specify the architecture
        //capabilities.setCapability("jenkins.label","RHEL6");
        //capabilities.setCapability("jenkins.label","redhat5 && amd64");
        // Say you want a specific node to thread your request, just specify the node name (it must be running a selenium configuration though)
        //capabilities.setCapability("jenkins.nodeName","(master)");

        //capabilities.setPlatform(Platform.WINDOWS); 
        //System.setProperty("webdriver.chrome.driver", "Drivers"+File.separator+"chromedriver.exe");
        //System.setProperty("webdriver.chrome.driver", "C:\\chromedriver\\chromedriver.exe");


        System.out.println("I am after setting chromedriver path ");

        remoteWD = new RemoteWebDriver(new URL("http://xxx.xxx.xxx.xxx:4444/wd/hub"), capabilities); 
        //remoteWD = new ChromeDriver(); 

        System.out.println("I am after RMD");

        remoteWD.get("http://www.google.com"); 
        WebElement element = remoteWD.findElement(By.name("q"));
        element.sendKeys("Selenium WebDriver"); 
        element.submit();
        Thread.sleep(10000);
        System.out.println(remoteWD.getTitle());
        remoteWD.quit();

1 个答案:

答案 0 :(得分:0)

超时问题是使用remoteWebDriver,默认为60秒。

以下是它的正确设置(我的示例是在C#中,但在Java中它应该是相同的:

var timeout = TimeSpan.FromHours(1);
var driver = new RemoteWebDriver(new Uri(node), new BrowserFactory().Create().ToCapabilities(), timeout);

我从本文中记录的完整解决方案中获取了它: https://www.tikalk.com/posts/2018/05/02/establishment-of-a-docker-and-chrome-based-selenium-grid-for-web-application-tests/