问题
i want to select multiple methods based on the name of the methods using bean shell script in testNG.xml.This is my current testng.xml
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="methodsuite">
<test name="test1" >
<method-selectors>
<method-selector>
<script language="beanshell">
<![CDATA[
String str=System.getProperty("testToRun");
testngMethod.getMethodName().contains(str);
]]>
</script>
</method-selector>
</method-selectors>
<packages>
<package name=".*"></package>
</packages>
</test>
</suite
Here i am able to select one method at a time.is it possible to select multiple mmethods using beanshell script?Or can i make use of looping/is looping allowed in the beanshell?
回答1:
Of course you can select multiple tests in BeanShell script. Basically TestNG calls your script for each @Test
method found in your suite (e.g. defined in <packages>
) and pass additional variables (http://testng.org/doc/documentation-main.html#beanshell) to it. You can define own functions here etc. Only important condition is - you have to return true/false if you want or not to include 'current' method to test suite. So if you for example change your script to:
<script language="beanshell">
<![CDATA[
String str = System.getProperty("testPerformance");
testngMethod.getMethodName().startsWith(str);
]]>
</script>
All tests which name starts with testPerformance
will be included in test suite.
来源:https://stackoverflow.com/questions/29897752/bean-shell-script-in-testng