开发者

testng - passing list as parmeters in testng.xml

开发者 https://www.devze.com 2023-02-17 09:18 出处:网络
Would it be possible to pass 开发者_运维百科a list in the testNG parameters. Below is sample code

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


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.


From the manual, @Parameter can be used for simple parameters. For complex objects, you should look at @Dataprovider

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号