Using both Parameter annotation and Data Provider

114 views
Skip to first unread message

Lior Kinsbruner

unread,
May 15, 2016, 10:33:02 AM5/15/16
to testng...@googlegroups.com
Hi,
I am having problems in using in my test classes of using both Parameters and data providers under the same test method (it seems like it ignore the Parameters annotations when having data provider defined - If I remove the data provider and only use the Parameters annotations it works fine). Any ideas how to use both??
See sample code on how I want to use this:

@Parameters({ "browser" })
@Test(groups = { "seleniumCadImport"}, dataProviderClass = DataProviderCadImport.class, dataProvider = "SECadImportTests")
public void testImportCadFile(SEUser seUsr,boolean showSiteList,String dxfFilePath,int tiltValue,int azimuthValue,String ExpectedNumberOfPanels,int expNumOfGroups,Object[][] expObj)
throws Exception {.....}

Thanks,
Lior

--
Lior Kinsbruner
Email: lior...@gmail.com
Phone: +972-54-7990307

⇜Krishnan Mahadevan⇝

unread,
May 15, 2016, 11:36:49 PM5/15/16
to testng...@googlegroups.com
Lior,

Here's what I know.

@Parameters and @DataProvider are two different ways in which you can parameterise a @Test method. The former lets you parameterise your @Test from a suite xml, while the latter lets you parameterise a @Test method from a data source [ DB/xml/json/excel/csv/yaml/txt]. So technically speaking it doesn't make sense for you to couple them.

But if you do need to do it, you can do it as below :

Test code
public class DataProviderWithParameter {

@Test (dataProvider = "dp")
public void testMethod(int age, String name) {
System.err.println("(" + name + "," + age + ")");

}

@DataProvider (name = "dp")
public Object[][] getData(ITestContext ctx) {
String name = ctx.getCurrentXmlTest().getLocalParameters().get("name");
return new Object[][] {{1, name}, {2, name}};
}
}
Suite XML :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Class1Suite" parallel="false" verbose="2">
<test name="Class1Test">
<parameter name="name" value="TestNG"/>
<classes>
<class name="organized.chaos.forums.DataProviderWithParameter"/>
</classes>
</test> <!-- Class1Test -->
</suite> <!-- Class1Suite -->
Output :
[XmlSuite] [WARN] 'parallel' value 'false' is deprecated, default value will be used instead: 'none'....
... TestNG 6.9.11 by Cédric Beust (ced...@beust.com)
...

[TestNG] Running:
  /Users/krmahadevan/githome/PlayGround/testbed/src/test/resources/dp-with-parameter.xml
(TestNG,1)
(TestNG,2)

===============================================
Class1Suite
Total tests run: 2, Failures: 0, Skips: 0
===============================================


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

Lior Kinsbruner

unread,
May 16, 2016, 2:10:37 AM5/16/16
to testng...@googlegroups.com
Thanks a lot for the quick answer, will review that and see if it solves my problem

Regards,
Lior

Julien Herr

unread,
May 16, 2016, 1:14:33 PM5/16/16
to testng-users
@Parameters may work on a @DataProvider method too.

If not, it could be a nice improvement.

Reply all
Reply to author
Forward
0 new messages