1 回答

TA贡献1966条经验 获得超4个赞
从这里引用 TestNG 文档
为了方便起见,TestNG 定义了以下变量:
java.lang.reflect.Method
method
:当前的测试方法。
org.testng.ITestNGMethod
testngMethod
:当前测试方法的描述。
java.util.Map<String, String>
groups
:当前测试方法所属的组图。
ITestNGMethod
因此,您只需通过对象提取参数。
这是你如何做到的
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="54335160_suite" parallel="false" verbose="2" configfailurepolicy="continue">
<parameter name="groupToRun" value="foo"/>
<method-selectors>
<method-selector>
<script language="beanshell"><![CDATA[
grpParameter = testngMethod.getXmlTest().getParameter("groupToRun");
return groups.containsKey(grpParameter);
]]></script>
</method-selector>
</method-selectors>
<test name="54335160_test">
<classes>
<class name="com.rationaleemotions.stackoverflow.qn54335160.Qn54335160Sample">
</class>
</classes>
</test>
</suite>
添加回答
举报