Wednesday, November 19, 2025

Testing a number of browser configurations through Selenium WebDriver


How one can do it

1)Create your Script to check a LogIn utility utilizing the TestNG class.

2) Move ‘Browser Kind’ as parameters utilizing TestNG annotations to the earlier than technique of the TestNG class. This technique will launch solely the browser, which might be offered as a parameter.
bundle automationFramework;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.ie.InternetExplorerDriver;

import org.testng.annotations.AfterClass;

import org.testng.annotations.BeforeClass;

import org.testng.annotations.Parameters;

import org.testng.annotations.Check;

public class MultiBrowser {

 public WebDriver driver;

  @Parameters("browser")

  @BeforeClass

  // Passing Browser parameter from TestNG xml

  public void earlier than the take a look at(String browser) {

  // If the browser is Firefox, then do that

  if(browser.equalsIgnoreCase("firefox")) {

   driver = new FirefoxDriver();

  // If the browser is IE, then do that   

  }else if (browser.equalsIgnoreCase("ie")) { 

   // Right here I'm establishing the trail for my iedriver

   System.setProperty("webdriver.ie.driver", "D:ToolsQAOnlineStoredriversIEDriverServer.exe");

   driver = new InternetExplorerDriver();

  } 

  // Would not the browser sort, launch the Web site

  driver.get("http://www.retailer.demoqa.com"); 

  }

  // As soon as Earlier than a technique is accomplished, the Check technique will begin

  @Check public void login() throws InterruptedException {

 driver.findElement(By.xpath(".//*[@id='account']/a")).click on();

    driver.findElement(By.id("log")).sendKeys("testuser_1");

    driver.findElement(By.id("pwd")).sendKeys("Check@123");

    driver.findElement(By.id("login")).click on();

 }  

  @AfterClass public void afterTest() {

 driver.give up();

 }

}

3) Create a TestNG XML for working your take a look at. Configure the TestNG XML for passing parameters i.e. to inform which browser needs to be used for Working the Check.





 

 

 

 

 

 

 

 

 

 

 

 


Be aware: You possibly can set any variety of Browsers right here and only for the instance goal I’ve arrange solely two essential browsers.

4) Now it’s time to run the XML. Run the take a look at by proper click on on the testng.xml file and choose Run As > TestNG Suite.

Be aware: TestNg will execute the take a look at one after the other. It’s possible you’ll prefer to carry out parallel exams, the following matter will cowl that.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

PHP Code Snippets Powered By : XYZScripts.com