Ryan Parman
Ryan Parman

Reputation: 6945

Running Selenium Grid through Vagrant

I'm trying to migrate from running my Selenium server and client from all on my Mac, to having the servers run in a Vagrant VM, and the clients run locally on my Mac.

I'm using Vagrant 1.4.3 running on Mac OS X 10.9.1 to launch an Ubuntu 13.10 VM. Once the VM is launched, I install Java, Node.js and a few other dependencies that are required for my testing environment. After installing Selenium 2.39.0 (the latest as of this writing), here are the relevant configurations.


I SSH into my Vagrant VM and run the following:

java -jar /usr/local/bin/selenium-server-standalone-*.jar \
    -role hub \
    -trustAllSSLCertificates \
    -hubConfig /vagrant/hub.json

/vagrant on the VM maps to the root of my project directory on my local Mac. Here's the relevant config from my 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

Here is the Hub config that the Selenium Grid Hub is using on the Vagrant VM. Selenium Hub uses port 3444 inside the VM, which is portmapped to 4444 outside the VM, facing my Mac.

{
    "browserTimeout": 180000,
    "capabilityMatcher": "org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
    "cleanUpCycle": 2000,
    "maxSession": 5,
    "newSessionWaitTimeout": -1,
    "nodePolling": 2000,
    "port": 3444,
    "throwOnCapabilityNotPresent": true,
    "timeout": 30000
}

Here's how I launch Selenium on my Mac as a node.

java -jar selenium-server-standalone-*.jar \
    -role node \
    -trustAllSSLCertificates \
    -nodeConfig node.mac.json

And here's the node config which tries to talk to the Hub running inside Vagrant.

{
    "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"
    }
}

Lastly, here's what I get in the Terminal on the Mac side.

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

Lastly, here's what I get in the Terminal on the Vagrant VM side.

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 [email protected]: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 returns nothing of usefulness in this situation. Can anybody help me determine why the Hub and the Node can't talk to each other?

Upvotes: 2

Views: 3016

Answers (3)

adbarads
adbarads

Reputation: 1303

The first answer was partially correct. You do have to ensure communication path between the node and the server and the server to the node is clear and able to connect on the specific ports. Since technically you are running 2 servers a server on the node listening on 1 port and a server on the hub listening to another port.

Try this: I had the same problem, but fixed it by adding the host field:

"host": [ip or hostname of node],

Here is my node config file:

{
    "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"
    }
}

Upvotes: 0

TestGal
TestGal

Reputation: 11

I have a similar setup where my selenium server (aka hub) is on a remote vm and a client (aka node) is on my local machine. I've been seeing the same error:

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.

I talked to our Ops team and they told me that my vm is sitting on a different network and in different location. And even though the node machine is able to reach the hub but the hub can never reach the node. They suggested to get another VM that is sitting on the same network. It's like one way street. Hope it helps.

Upvotes: 1

tmatilai
tmatilai

Reputation: 4176

I don't know too much about Selenium, but I guess the issue is about using 127.0.0.1. Especially the VM has no way to connect to the host, and you don't forward port 4445.

As you already specify a private_network address (192.168.50.6), you could try to use it directly without any port forwarding.

Upvotes: 0

Related Questions