Run a test cases in multiple browsers in Selenium Webdriver

package testng;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class verifyFacebookTitle {
	
	WebDriver driver;
	
	@Test
	@Parameters("browser")
	public void verifyTitle(String browserName)
	{
		if(browserName.equalsIgnoreCase("firefox"))
		{
			driver=new FirefoxDriver();			
			
		}
		else if(browserName.equalsIgnoreCase("chrome"))
		{			
			System.setProperty("webdriver.chrome.driver", "E:\\Selenium\\chromedriver.exe");
			
			driver=new ChromeDriver();
						
		}
		driver.manage().window().maximize();

		driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
		
		driver.get("http://www.facebook.com");
		
		System.out.println("Title:---" +driver.getTitle());
		
		driver.quit();
	}

}

testng.xml

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite1" verbose="1" >
  <test name="firefox Test Suite"   >
  <parameter name="browser" value="firefox"></parameter>
  <classes>
  <class name ="testng.verifyFacebookTitle"></class>
  </classes>    
 </test>
 <test name="chrome Test Suite"   >
  <parameter name="browser" value="chrome"></parameter>
  <classes>
  <class name ="testng.verifyFacebookTitle"></class>
  </classes>    
 </test>
</suite>

 

Leave a Reply

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