我正在尝试从在我的 Mac 上运行我的 Selenium 服务器和客户端迁移到让服务器在 Vagrant VM 中运行,而客户端在我的 Mac 上本地运行。
我正在使用在 Mac OS X 10.9.1 上运行的 Vagrant 1.4.3 来启动 Ubuntu 13.10 VM。启动 VM 后,我会安装 Java、Node.js 和我的测试环境所需的一些其他依赖项。安装 Selenium 2.39.0(撰写本文时的最新版本)后,以下是相关配置。
我通过 SSH 连接到我的 Vagrant VM 并运行以下命令:
java -jar /usr/local/bin/selenium-server-standalone-*.jar \
-role hub \
-trustAllSSLCertificates \
-hubConfig /vagrant/hub.json
/vagrant
VM 上的映射到我本地 Mac 上项目目录的根目录。这是我的相关配置Vagrantfile
。
config.vm.box = "saucy64"
config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/saucy/20140202/saucy-server-cloudimg-amd64-vagrant-disk1.box"
# ...
config.vm.define "testing" do | test |
test.vm.network :forwarded_port, guest: 3444, host: 4444
test.vm.network :private_network, ip: "192.168.50.6"
# ...
end
这是 Selenium Grid Hub 在 Vagrant VM 上使用的集线器配置。Selenium Hub 使用3444
VM 内部的端口,该端口映射到4444
VM 外部,面向我的 Mac。
{
"browserTimeout": 180000,
"capabilityMatcher": "org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
"cleanUpCycle": 2000,
"maxSession": 5,
"newSessionWaitTimeout": -1,
"nodePolling": 2000,
"port": 3444,
"throwOnCapabilityNotPresent": true,
"timeout": 30000
}
这是我在 Mac 上作为节点启动 Selenium 的方法。
java -jar selenium-server-standalone-*.jar \
-role node \
-trustAllSSLCertificates \
-nodeConfig node.mac.json
这是尝试与运行在 Vagrant 中的 Hub 通信的节点配置。
{
"capabilities": [
{
"platform": "MAC",
"seleniumProtocol": "WebDriver",
"browserName": "firefox",
"maxInstances": 1
},
{
"platform": "MAC",
"seleniumProtocol": "WebDriver",
"browserName": "chrome",
"maxInstances": 1
}
],
"configuration": {
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"hubHost": "127.0.0.1",
"hubPort": 4444,
"hub": "http://127.0.0.1:4444/grid/register",
"maxSession": 1,
"port": 4445,
"register": true,
"registerCycle": 2000,
"remoteHost": "http://127.0.0.1:4445",
"role": "node",
"url": "http://127.0.0.1:4445"
}
}
最后,这是我在 Mac 端的终端中得到的。
Feb 02, 2014 9:29:07 PM org.openqa.grid.selenium.GridLauncher main
INFO: Launching a selenium grid node
21:29:18.706 INFO - Java: Oracle Corporation 24.51-b03
21:29:18.706 INFO - OS: Mac OS X 10.9.1 x86_64
21:29:18.713 INFO - v2.39.0, with Core v2.39.0. Built from revision ff23eac
21:29:18.773 INFO - Default driver org.openqa.selenium.ie.InternetExplorerDriver registration is skipped: registration capabilities Capabilities [{platform=WINDOWS, ensureCleanSession=true, browserName=internet explorer, version=}] does not match with current platform: MAC
21:29:18.802 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4445/wd/hub
21:29:18.803 INFO - Version Jetty/5.1.x
21:29:18.804 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
21:29:18.804 INFO - Started HttpContext[/selenium-server,/selenium-server]
21:29:18.804 INFO - Started HttpContext[/,/]
21:29:18.864 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@593aa24f
21:29:18.864 INFO - Started HttpContext[/wd,/wd]
21:29:18.866 INFO - Started SocketListener on 0.0.0.0:4445
21:29:18.867 INFO - Started org.openqa.jetty.jetty.Server@48ef85f3
21:29:18.867 INFO - using the json request : {"class":"org.openqa.grid.common.RegistrationRequest","capabilities":[{"platform":"MAC","seleniumProtocol":"WebDriver","browserName":"firefox","maxInstances":1},{"platform":"MAC","seleniumProtocol":"WebDriver","browserName":"chrome","maxInstances":1},{"platform":"MAC","seleniumProtocol":"WebDriver","browserName":"iphone","maxInstances":1},{"platform":"MAC","seleniumProtocol":"WebDriver","browserName":"ipad","maxInstances":1}],"configuration":{"nodeConfig":"node.mac.json","port":4445,"host":"192.168.50.1","hubHost":"127.0.0.1","registerCycle":2000,"trustAllSSLCertificates":"","hub":"http://127.0.0.1:4444/grid/register","url":"http://127.0.0.1:4445","remoteHost":"http://127.0.0.1:4445","register":true,"proxy":"org.openqa.grid.selenium.proxy.DefaultRemoteProxy","maxSession":1,"role":"node","hubPort":4444}}
21:29:18.868 INFO - Starting auto register thread. Will try to register every 2000 ms.
21:29:18.868 INFO - Registering the node to hub :http://127.0.0.1:4444/grid/register
21:30:25.079 INFO - Registering the node to hub :http://127.0.0.1:4444/grid/register
21:31:31.254 INFO - Registering the node to hub :http://127.0.0.1:4444/grid/register
21:32:35.416 INFO - Registering the node to hub :http://127.0.0.1:4444/grid/register
21:33:41.581 INFO - Registering the node to hub :http://127.0.0.1:4444/grid/register
21:34:47.752 INFO - Registering the node to hub :http://127.0.0.1:4444/grid/register
21:35:51.908 INFO - Registering the node to hub :http://127.0.0.1:4444/grid/register
21:36:56.045 INFO - Registering the node to hub :http://127.0.0.1:4444/grid/register
21:38:00.189 INFO - Registering the node to hub :http://127.0.0.1:4444/grid/register
最后,这是我在 Vagrant VM 端的终端中得到的。
Feb 03, 2014 5:28:53 AM org.openqa.grid.selenium.GridLauncher main
INFO: Launching a selenium grid server
2014-02-03 05:28:54.780:INFO:osjs.Server:jetty-7.x.y-SNAPSHOT
2014-02-03 05:28:54.811:INFO:osjsh.ContextHandler:started o.s.j.s.ServletContextHandler{/,null}
2014-02-03 05:28:54.823:INFO:osjs.AbstractConnector:Started SocketConnector@0.0.0.0:3444
Feb 03, 2014 5:29:20 AM org.openqa.grid.selenium.proxy.DefaultRemoteProxy isAlive
WARNING: Failed to check status of node: Connection refused
Feb 03, 2014 5:29:22 AM org.openqa.grid.selenium.proxy.DefaultRemoteProxy isAlive
WARNING: Failed to check status of node: Connection refused
Feb 03, 2014 5:29:22 AM org.openqa.grid.selenium.proxy.DefaultRemoteProxy onEvent
WARNING: Marking the node as down. Cannot reach the node for 2 tries.
Feb 03, 2014 5:29:24 AM org.openqa.grid.selenium.proxy.DefaultRemoteProxy isAlive
WARNING: Failed to check status of node: Connection refused
Feb 03, 2014 5:29:26 AM org.openqa.grid.selenium.proxy.DefaultRemoteProxy isAlive
WARNING: Failed to check status of node: Connection refused
Feb 03, 2014 5:29:28 AM org.openqa.grid.selenium.proxy.DefaultRemoteProxy isAlive
WARNING: Failed to check status of node: Connection refused
Feb 03, 2014 5:29:30 AM org.openqa.grid.selenium.proxy.DefaultRemoteProxy isAlive
WARNING: Failed to check status of node: Connection refused
Feb 03, 2014 5:29:32 AM org.openqa.grid.selenium.proxy.DefaultRemoteProxy isAlive
WARNING: Failed to check status of node: Connection refused
在这种情况下,Google 不会返回任何有用的信息。谁能帮我确定为什么集线器和节点不能相互通信?