Discover the Power of Selenium Grid: Unleash the Full Potential of Your Automation Testing!
Selenium is a browser automation library with bindings for the most common programming languages, and is primarily used for testing web applications. However, it can also be used to automate any web browser task. Unlike tools such as Nightmare.js, Selenium is capable of running tasks or tests on any version of any major browser, though this may make it more difficult to set up. Nevertheless, it allows for testing to be conducted on the exact platforms that users will be using, making it a more reliable tool.
For many applications, the Selenium standalone server is sufficient; however, Selenium can also be configured as a grid, with multiple nodes communicating with a central hub, both on the same computer or server and on separate Linodes. Selenium Grid offers two main benefits: increased scalability and improved performance. Consequently, it is an ideal solution for running multiple tests simultaneously, as well as for reducing the execution time of individual tests.
- Selenium, being compatible with all major operating systems, makes it possible to set up a grid consisting of servers (or virtual machines) running Linux, OSX, and Windows. This allows for a test suite to be run against the grid, with each test being executed on multiple browsers and operating systems. The hub will then delegate each test to a node that has the requested capability, thus enabling tests to be run on Safari on an OSX machine, for example. Consequently, Selenium’s ability to run on Java and its compatibility with multiple operating systems makes it a powerful tool for automated testing.
- For larger projects, running a lengthy test suite in series can quickly become time consuming. However, by running the test suite across a grid consisting of multiple servers, it is possible to distribute the tests across multiple nodes and significantly accelerate the testing process; thus, providing an efficient and cost-effective solution.
This guide provides a step-by-step tutorial on how to set up a basic Selenium grid consisting of a hub and two nodes on separate Linodes, as well as demonstrate running tests against different versions of Firefox. Firstly, the Selenium grid will be set up, then a simple test script will be used to show how to run tests on the grid. Finally, the results will be verified to ensure everything is working correctly. By following the steps outlined in this guide, users will be able to quickly and easily get their Selenium grid up and running and test their applications against different versions of Firefox.
Build Your Infrastructure in Seconds with Grid Linodes!
To create a Selenium Grid, install Java and other dependencies on each Linode that will be part of the grid. This guide utilizes three Linodes for this task, but if one prefers, it can also be run from a single Linode. For the purpose of this guide, the three Linodes will be referred to as hub, node-1, and node-2, respectively.
Unlock the Potential of Your Computer – Install Java Now!
Install Java 8 JDK on Ubuntu 16.04 – Step-by-Step Guide!
- Unlock Unlimited Possibilities with Easy Repository Installation: Installing software-properties-common!
sudo apt-get install software-properties-common
- Unlock the Power of Java: Add the Java PPA Today!
sudo add-apt-repository ppa:webupd8team/java
- Stay Up-to-Date with the Latest Source List: Get the Updates You Need Now!
sudo apt-get update
- Unlock the Power of Java 8: Download the Java JDK 8 Now!
sudo apt-get install oracle-java8-installer
Unlock the Power of Your Projects with Dependency Installation!
When running tests with Selenium, it is important to remember that each grid node can only execute tests on browsers that have been installed on that node. Additionally, each browser requires a separate executable webdriver. As an example, install Geckodriver and different versions of Firefox on node-1 and node-2 respectively; this will ensure proper functioning and testing of the Selenium grid.
- Maximize Test Efficiency with Selenium Grid: How to Install Geckodriver and Different Versions of Firefox on Node-1 and Node-2
wget https://github.com/mozilla/geckodriver/releases/download/v0.19.1/geckodriver-v0.19.1-linux64.tar.gz
- Unlock Your Full Potential with Easy Archive Extraction & Executable Path Setup!
tar -xvf geckodriver-v0.19.1-linux64.tar.gz
sudo mv geckodriver /usr/local/bin/
- Install Firefox on Node-1 – Get the Latest and Most Stable Version Now!
sudo apt install firefox
- Unlock New Features and Enhance Your Development Process with Firefox Developer Edition on Node-2!
sudo add-apt-repository ppa:ubuntu-mozilla-daily/firefox-aurora
sudo apt update && sudo apt install firefox
- Ensure Quality Testing with Version Tracking: Check and Record the Appropriate Version Numbers!
node-1:
firefox --version
Mozilla Firefox 58.0.2
node-2:
firefox --version
Mozilla Firefox 59.0
Experience Automation Like Never Before: Download Selenium Now!
Selenium provides a single .jar file that can be used to run a standalone server, hub, or node. This file can be easily obtained from the Selenium downloads page, where the latest release can be located. To download the file to each Linode, simply use the wget command. Consequently, this ensures that all necessary components are quickly and reliably obtained, thereby streamlining the process.
wget http://selenium-release.storage.googleapis.com/3.10/selenium-server-standalone-3.10.0.jar
Unlock Limitless Possibilities with the Launch of Start Grid Hub!
- Start the Hub on Linode with One Simple Command – Set Your Selenium Server to Hub!
java -jar selenium-server-standalone-3.10.0.jar -role hub
- Get Ready For Node Registration & Hub Connection – Copy These URLs Now!
21:27:51.470 INFO [GridLauncherV3.launch] - Selenium build info: version: '3.10.0', revision: '176b4a9' 21:27:51.475 INFO [GridLauncherV3$2.launch] - Launching Selenium Grid hub on port 4444 2018-03-06 21:27:52.248:INFO::main: Logging initialized @1166ms to org.seleniumhq.jetty9.util.log.StdErrLog 21:27:52.446 INFO [Hub.start] - Selenium Grid hub is up and running 21:27:52.447 INFO [Hub.start] - Nodes should register to http://69.164.211.42:4444/grid/register/ 21:27:52.448 INFO [Hub.start] - Clients should connect to http://69.164.211.42:4444/wd/hub
Unlock Unprecedented Performance – Configure Grid Nodes for Maximum Efficiency!
On both node-1 and node-2, create a node configuration file named config.json and add the content mentioned in the prompt; specifically, replace the hub address with the public IP of the Linode, and replace the version with the version of Firefox installed on those nodes. If the grid and nodes are on the same Linode, replace the IP address with http://localhost:4444.
File: config.json
{
"capabilities":
[
{
"browserName": "firefox",
"marionette": true,
"maxInstances": 5,
"seleniumProtocol": "WebDriver",
"version": "58.0.2"
}
],
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 5,
"port": 5555,
"register": true,
"registerCycle": 5000,
"hub": "http://192.0.2.0:4444",
"nodeStatusCheckTimeout": 5000,
"nodePolling": 5000,
"role": "node",
"unregisterIfStillDownAfter": 60000,
"downPollingLimit": 2,
"debug": false,
"servlets" : [],
"withoutServlets": [],
"custom": {}
}
- Unlock New Possibilities with Network Connectivity: Connect Every Node to the Hub!
java -jar selenium-server-standalone-3.10.0.jar -role node -nodeConfig config.json
- Success! Your Nodes Have Been Registered to the Hub – See the Output Here!
21:33:22.856 INFO - Selenium Server is up and running on port 5555 21:33:22.857 INFO - Selenium Grid node is up and ready to register to the hub 21:33:22.895 INFO - Starting auto registration thread. Will try to register every 5000 ms. 21:33:22.896 INFO - Registering the node to the hub: http://69.164.211.42:4444/grid/register 21:33:23.064 INFO - Updating the node configuration from the hub 21:33:23.178 INFO - The node is registered to the hub and ready to use
Transform Your Ideas Into Reality – Unlock the Power of Your Mind with Hubs!
21:27:53.849 INFO [DefaultGridRegistry.add] - Registered a node http://198.58.122.154:5555 21:27:56.445 WARN [BaseRemoteProxy.<init>] - Max instance not specified. Using default = 1 instance 21:27:56.450 INFO [DefaultGridRegistry.add] - Registered a node http://50.116.22.93:5555 21:27:56.743 WARN [BaseRemoteProxy.<init>] - Max instance not specified. Using default = 1 instance
- Discover Your Nodes Instantly: Navigate to http://192.0.2.0:4444/grid/console with Your Public IP Address!
Ensure Maximum Compatibility Across Your Network: Configure Each Node with a Different Version of Firefox!
Unlock Your Local Development Potential: Create Your Own Test Environment Now!
In this example, the test script will be run both locally, from your development machine, and remotely, from a separate Linode if necessary. Connecting to the remote grid, it will execute the tests from there, thus allowing you to use either your local machine or a separate Linode, depending on availability.
Launch Your Web Development Journey – Install Node.js and NPM Now!
This guide uses the NPM selenium-webdriver package, which contains Node.js bindings for Selenium; specifically, it provides convenient access to Selenium’s capabilities for automation and testing purposes.
- Install the Latest Version of Node with Ease – Use Curl to Download the NodeSource Setup Script!
curl -sL https://deb.nodesource.com/setup_9.x -o nodesource_setup.sh
- Unlock the Potential of Your Code – Run the Script Now!
sudo bash nodesource_setup.sh
- Eliminate the Hassle of Manual Updates – Instantly Install Node.js with No Extra Work!
sudo apt install nodejs npm
Introducing: Node.js and NPM Now Installed Together!
Write the Perfect Test Script: A Step-by-Step Guide to Creating an Example Test Script
- Organize Your Tests for Maximum Efficiency: Create a Directory for Your Test Suite!
mkdir test-selenium && cd test-selenium
- Jumpstart Your Node.js App with this Simple Initialization Guide!
npm init
Stop Wasting Time – Follow the Prompts for Fast and Easy Default Values!
- Elevate Your Development Process: Learn How to Easily Install NPM Packages!
npm install --save selenium-webdriver
- Unlock the Power of Automation: Create test.js and Replace IP Address on Line 11 to Connect to Hub!
File: ~/test-selenium/test.js
const {Builder, By, Capabilities, Key, until} = require('selenium-webdriver');
let firefox = require('selenium-webdriver/firefox');
const VERSIONS = ['58.0.2','59.0'];
function buildDrivers(versions) {
let drivers = [];
for (let version of versions) {
driver = new Builder().forBrowser('firefox')
.withCapabilities(Capabilities.firefox().setBrowserVersion(version))
.usingServer('http://192.0.2.0:4444/wd/hub')
.setFirefoxOptions(
new firefox.Options().headless())
.build();
drivers.push(driver);
}
console.log('built drivers for ' + versions);
return drivers;
}
async function example(driver) {
try {
await driver.get('http://www.linode.com/docs');
await driver.findElement(By.name('q')).sendKeys('nginx', Key.RETURN);
let el = driver.findElement(By.linkText('How to Configure nginx'));
await driver.wait(until.elementIsVisible(el), 1000);
await el.click();
title = await driver.getTitle();
} finally {
await driver.quit();
}
};
async function main() {
const drivers = await buildDrivers(VERSIONS);
for (let driver of drivers) {
example(driver);
};
}
main();
- Run Your Test Scripts Now and Save Time – The Easier Way!
node test.js
If successful, the script will search for NGINX in the Linode docs library, and upon finding matches, visit one of the results page and check that the page title matches the link text; furthermore, it will print out the page title.
built drivers for 58.0.2,59.0 How to Configure nginx How to Configure nginx
- Testing Across Two Versions of Firefox Seamlessly: How test.js Runs the Driver Asynchronously Across Two Nodes!
By creating different drivers for each combination of platform, browser, and version that you want to test, you can easily specify which node or nodes should be used to run each test. Moreover, if more than one node has the requested capabilities, Selenium will select one of them randomly. Consequently, it is possible to execute a large, cross-browser test suite much faster than running the tests one at a time, thereby saving time and effort.
Unlock the Power of More Information: Discover the Benefits Today!
While the provided resources may be useful for additional information on this topic, it is important to note that their accuracy and timeliness cannot be vouched for. Therefore, caution should be exercised when relying on these sources.