Skip to main content

Selenium Grid - Distributed Systems

Selenium grid is powerful and can be easily used with just few lines of code.

A Grid is a network of computers which can be heterogeneous and geographically dispersed.
A Selenium Grid is how a grid of computers are connected using Selenium and configured to perform a task.

A task typically here is running a suite of test cases with different browsers in different platforms across geographically dispersed systems. The test cases can be run in parallel using Selenium.
So if we have a grid of three computers the same set of test cases can be run in IE, Firefox and Chrome.

To establish this we have three important components.
1) Hub
2) Node
3) Test Script

A Hub acts like the server to which requests are sent. The Hub sends to request to various registered nodes. The HUB can be instantiated using command line by using the selenium server standalone jar file.

Open command prompt, navigate to the folder which has the selenium server file and use this command.

java -jar selenium-server-standalone-2.14.0.jar -role hub

-role is the parameter to set the role the program plays. In Java, when executing commands through command line parameters are passed with "-" in front of it. -browsername,-platform are other parameters.

The hub will start using default port 4444. You have a console to view the status of the hub, the connected nodes etc. The console can be accessed using http://localhost:4444/grid/console

A Node registers itself to the hub to provide services. A Node and a hub can exist in the same local system.
Start the node in the command prompt by using the command

java -jar selenium-server-standalone-2.14.0.jar -role node -hub http://localhost:4444/hub/register

Using this command we register our node with the hub that we started. If the hub and node are not in the same system, you can use the IP Address in place of the localhost

java -jar selenium-server-standalone-2.14.0.jar -role node -hub http://192.14.54.134:4444/hub/register

The node will start using default port 5555.
The nodes are configured by default to provide 5 firefox, 5 chrome and 1 IE instances. This can be modified using command line settings.
This can be done using command prompt. You can decide what services your node should provide by setting the platform, browsername and version

java -jar selenium-server-standalone-2.14.0.jar -role node -hub http://192.14.54.134:4444/hub/register -browser browserName=firefox,version=3.6,maxInstances=5,platform=LINUX

You can specify more than one browser switch using -browser. 

Test Script is the program which should use this capability. As discussed in earlier chapters you need to use RemoteWebDriver and DesiredCapabilities to use grid feature.

DesiredCapabilities capability = DesiredCapabilities.firefox();
capability.setBrowserName("firefox");
capability.setPlatform("WINDOWS");
capability.setVersion("3.6")
KeyTypeDescription
browserNamestringThe name of the browser being used; should be one of {android|chrome|firefox|htmlunit|internet explorer|iPhone|iPad|opera|safari}.
versionstringThe browser version, or the empty string if unknown.
platformstringA key specifying which platform the browser should be running on. This value should be one of {WINDOWS|XP|VISTA|MAC|LINUX|UNIX|ANDROID}. When requesting a new session, the client may specify ANY to indicate any available platform may be used. For more information see
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);The hub will assign the test to a matching node.


Note: You need to have your windows and custom firewall settings configured to allow the connections between the hub and nodes to happen. When running the test cases in parallel, make sure the web driver instances are deallcoated at the end of the test case.
All properties that are set with respect to the browser like where to find the driver executable should be done in the node. System.setproperty("webdriver.ie.driver","path to driver executable") won't work when you are using grid.

 Eg:java -jar selenium-server-standalone-2.31.0.jar -role node -hub http://localhost:4444/grid/register
 -maxSession 15 -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=15
 -Dwebdriver.chrome.driver=lib\chromedriver.exe

Comments

Popular posts from this blog

Selenium - What Why Who How?

What is Selenium? Selenium is an open source automated   testing   suite for web applications across different browsers and platforms.   It is quite similar to HP Quick Test Pro ( QTP ) only that Selenium focuses on automating web-based applications. Why use Selenium? Selenium is fast and it supports programming in multiple languages like Java, C#,Python and Ruby.  So development of automation scripts can be done in your language of preference. Selenium works well with AJAX testing. Selenium Grid supports execution of test cases in multiple platforms and multiple browsers in remote systems as well.  The support for different programming languages gave selenium the power to harness the capabilities of those programming languages .  For example, using JAVA as the programming language to code selenium scripts enables selenium to use JDBC for database access and testing.All the APIs supported in Java also become the advantage of Selenium like L...

Transition from Test Automation Engineer to Test Engineer

What's the difference? Test Automation Engineer works on automating the Regression Test Suite. Test Engineer ensures the product can be released to the customer. With my industry experience, I have realized, that, as part of automation engineer your job duties don't stop with creating Automation tests, Frameworks and running them. With more tests being automated, your responsibilities not only include running the complete Regression suite but occasionally validation and verification of the product. There are different documents/sites defining different types of testing and where their usage, however,but finding bugs is a different skill. Though we are testers by role, our analytical minds work like developers as we develop scripts too. We could be biased. When something doesn't work, we look for a workaround and think it's no big deal. This attitude is a deal breaker!Instead use your skills to analyse and break the code. Here I am going to list some of my ideas ...