无法使用Selenium Grid访问虚拟机上的节点

3

我在物理机器(Windows 10,RAM 16Gb,x64)上启动了一个hub
java -jar selenium-server-standalone-2.53.0.jar -role hub port 4444

同时,我在虚拟机上注册了一个node(我使用VirtualBox:Linux,Ubuntu 16.04.2;i386。基础内存:2048 Mb):
java -jar selenium-server-standalone-2.53.0.jar -role webdriver port 9999 -hub http://172.xx.xxx.248:4444/grid/register

节点可以从网格控制台看到,但是连接失败 Grid console 无法运行测试。

IDE配置:
WebDriver driver = new RemoteWebDriver(new URL("http://10.0.2.15:9999/wd/hub"), capabilities);

运行测试时出现错误: 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. Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 10.0.2.15:9999 [/10.0.2.15] failed: Connection timed out: connect

物理机地址:172.xx.xxx.248
虚拟机地址:10.0.2.15


你能手动登录虚拟机并启动浏览器吗? - Bryan Oakley
是的,我可以在虚拟Linux机器的 /usr/bin 目录中手动启动Firefox。 - Nataliya
2个回答

4
我找到了一个解决方案。VM(在我的情况下是VirtualBox)应该按照以下方式配置:

进入设置 -> 网络
1. 附加到 应该是 '桥接适配器'
2. 展开 '高级' -> 混杂模式 应该是 '允许全部'enter image description here


0

您正在使用错误的URL启动RemoteWebDriver,应该将其提供给hub IP进行注册,而不是node IP。

WebDriver driver = new RemoteWebDriver(new URL("http://172.xx.xxx.248:4444/wd/hub"), capabilities);

这应该可以解决你的问题。


不幸的是,它没有帮助。我收到同样的异常org.openqa.selenium.remote.UnreachableBrowserException:无法启动新会话。可能的原因是远程服务器的地址无效或浏览器启动失败.... 原因是:org.apache.http.conn.HttpHostConnectException:连接到172.xx.xxx.248:9998 [/ 172.xx.xxx.248] 失败:连接被拒绝:connect - Nataliya
你使用的是哪个版本的Firefox? - acikojevic
虚拟机上的Firefox版本-47.0 - Nataliya
也许,原因是我使用的VM网络是NAT。当我改为桥接适配器时,异常也变成了:org.openqa.selenium.SessionNotCreatedException: Unable to bind to locking port 7054 within 45000 ms - Nataliya

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接