VST

Testing using Selenium

Cross Browser Testing using Selenium

In today’s world industries are focusing and migrating on web-based applications, there are large numbers of users using web browsers as per their convenience. There is a possibility that the user interface of the web application will not be the same for different web browsers. Also, sometimes applications may work as expected on default web browser on which it is developed and may not work same on another browser. The reason behind this is configuration/compatibility issues. To avoid such type of end user accessibility issues tester can perform cross browser testing to make sure application will work as per expectations on multiple browser their widely used versions and operating systems.

Let us assume we have ‘ABC’ e-commerce application which is developed on chrome browser, and it helps to select and buy grocery products. When we open the application on chrome browser, GUI of the application is displayed as per the expectations as well as user can select & buy products using it. But when the user is trying to search and buy a product using the same application on another browser (e.g., Firefox) there is a possibility that the GUI of the application will be different, and user will not be able to buy the product. To avoid such types of issues testers can perform cross browser testing to make sure that application will work fine on multiple browsers.

Cross browser testing Summary:

  • Cross browser testing is a non-functional form of testing.
  • Cross browser testing means testing web application on multiple browsers and their various versions. Multiple combinations of web browser, versions and OS can be tested using cross browser testing.
  • It can be performed manually and using automation tools.
  • It is recommended to implement cross browser testing at the initial phase of execution.
  • Testers should list down the number of browsers, versions, OS to be tested and plan the execution accordingly.

If the tester opted for manual cross browser testing, then it can be a tedious job to perform cross browser testing. There are plenty of browsers and their versions available in the market. To open and check applications on each browser will not be possible. When a tester performs manual testing, ad hoc test cases suites are created instead of testing complete test suite. There are chances of missing/skipping the functionality that needs to be tested on multiple browsers.

There comes the ‘Selenium’which is a popular framework to perform automated cross browser testing. Selenium helps to test complete set of test scripts on multiple browsers. It also reduces the time of execution, requires a less number of resources and does testing more efficiently.

Cross browser testing using Selenium:

  • Tester can perform automated cross browser testing using selenium + TestNG.
  • This will help tester to get confidence web application will work as per expectations on multiple browsers.
  • The exeuction time will reduce as compared manual cross browser testing.
  • Chances of skipping/missing the functionality to be tested is less.
  • Less number of resources are required.

Step 1: Create Maven project and add below dependencies in pom.xml file.

<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>VS-TestNG-Framework</groupId>
<artifactId>VS-TestNG-Framework</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.10.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.7.1</version>
</dependency>
</dependencies>
</project>

Step 2: Create BaseTest class and initialize browsers as per requirements.

public class BaseTest {
public WebDriver driver;
public WebDriver getDriver(String browser) {
if (browser.equals("chrome")) {
ChromeOptions co = new ChromeOptions();
co.addArguments("--remote-allow-origins=*");
driver = new ChromeDriver(co);
System.out.println("Initilize chrome");
}
else if (browser.equals("firefox")) {
driver = new FirefoxDriver();
System.out.println("Initilize firefox");
}
else if (browser.equals("edge")) {
EdgeOptions eOption = new EdgeOptions();
eOption.addArguments("--remote-allow-origins=*");
driver = new EdgeDriver(eOption);
System.out.println("Initilize edge");
}
   return driver;
}
}

Step 3: Create Test class file.

public class TestBrowser extends BaseTest {
@Parameters({"browserName"})
@Test
public void doLogin(String browser) throws InterruptedException {
Date date = new Date();
System.out.println("Browser name : "+browser+"--"+date);
Thread.sleep(4000);
driver=getDriver(browser);
driver.get("https://www.google.com/");
driver.manage().window().maximize();
driver.findElement(By.xpath("//textarea[@name='q']")).sendKeys("India");
Thread.sleep(4000);
Actions builder = new Actions(driver);
builder.sendKeys(Keys.ENTER);
driver.quit();
}
}

Step 4: Create test xml file (cross-browser.xml)

<?xml version="1.0" encoding="UTF-8"?
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Cross Browser Test" parallel="none">
<test name="Firefox Test">
<parameter name="browserName" value="firefox"></parameter>
<classes>
<class name="com.vstl.crossbrowsertest.TestBrowser" />
</classes>
</test>
<test name="Edge Test">
<parameter name="browserName" value="edge"></parameter>
<classes>
<class name="com.vstl.crossbrowsertest.TestBrowser" />
</classes>
</test>
<test name="Chrome Test">
<parameter name="browserName" value="chrome"></parameter>
<classes>
<class name="com.vstl.crossbrowsertest.TestBrowser" />
</classes>
</test>
</suite>>

Step 5: Run the cross-browser.xml using TestNG Suite option.

Single Test present in TestBrowser class file will be executed thrice on multiple browsers in below order.

1.      Firefox browser

2.      Edge browser

3.      Chrome browser

Ref link: https://www.selenium.dev/

Tags:
Testing using Selenium

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

Test Automation Streamlining REST API Processes with Postman Automation Summary:In today's world, industries are increasingly focusing on the development of...

Uncategorized Enhancing Test Efficiency with Playwright, TestNG and Allure Summary:Playwright is an open-source library developed by Microsoft for automated browser...

Test Automation Continuous Integration and Delivery with Jenkins and GitHub Summary: Testing and deployment-related operations can be automated with Jenkins,...

Mobile App Test Automation with TDD Telecommunications (Cable) Location Performance Testing CONTEXT Elyments is an India-based mobile application similar to...

Leave a Reply

Your email address will not be published. Required fields are marked *