如何使用Groovy脚本启用/禁用soapUI中的测试步骤(在每个测试用例内)基于用户想要启用或禁用的测试步骤

时间:2017-05-20 09:38:42

标签: groovy soapui

如何使用Groovy脚本启用/禁用soapUI中的测试步骤(在每个测试用例中)根据用户想要启用或禁用的测试步骤。
喜欢:

  • 如果我有一个测试用例,那么测试用例有10个步骤。我只想执行那些以Online开头的测试用例。
  • 如果我有一个测试用例并且测试用例有10步。我只想执行那些以Batch开头的测试用例。

请在下面找到抛出错误的样本:
Sat May 20 11:35:14 CEST 2017:ERROR:An error occurred [java.lang.NullPointerException], see error log for details while executing the next test cases.

代码:

context.testCase.testSuite.getTestCaseList().each
 {
    log.info "Test Case : ${it.name}".toUpperCase();
    it.testStepList.each 
    {
           log.info "Test Step--> : ${it.name}"

         def testStep = testRunner.testCase.getTestStepByName( "${it.name}" 
         log.info testStep.disabled
         if( testStep.disabled )
         {
            testStep.disabled = false

         }

      testRunner.testCase.getTestStepByName("${it.name}").setDisabled(true)
            log.info testStep.disabled
            log.info "Action Perfomed for Test Step : ${it.name}"

    }
 }

1 个答案:

答案 0 :(得分:0)

在您的代码示例中, def testStep = testRunner.testCase.getTestStepByName( "${it.name}"是不必要的。它在testSuite中查找一个带有特殊名称的testStep,其中包含您运行的脚本,但不会出现NullPointer异常。 它可以简单地替换为'

context.testCase.testSuite.getTestCaseList().each
{
    log.info "Test Case : ${it.name}".toUpperCase();
    it.testStepList.each 
    {
         log.info "Test Step--> : ${it.name}"

         log.info it.disabled
         if( it.disabled )
         {
            it.disabled = false
         }

        it.setDisabled(true)
        log.info it.disabled
        log.info "Action Perfomed for Test Step : ${it.name}"
    }
}