Selenium Grid is part of the Selenium project. It lets you distribute test execution across several machines. You can connect to it with Selenium Remote by specifying the browser, browser version, and operating system you want.
Why you want to use Selenium-Grid. ?
To run tests in multiple browsers, multiple versions of a browser, and browsers running on different operating systems.
To reduce the time it takes for the test suite to complete a test pass.
Selenium-Grid is used to speed up the execution of a test pass by using multiple machines to run tests in parallel.
For example, if you have a suite of 1000 tests, but you set up Selenium-Grid to support 4 different machines (VMs or separate physical machines) to run those tests, your test suite will complete in (roughly) one-fourth the time as it would if you ran your tests sequentially on a single machine.
For large test suites and long-running test suite such as those performing large amounts of data-validation, this can be a significant time-saver.
Some test suites can take hours to run. Another reason to boost the time spent running the suite is to shorten the turnaround time for test results after developers check-in code for the AUT.
Increasingly software teams practicing Agile software development want test feedback as immediately as possible as opposed to waiting overnight for an overnight test pass. Selenium-Grid is also used to support running tests against multiple runtime environments, specifically, against different browsers at the same time.
For example, a 'grid' of virtual machines can be set-up with each supporting a different browser that the application to be tested must support. So, machine 1 has Internet Explorer 8, machine 2, Internet Explorer 9, machine 3, the latest Chrome, and machine 4, the latest Firefox. When the test suite is run, Selenium-Grid receives each test-browser combination and assigns each test to run against its required browser.
Also, one can have a grid of all the same browser, type, and version.
For instance, one could have a grid of 5 machines, each running 4 instances of Firefox 12, allowing for a ‘server-farm’ (in a sense) of available Firefox instances. When the suite runs, each test is passed to Selenium-Grid, which assigns the test to the next available Firefox instance. In this manner, one gets a test pass where conceivably 12 tests are all running at the same time in parallel, significantly reducing the time required to complete a test pass.
Selenium-Grid is very flexible. These two examples can be combined to allow multiple instances of each browser type and version.
A configuration such as this would provide both parallel execution for a fast test pass completion and support for multiple browser types and versions simultaneously.
1.Goto https://seleniumhq.org/download/
2. Download the Selenium server, yes, we use it for both purposes for writing selenium script and also a server.
3. Save it in someplace in your system.
1. Start the Hub
2. Start the node
3.Execute the script from Hub machine
4. Check results in Hub machine
There is no such thing called as Grid installation & Grid installation means installing HUB and NODE.
Hub is a system where all the framework and all details available, follow below steps to install
1. Go to the CMD
2. Write the below command in the CMD and hit enter button
java -jar c:LocationOfServerSeleniumServerName.jar -role hub
3. When Grid starts running, you can see like below
Once you see this then hub has started
4. Grid always starts in the port: 4444 by default
5. You can also save this command in the .bat file (like running TestNG script from a batch file)
6. If port 4444 is occupied by some other process means you can give your own node like 8888,8899,1234...
java -jar c:LocationOfServerSeleniumServerName.jar -role hub -port 8888
There is no such thing called as Grid installation & Grid installation means installing HUB and NODE
Create Headless Firefox Browser in Selenium webdriver
Node is system execution happens, and execution is controlled by the hub, follow below steps to install selenium node.
1. Go to the CMD
2. Write the below command in the CMD and hit enter button
java -jar c:LocationOfServerSeleniumServerName.jar -role node -hub https://ipaddress:4444/grid/register
But in my case, I am using the same system as Hub and Node so I can replace the IP address with LocalHost.
java -jar c:Nodeselenium-server-standalone-2.45.0.jar -role node -hub http://localhost:4444/grid/register
3. When Grid starts running, you can see like below
Once you see this then hub has started
4. Grid always starts in the port: 4444 by default
5. You can also save this command in the .bat file (like running TestNG script from a batch file)
Xpath in Selenium
Node is a system where the execution happens, and the hub controls the execution.
Run Grid:
1.Goto program which you want to run in the grid
2. In order execute a script in Grid we need to create a RemoteWebdriver Class
WebDriver driver=new RemoteWebDriver(hubUrl, dCap);
3. We should supply the URL of the hub and the desired capabilities(browser and os) of the remote computer to the constructor of RemoteWebdriver class while creating an object
//hub URL
URL hubUrl=new URL("http://localhost:4444/grid/register");
//creating instance to Desired Capabilities class
DesiredCapabilities dCap=new DesiredCapabilities();
//set the browser name
dCap.setBrowserName("firefox");
//set the os
dCap.setPlatform(Platform.WINDOWS);
Complete program for remote webdriver execution
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Reporter;
import org.testng.annotations.Test;
public class TestNGClass
{
public static void main(String[] args) throws MalformedURLException
{
//hub URL
URL hubUrl=new URL("http://localhost:4444/grid/register");
//creating instance to Desired Capabilities class
DesiredCapabilities dCap=new DesiredCapabilities();
//set the browser name
dCap.setBrowserName("firefox");
//set the os
dCap.setPlatform(Platform.WINDOWS);
WebDriver driver=new RemoteWebDriver(hubUrl, dCap);
driver.get("https://chercher.tech");
//remaining normal code
}
}
Run the code it will execute it in the node.
Ways to select a dropdown option in selenium
I am Pavankumar, Having 8.5 years of experience currently working in Video/Live Analytics project.
Thanks, siva. I have removed the duplication, with next update it will not be present. Thanks
Hi Tried GRID set up as given in this artical but i gettting error "Exception in thread "main" org.openqa.selenium.WebDriverException: Unable to parse remote response: " Evety time pls help