Guide to Setup Selenium
Grid2
Objective:-
Intent of this document to use Selenium Grid2 to execute Selenium
WebDriver test scripts on multiple browsers running on multiple physical/virtual
machines.
Some Terminology
need to know:-
- Hub – Implies selenium grid2 hub, which can only be one in our case & it will distribute test among multiple nodes registered to it at runtime.
- Node – One node represents one machine where test will be running & we can have multiple nodes those will be registered with one centralized hub which will be running on anyone machine.
Selenium-server-standalone
jar:-
- Download latest version of selenium-server-standalone-x.x.x.jar from below url-http://code.google.com/p/selenium/downloads/list
Note: - Have used selenium-server-standalone-2.25.0.jar
here, You can download latest available version jar.
JSON configuration
file creation:-
- Create a text file named as “webconfig.txt”
- Open that created “webconfig.txt” file & Copy following content in to that.
{
"capabilities":
[
{
"browserName":
"firefox",
"acceptSslCerts":
true,
"javascriptEnabled":
true,
"takeScreenshots":
true,
"firefox_profile":
"",
"maxInstances":
3,
"seleniumProtocol":
"WebDriver"
},
{
"browserName":
"chrome",
"maxInstances":
3,
"seleniumProtocol":
"WebDriver"
},
{
"platform":
"WINDOWS",
"browserName":
"internet explorer",
"maxInstances":
4,
"seleniumProtocol":
"WebDriver"
}
],
"configuration":
{
"cleanUpCycle":
2000,
"timeout":
30000,
"proxy":
"org.openqa.grid.selenium.proxy.WebDriverRemoteProxy",
"maxSession":
5,
"port":
5555,
"host":
noiam003ag-w1,
"register":
true,
"hubPort":
4444,
"hubHost"
: noiam003ag-w1
}
}
- Now
after copying above content in the file, Save it.
- Make sure both ‘selenium-server-standalone-2.25.0.jar’ and ‘webconfig.txt’ are in the same directory.
Configurable parameters
in the “webconfig.txt”:-
- In
capabilities section we can have sections for browsersName &
‘maxInstances’ parameter value can be changed as per the required number
of instances of that particular browser on that machine.
- In
configuration section, ‘port’ defines port with which a node will be
registered to the hub & each node will be registered with different
port.
- In
configuration section, ‘host’ defines machine_name/machine_IP on which
that node is running & one machine can have only one node running on.
- In
configuration section, ‘hubPort’ defines port where hub is running on
anyone machine among all test machine/VMs & port “4444” (i.e. default
port to run hub) will remain same when we will have ‘webconfig.txt’ file
on any node machine only node configurations will be changed.
- In configuration section, ‘hubHost’ defines machine_name/machine_IP where hub is running on anyone machine among all test machine/VMs & its value will remain same when we will have ‘webconfig.txt’ file on any node machine only node configurations will be changed.
Copying both
‘selenium-server-standalone-2.25.0.jar’ and ‘webconfig.txt’ on number of
machines required for testing:-
- Before
copying ‘webconfig.txt’ on multiple machine, Set ‘hubPort’ and ‘hubHost’
parameters value to the port ‘4444’ and the ‘machine_name’ respectively.
- Copy
both files on all machines/VMs under the same directory.
- After copying update ‘port’ and ‘host’ parameter values accordingly (i.e. port value will be 5555, 5556, 5557 …in sequence for each node on a machine & host value will be the name of each machine_name where node will running).
Running Hub &
Nodes:-
- On first machine, open command prompt.
- Navigate to folder location where both ‘selenium-server-standalone-2.25.0.jar’ and ‘webconfig.txt’ files are available.
- Now run below command to run Selenium Grid 2 Hub on that machine:-
java -jar
selenium-server-standalone-2.25.0.jar -role hub -hubConfig webconfig.txt
Command prompt looks
as below:-
- Open another command prompt if you want to use same as a node also.
- Navigate to folder location where both ‘selenium-server-standalone-2.25.0.jar’ and ‘webconfig.txt’ files are available.
- Run below command to run node on that machine:-
java -jar selenium-server-standalone-2.25.0.jar
-role wd –hub http://put_hub_machine_name_here:4444/grid/register
-port 5555 -nodeConfig webconfig.txt
(Note: - Don’t forget to enter the “hub_machine_name”
in above command)
Command prompt should appear as
below:-
- Follow the steps 4 to 6 on each machine where you want to run the node, only you need to change the node port from ‘5555’ to ‘5556’, ‘5557’ …. on each machine in the same sequence.
Running Grid2
console in browser:-
- Open
the browser, Enter the following URL:-
http://put_hub_machine_name:4444/grid/console
(Note: - Don’t forget to enter the “hub_machine_name”
in above URL)
- Web page will be showing number of nodes running.
- Following screen would appear on the browser.
Here we have two nodes running on
two different nodes with number of browser instances (i.e. configured in
webconfig.txt file) available.
Make sure BaseTestSetup.java
class has setup method as below:-
Use following setup method with your WebDriver scripts to manage multiple browser with Grid2:-
public WebDriver
setup(String BROWSER) throws MalformedURLException{
System.out.println("Browser:
" + BROWSER);
if
(BROWSER.equals("FF")) {
System.out.println("FF is
selected");
capability = DesiredCapabilities.firefox();
capability.setBrowserName("firefox");
capability.setPlatform(org.openqa.selenium.Platform.ANY);
driver = new
RemoteWebDriver(new URL("http://noiam003ag-w1:4444/wd/hub"), capability);
driver.get(baseURL);
} else if (BROWSER.equals("IE")) {
System.out.println("IE is
selected");
capability =
DesiredCapabilities.internetExplorer();
capability.setBrowserName("internet
explorer");
capability.setPlatform(org.openqa.selenium.Platform.WINDOWS);
} else if (BROWSER.equals("CH")){
System.out.println("Google
chrome is selected");
System.setProperty("webdriver.chrome.driver", "C:/ChromeDriver/chromedriver.exe");
capability =
DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setPlatform(org.openqa.selenium.Platform.WINDOWS);
driver = new
RemoteWebDriver(new URL("http://noiam003ag-w1:4444/wd/hub"), capability);
driver.get(baseURL);
}
System.out.println("Remote
Driver setup");
return driver;
}
Running
testScripts on those nodes:-
Now create TestNG.xml with following content and run as TestNG Suite then after Grid Hub will distribute the test among nodes & their available browser
instances.
<!DOCTYPE suite SYSTEM
"http://testng.org/testng-1.0.dtd">
<suite name="Selenium WebDriver
Training" parallel="tests" thread-count="20">>
<test name="WebDriverDemo with
Opera" preserve-order="true">
<parameter
name="BROWSER" value="OPERA"></parameter>
<classes>
<!--class
name="com.pb.selenium.training.testScripts.GoogleTest"></class-->
</classes>
</test>
<test name="WebDriverDemo With
FF" preserve-order="true">
<parameter
name="BROWSER" value="FF" />
<classes>
<class
name="com.pb.selenium.training.testScripts.GoogleTest"></class>
<class
name="com.pb.selenium.training.testScripts.GridSample"></class>
</classes>
</test>
<test name="WebDriverDemo with
IE" preserve-order="true">
<parameter
name="BROWSER" value="IE"></parameter>
<classes>
<!--class
name="com.pb.selenium.training.testScripts.GoogleTest"></class-->
</classes>
</test>
<test name="WebDriverDemo with
Google Chrome" preserve-order="true">
<parameter
name="BROWSER" value="CH"></parameter>
<classes>
<class
name="com.pb.selenium.training.testScripts.GoogleTest"></class>
<class
name="com.pb.selenium.training.testScripts.GridSample"></class>
</classes>
</test>
</suite>



Visit www.toolsqa.com for Selenium Learning with Practice Exercises and detailed explanations.
ReplyDeleteHi Amit,
ReplyDeleteI'm having problems in setting up the Base class could you please send the full base class code
Thanks
Hello Vamshi,
DeleteSend in you class file, will try to rectify it.
Hi Amit,
Deleteplease could you send me a test mail to: vamshi9006@gmail.com, In reply I can send you the code.
Hi Amit,
ReplyDeleteI am getting the error that is Couldn't register this node: Error sending the registration request: The hub responded with 500:Server Error. Could you please tell me how to resolve this.
Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn aboutSelenium
ReplyDeleteThanks for the nice article Amit, It was very helpful.
ReplyDeleteBest Selenium training institute in Chennai | Best Selenium training in Chennai
This comment has been removed by the author.
DeleteThanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium. PHP Training Institute in Chennai>
ReplyDeleteBest PHP Training in Chennai>
Attend The Python training in bangalore From ExcelR. Practical Python training in bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Python training in bangalore.
ReplyDeletepython training in bangalore
Such as very excellent information, it helps us to improve our mind knowledge. Keep on updating like this information!!artificial intelligence course
ReplyDeleteYou shared the very useful information with us. For more topics and more data go to All Writers Destination. Where the guest posting facility is available.
ReplyDelete"ExcelR is a global leader delivering a wide gamut of management and technical training over 40 countries. We are a trusted training delivery partner of 350+ corporate clients and universities across the globe with 140,000+ professionals trained across various courses.
ReplyDeleteBest Data Science Courses in Pune "
I am impressed by the information that you have on this blog. It shows how well you understand this subject.
ReplyDeletedata science course in varanasi
Infycle Technologies in Chennai offers the leading Big Data Hadoop Training in Chennai for tech professionals and students at the best offers. In addition to the Python course, other in-demand courses such as Data Science, Big Data Selenium, Oracle, Hadoop, Java, Power BI, Tableau, Digital Marketing also will be trained with 100% practical classes. Dial 7504633633 to get more info and a free demo.
ReplyDeletemmorpg oyunlar
ReplyDeleteINSTAGRAM TAKİPÇİ SATİN AL
tiktok jeton hilesi
tiktok jeton hilesi
SAC EKİMİ ANTALYA
referans kimliği nedir
instagram takipçi satın al
metin2 pvp serverlar
instagram takipçi satın al
perde modelleri
ReplyDeletesms onay
vodafone mobil ödeme bozdurma
nft nasıl alınır
ANKARA EVDEN EVE NAKLİYAT
trafik sigortası
dedektör
Web sitesi kurmak
aşk kitapları