Skip to main content

Posts

Showing posts with the label Data Driven TestNG Selenium RC

Apache POI - Read Excel - For use of Selenium TestNG DataProvider

Here is the Class designed for reading Excel file... You can download the JAR files needed to work with Apache POI here . package Excel; import java.io.File; import java.io.FileInputStream; import org.apache.poi.ss.usermodel.*; import java.io.IOException; import java.io.InputStream; import java.util.Enumeration; import java.util.Hashtable; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.dom4j.DocumentException; public class POI { int rowIndex = 0, columnIndex = 0; Workbook wb; Sheet ws; Row wr; String fileName, sheetName; Hashtable <String, String> [] data = null; public  void open() throws IOException  { if (fileName.indexOf("xlsx") < 0) { wb = new HSSFWork...

TestNG - DataDriven Custom Framework

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 = "...