Selenium Grid is used to speed up the execution of a test by using multiple machines to run tests in parallel. It is also used to support running tests against multiple environments, specifically, against different browsers at the same time. You can use Selenium Grid in the following scenarios:
- To run tests against multiple browsers, multiple versions of a browser, and browsers running on different operating systems.
- To reduce the time it takes for a test suite to complete a test pass.
Download and Configurations
Download Selenium Standalone Server, Chrome, Safari, and Firefox drivers, then configure your Mac machine to run a Safari test. The following steps explain the process:
1. Download Selenium Server
Download the Selenium Server jar file from Selenium’s official website, formerly known as Selenium RC Server, and save it to any location on your local disk.
Visit the Selenium HQ download page at http://www.seleniumhq.org/download/
You should see a similar file to selenium-server-standalone-3.141.59.jar in the download folder once the download is completed.
2. Download the Chrome and Firefox driver
- Navigate to the Chrome driver download page and download the chromedriver_mac64.zip file, then extract it.
- Navigate to the Firefox driver download page and download the geckodriver-v0.26.0-macos.tar.gz file and extract it.
- Beginning with Safari 10 on macOS X El Capitan and macOS Sierra, Safari comes bundled with a new driver implementation that’s maintained by the Web Developer Experience team at Apple. Safari’s driver is launchable via the
3. Configure Chrome, Firefox, and Safari drivers for automation
- After downloading and extracting the Chrome driver, you need to move it to the
binfolder to run the Chrome and Firefox test
Choose your method from the following two options:
From a command-line interface, navigate to the folders where you've extracted the Chrome and Gecko driver and run the following commands:
mv geckodriver /usr/local/bin
From the user interface, open a new Finder window:
4. Configurations for Safari
- Ensure that the Develop menu is available. It can be turned on by opening Safari Preferences in the menu bar, Safari > Preferences > Advanced tab, and confirm that the Show Develop menu in menu bar checkbox is checked.
- Enable Remote Automation in the Develop menu. This is toggled via Develop > Allow Remote Automation in the menu bar.
safaridriverto launch the
webdriverdservice which hosts the local webserver. To permit this, run
/usr/bin/safaridriveronce manually and complete the authentication prompt.
safaridriver /usr/bin/safaridriver --enable
- Enter the password and you're done.
Running Selenium Hub and Node on Macs
The hub is the central server that manages nodes, takes instructions from the client and executes them remotely on the nodes, then manages test threads. Each Selenium Grid consists of one hub. The hub needs to be reachable from respective clients, for example, the CI server, developer machine, etc. The hub will connect to one or more nodes that tests will be delegated to.
Nodes are Selenium instances that will execute tests on individual computer systems. There can be many nodes in a grid. A node on a Windows machine may have the capability of offering Internet Explorer as a browser option, whereas this wouldn't be possible on a Linux or Mac.
How to setup HUB:
To ease the configuration, download the attached SeleniumGrid.zip file, which contains all the required files, and extract the SeleniumGrid folder. Then copy the extracted Grid Setup folder to your Desktop.
Ensure that you have downloaded the compatible drivers and correct Selenium Grid version to perform the setup procedures as previously listed.
Note: Copy the compatible grid version to the SeleniumGrid folder and rename it to selenium-server-standalone.jar
Now, open Terminal and run the following command:
chmod u+x ~/Desktop/Selenium Grid/gridSetup.command
This will allow you to run the grid through the gridSetup.command script.
Double-clicking on the gridSetup.command script should open two command windows and run both the Selenium Hub and Node on your Mac machine.
Visit the How to setup Selenium Grid? article for information about Hub and Node configuration files and the execution process.