Thursday 19 November 2015

Working with Selenium Grid !

Prerequisites:

Must have a well setup of test environment with Eclipse and TestNG .
If not, refer the link Setup WebDriver with Eclipse

Working with Selenium GRID

Step 1
Download Selenium Server jar file from Selenium’s official website and save it at any location on the local disk.
Note- Copy this file to a simple place, for example C:\

URL of selenium HQ: http://www.seleniumhq.org/download/


Step 2
Now open command prompt (with administrator privileges).
Go to C:\ and enter the following line to start Selenium Grid

java -jar selenium-server-standalone-2.33.0.jar -role hub -port 4444
OR
java -jar selenium-server-standalone-2.48.2.jar -role hub

The hub will use the port 4444 by default. This port can be changed by passing the different port number in command prompt provided the port is open and has not been assigned a task.

Status can be checked by using the web interface: http://localhost:4444/grid/console


Step 3:
Open a new command prompt window, go to c:\ and enter the following line to register the browser to the Selenium Grid:

java -jar selenium-server-standalone-2.33.0.jar -role node -hub http://localhost:4444/grid/register -browser browserName=firefox,maxInstances=3

The maxInstance will determine the max number of the browsers. If it is set to 3 than maximum 3 browsers(tests) are able to run parallel.



Step 4:
Now in Eclipse create a new project, a new package and a new class. Name it TestBase.
Here is the code























Now create five java class file. These files would contain the tests.
For example here is my sample test file:












Create similar test files with different name (e.g Test 02,Test 03 and so on)

NOTE- @BeforeMethod and @AfterMethod methods will be executed from TestBase. So every test file need to be extended with TestBase.



Step 5:
Now we need to create two xml file in Eclipse to the project root.
One of the files must be named to testng.xml.
Here is the content of the testng.xml file:








And here is the testFiles.xml (another xml file)






















NOTE- Here "testNG.Parallel" is the name of the package where above class files are stored.


Step 6:
To run the tests just right click to testng.xml , select Run As-> TestNG Suite.
That’s it!

:)
Enjoy working with selenium grid ! 


To get the full code-Here is my github 

https://github.com/deshpandeaditya111/Selenium_Grid_Project

For any query mail me @ deshpandeaditya111@gmail.com