Testing a number of browser configurations through Selenium WebDriver

0
23
Testing a number of browser configurations through Selenium WebDriver


Find out how to do it

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

2) Go ‘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();

  } 

  // Does not the browser kind, 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 Operating the Check.





 

 

 

 

 

 

 

 

 

 

 

 


Observe: You may set any variety of Browsers right here and only for the instance function I’ve arrange solely two primary 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.

Observe: TestNg will execute the take a look at one after the other. Chances are you’ll wish to carry out parallel exams, the following matter will cowl that.

LEAVE A REPLY

Please enter your comment!
Please enter your name here