1

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

  @Parameters({"safaf"})

  @DataProvider(name="sss")

  public void hhhhh (String safaf){

  }
| improve this question | | | | |
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"/> 
   <classes>
     <class name="DataProvider123" />
  </classes>
   </test>
  </suite>
| improve this answer | | | | |
  • 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 Oct 17 '15 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){ } – JustARandomGuy Oct 19 '15 at 0:34
  • Did that solve your problem ? – JustARandomGuy Oct 21 '15 at 1:48
  • No, i was looking for something else. I've changed my code to avoid this problem. – osama Oct 22 '15 at 4:05
0

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

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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