Learn Selenium Grid
Simple steps to learn Selenium grid or How can you use
selenium grid and Jmeter CPU performance. 22 Steps to learn
Selenium grid
Hello Friends,
Hope you all are doing good in your fields…… 🙂
By using Selenium Grid, you can run a single functional
testing code of selenium on multiple machines simultaneously.
You can use selenium webdriver and Jmeter simultaneously
to check the performance of the Application server. How ??
Run your functional code on 10 machines using selenium grid
and check the performance of the application server using
Jmeter CPU memory usage(Perfmon plugin). 🙂
What ever you can test on tools but real performance is
achieved only when the application runs on physical
machine in real time. So we are sharing the steps to
simply setup the Selenium grid on machine.
- First download the Selenium standalone server(RC) current version 2.48.2 from the Official selenium website (http://www.seleniumhq.org/download/)
- Now put the downloaded Jar file usually naming selenium-standalone-server.2.48.2.jar on any folder
- Now this selenium jar file will not be executed directly. You have to execute this using command prompt(run>cmd)
- Firstly you have to locate the path where you selenium standalone jar file is. Like if it is on your desktop then in cmd your path should be C>Desktop
- Now you have to execute the following command to run the selenium server
java -jar selenium-server-standalone-2.48.2.jar -port 4444 -role hub -nodeTimeout 1000
Java -jar selenium-server-standalone-2.48.2.jar -port 4444 -role hub -nodeTimeout 1000
This 2.48.2 version may be change so you should be aware that which file you have downloaded from website.
This command you have to executed on the system to which you want to make hub.
What is hub ? Hub means the machine from where you will execute your test like where you have code for your selenium.
Node – node means the machine/machines where you want to run the selenium code of your hub machine. Hub is the center from where you will trigger the automated test and that single automated test will be executed on all the connected node machines if you have setup them correctly 🙂
When you will run the above command on hub machine then it will look like this –
It can show you failure message if port 4444 is already being used on your machine. So you can change the port like 4445 or whatever you like.
- Now your server is started so you can go and check if it is running correctly –
Open browser and hit http://localhost:4444 (localhost=192.168.0.159) or the port you have used
- You can click on the link – Console and check the configuration.
- Now your hub is configured correctly 🙂
- Now you have to configure your nodes(machines where you want to run your test)
- To configure the node, share/download the same selenium standalone server file on all the nodes where you want to run the test.
- On node machines, you have to run the following command to run node server and connect the hub
- java -jar selenium-server-standalone-2.48.2.jar -role node -hub http://192.168.0.159:4444/grid/register -browser browserName=firefox -port 5555
- In 12thstep, ip 192.168.0.159:4444 is the IP of the hub which we have configured in above step.
- So the conclusion is that we are connecting node machine to the hub machine using above command
- If your command is executed successfully on the node machine then check your Hub machine and hit the same URL above provided http://localhost:4444 and check that Hub and server is connected.
- Now you are ready with your servers hub and node. Now you have to code the selenium program using remotedriver commands on your hub machine 0.159 here –
public class TestNGClass
{
public WebDriver driver;
public String URL, Node;
protected ThreadLocal<RemoteWebDriver> threadDriver = null;
@Parameters(“browser”)
@BeforeTest
public void searching(String browser) throws MalformedURLException
{
String URL = “http://www.google.com”;
browser.equals(“firefox”);
System.out.println(” Executing on FireFox”);
String Node = “http://192.168.0.81:5555/wd/hub”;
DesiredCapabilities cap = DesiredCapabilities.firefox();
cap.setBrowserName(“firefox”);
driver = new RemoteWebDriver(new URL(Node), cap);
// Puts an Implicit wait, Will wait for 10 seconds before throwing exception
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// Launch website
driver.navigate().to(URL);
driver.manage().window().maximize();
}
@Test
public void search()
{
driver.findElement(By.xpath(“testxpath”)).click();
driver.findElement(By.xpath(“test2xpath”)).click();
driver.findElement(By.id(“test”)).sendKeys(“5”);
driver.findElement(By.id(“test2”)).sendKeys(“20”);
}
}
- Work is not completed here friends :). Your program is ready but how it will communicate with the node server. For that you have to create/generate an XML file. Now like me you can also be feared out XML file???? How to write XML bla bla… 🙂 but don’ t worry it is very simple XML file in which only you have to pass parameters like for above program.
- Go to eclipse or whatever editor you are using(here we are using eclipse) and right click on the project and select new>Other>
Now select XML file as shown above and it will open a blank XML file to you
Now write the code in them for XML like in our case above
<?xml version=“1.0” encoding=“UTF-8”?>
<!DOCTYPE suite SYSTEM “http://testng.org/testng-1.0.dtd”>
<suite name=“Suite” parallel=“tests”>
<test name=“FirefoxTest”>
<parameter name=“browser” value=“firefox” />
<classes>
<class name=“TestNG.TestNGClass” />
</classes>
</test>
</suite>
Now you can see this XML is very simple. We have only write browser parameter, class parameter and their value. Browser parameter value is firefox as we need to run on firefox, you can choose IE or chrome too.
Class name is the class name we have given during class creation.
- Now you are ready to run your test. Simply right click on newly created XML file> Run as> TestNG Suite
- This will successfully run your code on your node machines.
Sometimes it shows an error of FAILED CONFIGURATION: @BeforeTest launchapp
org.testng.TestNGException:
Parameter ‘browser’ is required by @Configuration on method launchapp but has not been marked @Optional or defined
- in C:\Users\AppData\Local\Temp\testng-eclipse-1750918716\testng-customsuite.xml
- So go to your above XML file which we have created in step 18 and check browser value = firefox. If it is already there, then just save the file and run it, because sometimes doing no change and only save can make a huge change 😉
So this above 22 steps can easily teach you how to run any test on remote machines.
Here in above code, IDs,Xpaths are false so please do not just copy paste and try to run 😉
Thanks for reading and please like/follow us on social media to encourage us for writing more 🙂
https://www.facebook.com/Knowledge-World-For-You-1660665640835573/timeline/
https://twitter.com/you_knowledge
Thanks
KnowledgeWorldForYou Team