Tuesday 24 November 2015

Working with Selenium GRID On Different Machines


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: Initialize Hub

Now open command prompt on your machine (with administrator privileges).
Go to C:\ (Location where Selenium Standalone Server is present) and enter the following line to start Selenium Grid

java -jar selenium-server-standalone-2.48.2.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

You can use different port (4445) as well and check this at 
http://localhost:4445/grid/console


Step 3:Initialize Node

Open a new command prompt window on the machine where you want to run your code, go to C:\ (Location where Selenium Standalone Server is present) and enter the following line to register the browser to the Selenium Grid:

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


Step 4:

Now on your first command prompt you will get a message "Registered a node http://IP_Of_Machine_Where_You_Want_To_Run_Your_Code:New_Port_Number_"

(Here you will be Using that IP:New_Port in your code)


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













NOTE- Here 5555 is new port.

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 6:
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 7:

To run the tests just right click to testng.xml , select Run As-> TestNG Suite.
That’s it!
:)
This is how you can run your Tests on different machines.
Enjoy working with Selenium Grid !

Get complete access to the code-here is my github 

https://github.com/deshpandeaditya111/Selenium_Grid_Different_Machine


For any query mail me @ deshpandeaditya111@gmail.com


Thanks.