我在物理机(Windows 10,RAM 16Gb,x64)上启动了一个 hub:
java -jar selenium-server-standalone-2.53.0.jar -role hub port 4444
我还在虚拟机上注册了一个节点(我使用VirtualBox:Linux,Ubuntu 16.04.2;i386。基本内存:2048 Mb):
java -jar selenium-server-standalone-2.53.0.jar -role webdriver port 9999 -hub <a href="http://172.xx.xxx.248:4444/grid/register" rel="noreferrer noopener nofollow">http://172.xx.xxx.248:4444/grid/register</a>
IDE 中的配置:
WebDriver driver = new RemoteWebDriver(new URL("<a href="http://10.0.2.15:9999/wd/hub" rel="noreferrer noopener nofollow">http://10.0.2.15:9999/wd/hub</a>"), 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
最佳答案
我找到了一个解决方案。 VM(在我的例子中是 VirtualBox)应该按以下方式配置:
进入设置 -> 网络
1. Attached to 应该是'Bridged Adapter'
2. 展开'Advanced' -> Promiscuous mode 应该是'Allow All'
关于selenium - 无法使用 Selenium Grid 访问虚拟机上的节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43610397/