testng 中的 Bean shell 脚本 [英] Bean shell script in testng

查看:24
本文介绍了testng 中的 Bean shell 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据testNG.xml中使用bean shell脚本的方法名称选择多个方法.这是我当前的testng.xml

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

这里我可以一次选择一种方法.是否可以使用 beanshell 脚本选择多种方法?或者我可以使用循环/在 beanshell 中是否允许循环?

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?

推荐答案

当然你可以在 BeanShell 脚本中选择多个测试.基本上,TestNG 会为套件中的每个 @Test 方法调用您的脚本(例如,在 中定义)并传递附加变量(http://testng.org/doc/documentation-main.html#beanshell) 到它.您可以在此处定义自己的函数等.唯一重要的条件是 - 如果您想或不包括当前"方法来测试套件,您必须返回真/假.因此,例如,如果您将脚本更改为:

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>

名称以 testPerformance 开头的所有测试都将包含在测试套件中.

All tests which name starts with testPerformance will be included in test suite.

这篇关于testng 中的 Bean shell 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆