【问题标题】:Running specific test step in SoapUI based on testSuite property基于 testSuite 属性在 SoapUI 中运行特定的测试步骤
【发布时间】:2017-01-06 18:47:41
【问题描述】:

我是脚本新手,需要一些帮助。我有一个关于 SoapUI groovy 脚本的问题,我可以使用帮助。

我需要一个脚本,它可以让我根据 testSuite 属性的值('CC1' 是属性的名称)在 testCase 中运行特定的 testStep,有 5 种可能性。我猜可以使用switch/case,但不知道如何正确写。

目前我尝试使用这个:

def CC1 = testRunner.testCase.testSuite.getPropertyValue("CC1")
log.info testRunner.testCase.testSuite.getPropertyValue("CC1")

switch(CC1)  
{  
  case ~/^[H1]+$/: testRunner.runTestStepByName( "PT02_H1" ); break;  
  case ~/^[Y5]+$/: testRunner.runTestStepByName( "PT02_Y5" ); break;  
  case ~/^[Q2]+$/: testRunner.runTestStepByName( "PT02_Q2" ); break;  
  case ~/^[T5]+$/: testRunner.runTestStepByName( "PT02_T5" ); break;  
  default : testRunner.runTestStepByName( "PT02_AQ" );  
}

但没有运行所需的步骤。

有人可以帮我解决这个问题吗?

【问题讨论】:

  • 为什么两个问题合二为一?
  • 我为一个问题编辑了帖子。
  • 你的测试用例是什么样的?上述 groovy 脚本和其他 5 个测试步骤(您想要执行其中一个)是否在同一个测试用例中?你看过Conditional goto 测试步骤吗?

标签: groovy soapui


【解决方案1】:

尝试以下脚本(从 groovyTestStep 运行):

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
def testCase = testRunner.testCase;
def testStep = null;
def CC1 = testRunner.testCase.testSuite.getPropertyValue("CC1")
log.info testRunner.testCase.testSuite.getPropertyValue("CC1")

switch(CC1)  
{  
  case ~/^[H1]+$/: testStep = testCase.getTestStepByName( "PT02_H1" ); break;  
  case ~/^[Y5]+$/: testStep = testCase.getTestStepByName( "PT02_Y5" ); break;  
  case ~/^[Q2]+$/: testStep = testCase.getTestStepByName( "PT02_Q2" ); break;  
  case ~/^[T5]+$/: testStep = testCase.getTestStepByName( "PT02_T5" ); break;  
  default : testStep = testCase.getTestStepByName( "PT02_AQ" );  
}
testRunner = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner(testCase, null);
testStepContext = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext(testStep);
testStep.run(testRunner, testStepContext);
log.info "TEST OK:"+testStep.getName();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多