Bean shell script in testng

瘦欲@ 提交于 2019-12-23 15:53:31

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!