package dataProvider; import java.lang.reflect.Method; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; public class dataProviders { WebDriver driver; @BeforeMethod public void setUp(){ //Initializing Driver System.setProperty("webdriver.gecko.driver", "C:\\geckodriver.exe"); driver = new FirefoxDriver(); //Opening search engine driver.get("https://google.com"); } @AfterMethod public void tearDown(){ driver.quit(); } @Test(dataProvider="destinations") public void domesticMonuments(String monument,String city) throws InterruptedException{ WebElement searchBox=driver.findElement(By.name("q")); searchBox.sendKeys(monument +" "+city); System.out.println("You are trying to search " +monument+ " which is in " +city); WebElement srchBtn = driver.findElement(By.name("btnK")); srchBtn.submit(); Thread.sleep(3000); System.out.println("The page title is: " +driver.getTitle()); } @Test(dataProvider="destinations") public void intlDestinations(String location) throws InterruptedException{ WebElement searchBox=driver.findElement(By.name("q")); searchBox.sendKeys(location); System.out.println("You are trying to search : " +location); WebElement srchBtn = driver.findElement(By.name("btnK")); srchBtn.submit(); Thread.sleep(3000); System.out.println("The page title is: " +driver.getTitle()); } @DataProvider(name="destinations") public Object[][] getDataProviderData(Method m){ if(m.getName().equalsIgnoreCase("domesticMonuments")){ return new Object[][]{ { "India Gate", "Delhi" }, { "Taj Mahal", "Agra" }, { "Char Minar", "Hyderabad" } }; } else{ return new Object[][]{ {"Paris"}, {"Cairo"}, {"Washington"} }; } } }