Would it be possible to pass a list in the testNG parameters. Below is sample code
Example: Trying to pass list of numbers in XML. Not sure if TestNG does not support this feature. Or am i missing anything?
<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
TestNG allows the user to pass values to test methods as arguments by using parameter annotations through testng. xml file. Some times it may be required for us to pass values to test methods during run time. Like we can pass user name and password through testng.
Parameterization In TestNG Using @Parameters Annotation & XML file. As of now, Parameters have been scoped to only Suite or Test tag in testng. xml file. If the same parameter value is passed in both Suite and Test, the priority is given to parameter value passed in the Test tag.
TestNG Parameters are present in the xml file. They can be applied either inside the tag or tag. If we want to apply the parameters to all the test cases, then the parameters are applied inside the tag.
You can only pass basic types like this, so you should declare your last parameter as a "String" and then convert "{3, 4}" to a List. I suggest using "3 4" instead and simply parse it with String#split.
If you want to pass more complex parameters and you don't want to bother with converting, switch to using a @DataProvider.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With