Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

/*package test; import org.testng.annotations.DataProvider; import org.testng.annotations.

Test; public class DataProviderTest { static Object[] data; // to // subject // mail body @Test(dataProvider="getData") public void testMailSending(String to , Integer sub, String msg){ System.out.println(to +" --- " + sub + " --- " + msg); // DataProviderTest.getData(). data[0]. } @DataProvider public static Object[] getData(){ // Selenium framework - read the data from xls file and put it i n Object array // rows - number of time test has to be repeated // cols - number of parameters in test data data = new Object[2]; // 1st row data[0] = "xyz@gmail.com"; data[1] = "123"; data[0][2] = "howzz life"; // 2nd row data[1][0] = "abc@gmail.com"; data[1][1] = 444; data[1][2] = "life is good"; return data; } } package test; import java.net.MalformedURLException; import java.net.URL; import import import import import import import import import import public org.openqa.selenium.By; org.openqa.selenium.WebDriver; org.openqa.selenium.WebElement; org.openqa.selenium.remote.DesiredCapabilities; org.openqa.selenium.remote.RemoteWebDriver; org.testng.annotations.AfterClass; org.testng.annotations.BeforeClass; org.testng.annotations.DataProvider; org.testng.annotations.Parameters; org.testng.annotations.Test; class ParallelTest{

public WebDriver driver; //@Parameters({"browser"}) @BeforeClass public void setup() throws MalformedURLException, InterruptedException{ DesiredCapabilities capability=null; // String browser="chrome"; if(data.equalsIgnoreCase("firefox")){ System.out.println("firefox"); capability= DesiredCapabilities.firefox(); capability.setBrowserName("firefox"); capability.setPlatform(org.openqa.selenium.Platform.AN Y); //capability.setVersion("3.6"); } if(browser.equalsIgnoreCase("internet explorer")){ System.out.println("internet explorer"); capability= DesiredCapabilities.internetExplorer() ; capability.setBrowserName("internet explorer"); capability.setPlatform(org.openqa.selenium.Platform. WINDOWS); //capability.setVersion(""); } if(browser.equalsIgnoreCase("chrome")){ System.out.println("chrome"); System.setProperty("webdriver.chrome.drive r", "d:\\chromedriver\\chromedriver.exe"); // browser.add(setupDriver(new ChromeDriver ())); capability= DesiredCapabilities.chrome(); capability.setBrowserName("chrome"); capability.setPlatform(org.openqa.selenium.P latform.WINDOWS); //capability.setVersion(""); } System.out.println("A"); driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/h ub"), capability); //Thread.sleep(50000L); System.out.println("B"); driver.get("http://google.com"); Thread.sleep(10000L); } @Test(dataProvider="getData") public void test_THIRD() throws InterruptedException{ Thread.sleep(3000); WebElement search_editbox = driver.findElement(By.name("q")); WebElement search_button = driver.findElement(By.name("btnG" )); search_editbox.clear(); search_editbox.sendKeys("3RD"); search_button.click(); System.out.println("third"); }

@Test(dataProvider="getData") public void test_FOURTH(){ WebElement search_editbox = driver.findElement(By.name("q")); WebElement search_button = driver.findElement(By.name("btnG" )); search_editbox.clear(); search_editbox.sendKeys("4TH"); search_button.click(); System.out.println("fouth"); } @AfterClass public void tearDown(){ driver.quit(); } @DataProvider public Object[] getData(){ // Selenium framework - read the data from xls file and put it in Object array // rows - number of time test has to be repeated // cols - number of parameters in test data Object[] data = new Object[3]; // 1st row data[0] = "chrome"; data[1] = "iexplore"; data[2] = "firefox"; return data; } } */

You might also like