Is there any way to use Parameters with DataProvider together in Selenium ?



  public void hhhhh (String safaf){


2 Answers 2


Yes, it can be done. Parameter passing in TestNG can be done two ways:

  1. Using @Parameter tag and you pass the value from your testng.xml Useful when your dealing with simple parameter
  2. Using @DataProvider tag Useful if your reading values from prop file or database.

So your testng.xml will look something of this sort:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Suite123">
   <test name="test123">
   <parameter name="safaf" value="blah"/> 
     <class name="DataProvider123" />
  • Unfortunately, it does not work! @Parameters({"path"}) @Test(priority=2,dataProvider="db") public void description2( String path,String item) I got this error (The data provider is trying to pass 1 parameters but the method com.macys.NewTest#description2 takes 2 and TestNG is unable in inject a suitable object)!!!! anyway, Thanks for your help
    – osama
    Commented Oct 17, 2015 at 5:29
  • Ok, i wasn't precise earlier. Do not use both the annotation together on @Test. Follow the below approach: ` String myParam; @BeforeClass @Parameters("test") public void one(String p1) { p1 = this.myParam; } @Test(dataProvider="dp") public void two(String p2){ } Commented Oct 19, 2015 at 0:34
  • Did that solve your problem ? Commented Oct 21, 2015 at 1:48
  • No, i was looking for something else. I've changed my code to avoid this problem.
    – osama
    Commented Oct 22, 2015 at 4:05

DataProvider is a method in a class that returns a two dimensional an array of object (Object [ ][ ]) to the test method. The test method will be called m times in the m*n type of object array. Where m ➨ The first array m represents the number of rows that has to be repeated your test m number of times. n ➨ The second array n represents a column that is the number of parameters in the test data. This method is annotated with @DataProvider. DataProvider in TestNG

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.