Selenium Grid on Mac OS

Selenium grid on mac article describes how to install the selenium grid on your MAC. I will also share a very basic test code to test the selenium grid on your MAC operating system. Let’s start!

What is Selenium Grid?

Selenium Grid allows you to:

  • Scale by distributing tests on several machines ( parallel execution )
  • Manage multiple environments from a central point, making it easy to run the tests against a vast combination of browsers / OS.
  • Minimize the maintenance time for the grid by allowing you to implement custom hooks to leverage virtual infrastructure for instance.

Now, please go to http://www.seleniumhq.org/download/ and download Selenium Standalone Server. Selenium team constantly updating the versions. You may see a different version, pls do not panic, just download it. ;)

selenium-grid-on-mac

Then, create a seleniumgrid folder under Documents and copy the .jar file under the Documents > seleniumgrid folder as you see below.

selenium-grid-on-mac

What are Hub and Nodes?

Basically, we have a Hub which is a server that we connect from our tests and we have Nodes, they can be on different machines and they register with the hub. Simply, we have a hub and several nodes, nodes are registered our hub and hub knows that which browsers are available. Hub sends requests to the nodes based on desired capabilities and executes the tests.

How to Start and Configure Hub and Nodes on MAC

First, download the hub and node config files from below addresses.

Hub Config:

{
  "port": 4444,
  "newSessionWaitTimeout": -1,
  "servlets" : [],
  "withoutServlets": [],
  "custom": {},
  "capabilityMatcher": "org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
  "registry": "org.openqa.grid.internal.DefaultGridRegistry",
  "throwOnCapabilityNotPresent": true,
  "cleanUpCycle": 5000,
  "role": "hub",
  "debug": false,
  "browserTimeout": 0,
  "timeout": 1800
}

Node Config: 

{
  "capabilities":
  [
    {
      "browserName": "firefox",
      "marionette": true,
      "maxInstances": 5,
      "seleniumProtocol": "WebDriver"
    },
    {
      "browserName": "chrome",
      "maxInstances": 5,
      "seleniumProtocol": "WebDriver"
    },
    {
      "browserName": "internet explorer",
      "platform": "WINDOWS",
      "maxInstances": 1,
      "seleniumProtocol": "WebDriver"
    },
    {
      "browserName": "safari",
      "technologyPreview": false,
      "platform": "MAC",
      "maxInstances": 1,
      "seleniumProtocol": "WebDriver"
    }
  ],
  "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
  "maxSession": 5,
  "port": -1,
  "register": true,
  "registerCycle": 5000,
  "hub": "http://localhost:4444",
  "nodeStatusCheckTimeout": 5000,
  "nodePolling": 5000,
  "role": "node",
  "unregisterIfStillDownAfter": 60000,
  "downPollingLimit": 2,
  "debug": false,
  "servlets" : [],
  "withoutServlets": [],
  "custom": {}
}

Save them as hub.json and node.json under seleniumgrid folder.

How to start Selenium Grid on MAC?

Then save below script as startgrid.command this script automatically starts node and hub.

But before you need to install a chrome driver on your MAC. For this, please check this article.

#! /bin/bash
osascript -e 'tell app "Terminal"
    do script "cd Documents/seleniumgrid/ && 
    java -jar selenium-server-standalone.jar -role hub -hubConfig hub.json"
end tell'
osascript -e 'tell app "Terminal"
    do script "cd Documents/seleniumgrid/ && 
    java -jar -Dwebdriver.chrome.driver=/usr/local/bin/chromedriver selenium-server-standalone.jar -role node -nodeConfig node.json"
end tell'

Note: If you also download and move the firefox driver (geckodriver) to the /usr/local/bin folder, you can use below script. It registers both Firefox and Chrome drivers.

#! /bin/bash
osascript -e 'tell app "Terminal"
    do script "cd Documents/seleniumgrid/ && 
    java -jar selenium-server-standalone.jar -role hub -hubConfig hub.json"
end tell'
osascript -e 'tell app "Terminal"
    do script "cd Documents/seleniumgrid/ && 
    java -jar -Dwebdriver.gecko.driver=/usr/local/bin/geckodriver -Dwebdriver.chrome.driver=/usr/local/bin/chromedriver selenium-server-standalone.jar -role node -nodeConfig node.json"
end tell'

Then when you run below script both hub and node will be run.

./startgrid.command

selenium-grid-on-mac

Now, we can check the selenium grid is working on MAC. In order to do that, open a chrome browser and go to this link: http://localhost:4444/grid/console

You should see the below window which means grid works properly.

selenium-grid-on-mac

When you run below project it will run and it will use one of the chrome browsers of the grid.

GitHub Project for Basic Selenium Grid Test: https://github.com/swtestacademy/basicseleniumgridproject

Thanks.
Onur Baskirt

13 thoughts on “Selenium Grid on Mac OS”

  1. Hi. When I try to run the script to run the Hub and Node, I get permission denied.
    -bash: ./startgrid.command: Permission denied

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.