TestNg @Dataprovider is not working in my DataDriven testing - using selenium eclipse
My Java class is not running. I have a @DataProvider with Apache POI to read data from an Excel file and set that values in an web page. but the script is ending with No test found error. Here is my code :
package testCases;
import org.openqa.selenium.By;
import org.testng.Reporter;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import base.TestBase;
public class StudentRegistrationForm extends TestBase {
@Test(dataProvider = "getData")
public void addStudent(String fname, String email, String CurrentAddress,String PermAddress) {
System.setProperty("org.uncommons.reportng.escape-output", "false");
//driver.get(confg.getProperty("testsiteurl"));
driver.get(confg.getProperty("url2"));
log.debug("Navigated to : " + confg.getProperty("url2"));
driver.findElement(By.cssSelector(or.getProperty("fullname"))).sendKeys(fname);
driver.findElement(By.cssSelector(or.getProperty("email"))).sendKeys(email);
driver.findElement(By.cssSelector(or.getProperty("currentAddress"))).sendKeys(CurrentAddress);
driver.findElement(By.cssSelector(or.getProperty("permAddress"))).sendKeys(PermAddress);
driver.findElement(By.cssSelector(or.getProperty("submit"))).click();
log.debug("Completed Test 2 - Student Registration Form");
Reporter.log("Completed Test 2 - Student Registration Form");
}
@DataProvider(name="getData")
public Object[][] getData(){
String SheetName = "sheet1";
int rows = excel.getRowCount(SheetName);
int cols = excel.getColumnCount(SheetName);
Object[][] data = new Object[rows - 1][cols];
for (int RowNum = 2; RowNum < rows; RowNum++) {
for (int colNum = 0; colNum < cols; colNum++) {
data[RowNum - 2][colNum] = excel.getCellData(SheetName, colNum, RowNum);
}
}
return data;
}
}
And here is my output in the eclipse console.
=============================================== Default test Tests run: 0, Failures: 0, Skips: 0
=============================================== Default suite Total tests run: 0, Passes: 0, Failures: 0, Skips: 0
[TestNG] No tests found. Nothing was run Usage: [options] The XML suite files to run Options: -alwaysrunlisteners Should MethodInvocation Listeners be run even for skipped methods Default: true -configfailurepolicy Configuration failure policy (skip or continue) -d Output directory -dataproviderthreadcount Number of threads to use when running data providers -dependencyinjectorfactory The dependency injector factory implementation that TestNG should use. -excludegroups Comma-separated list of group names to exclude -failwheneverythingskipped Should TestNG fail execution if all tests were skipped and nothing was run. Default: false -groups Comma-separated list of group names to be run -junit JUnit mode Default: false -listener List of .class files or list of class names implementing ITestListener or ISuiteListener -methods Comma separated of test methods Default: [] -methodselectors List of .class files or list of class names implementing IMethodSelector -mixed Mixed mode - autodetect the type of current test and run it with appropriate runner Default: false -objectfactory List of .class files or list of class names implementing ITestRunnerFactory -parallel Parallel mode (methods, tests or classes) Possible Values: [tests, methods, classes, instances, none, true, false] -port The port -reporter Extended configuration for custom report listener -spilistenerstoskip Comma separated fully qualified class names of listeners that should be skipped from being wired in via Service Loaders. Default: -suitename Default name of test suite, if not specified in suite definition file or source code -suitethreadpoolsize Size of the thread pool to use to run suites Default: 1 -testclass The list of test classes -testjar A jar file containing the tests -testname Default name of test, if not specified in suitedefinition file or source code -testnames The list of test names to run -testrunfactory, -testRunFactory The factory used to create tests -threadcount Number of threads to use when running tests in parallel -threadpoolfactoryclass The threadpool executor factory implementation that TestNG should use. -usedefaultlisteners Whether to use the default listeners Default: true -log, -verbose Level of verbosity -xmlpathinjar The full path to the xml file inside the jar file (only valid if -testjar was specified) Default: testng.xml
There is nothing wrong with the testng usage in your code above. This simply means there is no data being provided by the data provider. You can either put a debug point on your data object or print it to see if the data array is being initialized. Maybe your excel utility is not correctly written or an exception is being eaten inside.