According to the latest stats, Chrome is acquiring 60.98%, Internet Explorer by 12.18%, Firefox by 11.47% and Safari by 3.72% of total market shares in the browser uses. Different users use different versions of browsers to open a website as per their comfort levels. Imagine when your websites don’t provide the same user experience with different combinations of browsers and OS. It will be a major drawback for your business, and you do not want that to happen.
On different browsers, a website provides different user experiences. Cross-Browser testing is the procedure of comparing a site or web app’s design and functionality across different platforms and web browsers to make sure consistent functionality and behaviour for the end-user. With so many varieties of web browsers, operating systems and devices, obtainable today, cross-browser testing has become a critical part of software development.
In this blog, we are going to discuss the role of cross-browser compatibly. With cross browser testing, we can test our website in all available browsers with different versions to provide same experience to our users everywhere.
There are two possible options available for cross browser testing as shown in the above image-
Selenium Grid is a part of Selenium suite which is used for executing test scripts, or we can say test cases across different systems, operating systems and web browser in parallel process. Mainly, there are two versions of Selenium Grid-
Selenium Grid works on the Hub-Node Principle. There is machine, or we can say a System that is called Hub, the centre part of the Selenium Grid. All the scripts will be executed from Hub. All the systems, where we want to execute our scripts, called NODE. These nodes are handled by the Hub remotely.
For configuration of selenium grid, firstly, we have to download selenium Java client Driver, which is a Jar file. Currently, its stable version is 3.141.59. Like we have stated earlier, Grid is working on the principle of HUB-Node. Let’s assume here, machine A is hub and Machine B is Node.
Now, put this Jar file in C drive of the machine A and B.
The screen should now look something like this-
Move to Drive C and run the code given-below. Here, we have worked with the IP address 192.168.1.3 because our hub is processing from there only. We can use any port number as well. For Ex. We used 5566 here-
java -jar selenium-server-standalone-3.4.0.jar -role webdriver -hub http://192.168.1.3:4444/grid/register -port 5566
At the time, we have set up a simple grid with a NODE on machine B, which is controlled by Hub, on machine A.
Now we move to the Gris’s web interface, hover on the icon of the browser that will be automated. We can note the platform name and Browser name shown by hovering.
Create Hub and nodes as explained earlier and TestNG should be configured in eclipse. Here, we have taken a sample test to login to Gmail and enter username and password.
public class GridExample {
@Test
public void mailTest() throws MalformedURLException{
DesiredCapabilities dr=null;
nodeURL1 = “<a href="http://192.168.1.4:5566/wd/hub">http://192.168.1.4:5566/wd/hub</a>”;
nodeURL2 = “<a href="http://192.168.1.4:5566/wd/hub">http://192.168.1.5:5566/wd/hub</a>”;
if(browserType.equals("firefox")){
dr=DesiredCapabilities.firefox();
dr.setBrowserName("firefox");
dr.setPlatform(Platform.WINDOWS);
}else{
dr=DesiredCapabilities.internetExplorer();
dr.setBrowserName("iexplore");
dr.setPlatform(Platform.WINDOWS);
}
RemoteWebDriver driver=new RemoteWebDriver(new URL(nodeURL1), dr);
driver.navigate().to("http://gmail.com");
driver.findElement(By.xpath("//input[@id='Email']")) .sendKeys("username");
driver.findElement(By.xpath("//input[@id='Passwd']")) .sendKeys("password");
Thread.sleep(2000);
RemoteWebDriver driver=new RemoteWebDriver(new URL(nodeURL2), dr);
driver.navigate().to("http://gmail.com");
driver.findElement(By.xpath("//input[@id='Email']")) .sendKeys("username");
driver.findElement(By.xpath("//input[@id='Passwd']")) .sendKeys("password");
Driver.close();
}
The above code launches chrome browser and navigates to the URL specified in the nodeURL1 and nodeURL2.
To execute test scripts on the Grid, we require two objects, the first one is DesiredCapabilities and the second is RemoteWebDriver object.
So, in this blog, we have understood the cross-browser testing using Selenium Grid. Now you can easily your website in all available browsers with different versions to provide the same experience to our users everywhere with the help of cross-browser testing.
Here you can know the steps to Install Selenium Webdriver in Eclipse IDE and Create Selenium Webdriver project by visit on it. Hope this information will be helping you and your growth also.