Testng - walkthrough as parmers in testng.xml

Is it possible to pass a list in the testNG parameters. Below is a sample code

Example: trying to pass a list of numbers in XML. Not sure TestNG does not support this feature. Or am I missing something?

<suite name="Suite" parallel="none"> <test name="Test" preserve-order="false"> <parameter name="A" value="1"/> <parameter name="B" value="2"/> <parameter name="C" value="3"/> <parameter name="D" value="{4,5}"/> <classes> <class name="TestNGXMLData"/> </classes> </test> </suite> 

 import java.util.ArrayList; import java.util.Iterator; import java.util.List; import com.thoughtworks.selenium.Selenium; import static org.testng.Assert.assertTrue; import org.testng.annotations.*; import com.thoughtworks.selenium.*; public class TestNGXMLData { @Test @Parameters(value = { "A", "B", "C", "D" }) public void xmlDataTest(String A, String B, String C, ArrayList<String> ls) { System.out.println("Passing Three parameter to Test " + A + " and " + B + " and " + C); Iterator it = ls.iterator(); while (it.hasNext()) { String value = (String) it.next(); } } } 

Thanks, Siva

+6
java xml testng
source share
2 answers

You can only pass basic types like this, so you must declare your last parameter as "String" and then convert "{3, 4}" to a list. I suggest using "3 4" instead and just parse it with String # split.

If you want to pass more complex parameters, and you do not want to worry about conversion, switch to using @DataProvider.

+8
source share

In the guide, @Parameter can be used for simple parameters. For complex objects you should look @Dataprovider

0
source share

All Articles