如何在soapUI中使用groovy删除测试步骤

时间:2016-09-20 06:42:04

标签: groovy soapui

有人可以建议如何使用groovy删除SoapUI中的测试步骤吗?

在我的项目中,我有一个REST测试请求,可以动态生成和执行。提交请求后,我想使用groovy脚本自动删除此步骤。

我尝试过类似的事情:

testRunner.testCase.removeTestStep( "Trigger_REST_Request" );

但这会返回错误:

groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.removeTestStep()
 is applicable for argument types: (java.lang.String) values: [Trigger_REST_Request]
 Possible solutions:     
    removeTestStep(com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep), 
    moveTestStep(int, int) groovy.lang.MissingMethodException

谢谢!

那是有效的......有点儿。当我添加建议的两行时,我可以看到测试步骤已被删除,但是,我现在也收到了NullPointerException。因此,在返回NPE后退出测试套件。这是我得到的NPE错误:

Wed Sep 21 09:27:11 EST 2016:ERROR:java.lang.NullPointerException
   java.lang.NullPointerException
    at com.eviware.soapui.model.support.ModelSupport.dependsOn(ModelSupport.java:196)
at com.eviware.soapui.impl.wsdl.teststeps.actions.ShowMessageExchangeAction$MessageExchangeDesktopPanel.dependsOn(ShowMessageExchangeAction.java:203)
at com.eviware.soapui.ui.desktop.AbstractSoapUIDesktop.closeDependantPanels(AbstractSoapUIDesktop.java:101)
at com.eviware.soapui.ui.desktop.AbstractSoapUIDesktop$InternalTestSuiteListener.testStepRemoved(AbstractSoapUIDesktop.java:190)
at com.eviware.soapui.impl.wsdl.WsdlTestSuite.fireTestStepRemoved(WsdlTestSuite.java:277)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.removeTestStep(WsdlTestCase.java:577)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase$removeTestStep.call(Unknown Source)
at Script9.run(Script9.groovy:19)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:92)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:141)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.runTestStep(AbstractTestCaseRunner.java:211)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner.runCurrentTestStep(WsdlTestCaseRunner.java:47)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:138)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:46)
at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.run(AbstractTestRunner.java:129)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)    

1 个答案:

答案 0 :(得分:0)

如果您需要删除测试步骤,请使用以下代码:

def tc = testRunner.testCase
def tbr = tc.getTestStepByName('ToBeRemoved')
if (tbr != null) { 
  tc.removeTestStep(tbr)
}

该脚本还处理ToBeRemoved测试步骤不存在时的情况。