Here is the sample code for DataDriven TestNG test...
package Excel;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.Hashtable;
import org.testng.annotations.Test;
import org.testng.annotations.DataProvider;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import org.openqa.selenium.*;
import org.openqa.selenium.server.SeleniumServer;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
import Excel.POI; //Class POI contains methods to read Excel file
public class Test1 {
SeleniumServer server;
Selenium sel;
POI poi = new POI();
@BeforeClass
public void beforeClass() throws Exception {
server = new SeleniumServer();
server.start();
sel = new DefaultSelenium("localhost", 4444, "*iehta", "http://www.google.com/");
sel.start();
}
@DataProvider
public Object[][] dp() throws IOException {
poi.fileName = "C:\\Users\\shanmugavel.chinnago\\Desktop\\test.xlsx";
poi.sheetName = "Sheet1";
poi.open();
return poi.getData();
}
@Test(dataProvider = "dp")
public void googleTest(Hashtable value) {
sel.open("/");
sel.type("//input[@name='q']", value.get("C1")); //C1 - ColumnName
}
@AfterClass
public void afterClass() {
sel.close();
sel.stop();
server.stop();
}
}
Comments
Post a Comment