My Blog List

Wednesday, August 17, 2011

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 = "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();
}

}

2 comments:

  1. Hi,
    I am doing this in java web driver.But when i am writing driver.findElement(By.name("txtUserName")).sendKeys("UserName");The program is not running.Please help me how to do this.

    ReplyDelete
  2. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium

    ReplyDelete