Why do we need Grids?
If we want to run our tests against multiple browsers with different versions and if the browsers are running on different operating systems, then Grids is the right solution.
What is Grid actually?
Grid Concept is used to run multiple tests simultaneously in different browsers with different OS environments, and it originated from Selenium Automation Tool, but now we can implement the Grid Concepts using Cucumber Automation Tool by simply integrating it with selenium jar file.
The jar file can be downloaded from the below website:
The Grids can be configured by setting up an Environment file in Cucumber, and we can specify all the information in env.rb file stored inside Support Folder
Grid uses the Hub – Node concepts in which the Hub is the centralized location where we load our test scenarios. Nodes are instances that are connected to the Hub which will execute the test scenarios that we loaded on the Hub.
For more details: Cucumber-driven Selenium Grid Testing
Benefits of implementing Grid in Cucumber:
- Running our tests in Grids will give more flexibility to distribute the test cases among node machines.
- It will reduce the batch process time.
- Selenium or Cucumber tools need not to be installed on node machines.
Implementing Grid in Cucumber:
- For implementing the Grid in Cucumber, first install Cucumber on the Hub machine (Node machines need not install Cucumber/Selenium)
- Then, we have to download the selenium jar file. It can be downloaded from Selenium websitehttp://docs.seleniumhq.org/download/
- Finally, keep the downloaded .jar file in any of the local drive (C or D or E drive) on Hub and Node machines on which we are going to execute the scripts.
Now, the devices can be configured with Hub-Node relationship.
Configuring Hub Machine:
- Open the command prompt on the hub machine and set the path where the jar file placed, and then enter the following command
D:\java -jar selenium-server-standalone-2.43.1.jar -role hub
Please refer the below Image-a:
Image-a Hub-configuration
- We can check whether the Hub is configured properly or not by entering the below url on the browser http://localhost/grid/console
Please refer the below Image-b
Image-b Hub-Verification
Configuring the Node Machine:
- Open the command prompt on the node machine, set the path where the Selenium jar file placed, and then enter the following command
D:/ java -jar selenium-server-standalone-2.43.1.jar -role webdriver -hub http://
100.00.00.7:4444/grid/register -port 5566
Please refer the below Image-c
Image-c Node-Configuration
- We can check whether the Node is configured properly or not by entering the below url on the browser http://localhost/grid/console
Please refer the below Image-d
Image-d Node-Verification
By following this Node Configuration, we can connect multiple Node machines with Hub
Writing the test scripts that runs on the Grid:
In Cucumber, first we have to set up an environment file (env.rb) which allows the Grid execution inside the Support Folder
The Folder structure as follows:
Environment File:
require 'capybara' require 'capybara/cucumber' require 'rspec' require 'selenium/webdriver' caps = Selenium::WebDriver::Remote::Capabilities.firefox caps.version = "8.1" caps.platform = "WINDOWS" Capybara.default_driver = :selenium Capybara.register_driver :selenium do |app| Capybara::Selenium::Driver.new(app, :browser => :remote, :url => "http://100.00.00.5:5555/wd/hub", :desired_capabilities => caps) end
Note: We can specify the browser name in this env.rb file
Step Definition File:
Given /^I am on (.+)$/ do |url| visit "http://www.youtube.com" page.driver.browser.save_screenshot("E:/#{url}.png") end When /^I fill in "([^"]*)" with "([^"]*)"$/ do |field, value| fill_in(field, :with => value) page.driver.browser.save_screenshot("E:/#{field}.png") end When /^I press "([^"]*)"$/ do |button| click_button(button) page.driver.browser.save_screenshot("E:/#{button}.png") end Then /^I should see "([^"]*)"$/ do |text| #page.should have_content(text) end
Feature File:
Feature: YouTube has a search function.
Background:
Given I am on YouTube
Scenario: Search for a term
When I fill in “search_query” with “text adventure”
And I press “search-btn”
Then I should see “GET LAMP: The Text Adventure Documentary”
Execute the scripts on the Hub machine. The results will be shown on the node machines.
Note: The test scripts are executed on the node machines successfully even the node machines have not installed selenium/cucumber.
Below are the screenshots of the results (Result-1, Result-2, and Result-3) that are executed on the node machines.