2

我正在尝试从在我的 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

/vagrantVM 上的映射到我本地 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 使用3444VM 内部的端口,该端口映射到4444VM 外部,面向我的 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 不会返回任何有用的信息。谁能帮我确定为什么集线器和节点不能相互通信?

4

3 回答 3

1

我有一个类似的设置,我的 selenium 服务器(又名集线器)在远程 vm 上,客户端(又名节点)在我的本地机器上。我一直看到同样的错误:

Feb 04, 2014 5:29:22 PM org.openqa.grid.selenium.proxy.DefaultRemoteProxy isAlive
WARNING: Failed to check status of node: Connection refused
Feb 04, 2014 5:29:22 PM org.openqa.grid.selenium.proxy.DefaultRemoteProxy onEvent
WARNING: Marking the node as down. Cannot reach the node for 2 tries.

我与我们的运维团队交谈,他们告诉我我的虚拟机位于不同的网络和不同的位置。即使节点机器能够到达集线器,但集线器永远无法到达节点。他们建议获取另一个位于同一网络上的虚拟机。这就像一条路。希望能帮助到你。

于 2014-02-04T23:47:46.340 回答
0

我对 Selenium 不太了解,但我想问题在于使用 127.0.0.1。尤其是VM没有办法连接到主机,你也不转发4445端口。

由于您已经指定了private_network地址 (192.168.50.6),因此您可以尝试直接使用它而无需任何端口转发。

于 2014-02-03T14:15:20.740 回答
0

第一个答案是部分正确的。您必须确保节点和服务器之间的通信路径以及服务器到节点的通信路径清晰并且能够在特定端口上连接。由于从技术上讲,您正在运行 2 台服务器,节点上的服务器侦听 1 个端口,集线器上的服务器侦听另一个端口。

试试这个:我有同样的问题,但通过添加主机字段来解决它:

"host": [ip 或节点的主机名],

这是我的节点配置文件:

{
    "capabilities":[
        {
            "platform":"MAC",
            "browserName":"firefox",
            "version":"28",
            "maxInstances":1
        },
        {
            "platform":"MAC",
            "browserName":"chrome",
            "version":"34",
            "maxInstances":1
        }
    ],
    "configuration":{
        "port": 5556,
        "hubPort": 5555,
        "host": 10.50.10.101, //this is the ip of my node
        "hubHost":"10.50.10.100", //this is ip of my grid hub
        "nodePolling":2500,
        "registerCycle":10500,
        "register":true,
        "cleanUpCycle":2500,
        "maxSession":5,
        "role":"node"
    }
}
于 2014-04-23T20:14:27.770 回答