SoapUI - 使用 Groovy 脚本在标签之间提取 XML 值
SoapUI - Extract XML value between tags using Groovy Script
我想遍历 x 数量的测试步骤并在 Groovy
中提取一个 XML 值
我在 Whosebug 上发现了一些有用的东西,并且实际提取了价值。但是,我无法实现循环。
这里是a link!我发现哪个真的很有用;我仍然无法实施。
这是我在这里找到的脚本:
def project = testRunner.testCase.testSuite.project ;
def tcase =
project.testSuites["Testsuite_name"].testCases["TestCase Name"] ;
def tstep = tcase.getTestStepByName("TestStep");
def responseTestSuite1 = tstep.getPropertyValue("response");
log.info(responseTestSuite1.toString());
def gutils = new com.eviware.soapui.support.GroovyUtils( context );
def holder = gutils.getXmlHolder("$responseTestSuite1");
def byteResponse = holder.getNodeValue("//*:number")
此输出为:脚本结果:023903122
答案可以找到!
如果有人能提供帮助那就太好了!
在您的例子中,变量 tcase
引用 TestCase 对象。
您可以使用 tcase.getTestStepCount()
获取步数,使用 tcase.getTestStepAt(int index)
按索引获取步数。
所以要循环执行这些步骤,您可以这样做
def tcase = context.getTestCase()
def stepCount = tcase.getTestStepCount()
for(int stepId = 0; stepId<stepCount; stepId++) {
def tstep = tcase.getTestStepAt(stepId)
if( tstep instanceof com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep ) {
//only if this wsdl test do something:
log.info( "label : ${ tstep.getLabel() } " )
log.info( " class : ${ tstep.getClass() } " )
log.info( " props : ${ tstep.getPropertyNames() } " )
}
}
我想遍历 x 数量的测试步骤并在 Groovy
中提取一个 XML 值我在 Whosebug 上发现了一些有用的东西,并且实际提取了价值。但是,我无法实现循环。
这里是a link!我发现哪个真的很有用;我仍然无法实施。
这是我在这里找到的脚本:
def project = testRunner.testCase.testSuite.project ;
def tcase =
project.testSuites["Testsuite_name"].testCases["TestCase Name"] ;
def tstep = tcase.getTestStepByName("TestStep");
def responseTestSuite1 = tstep.getPropertyValue("response");
log.info(responseTestSuite1.toString());
def gutils = new com.eviware.soapui.support.GroovyUtils( context );
def holder = gutils.getXmlHolder("$responseTestSuite1");
def byteResponse = holder.getNodeValue("//*:number")
此输出为:脚本结果:023903122
答案可以找到
如果有人能提供帮助那就太好了!
在您的例子中,变量 tcase
引用 TestCase 对象。
您可以使用 tcase.getTestStepCount()
获取步数,使用 tcase.getTestStepAt(int index)
按索引获取步数。
所以要循环执行这些步骤,您可以这样做
def tcase = context.getTestCase()
def stepCount = tcase.getTestStepCount()
for(int stepId = 0; stepId<stepCount; stepId++) {
def tstep = tcase.getTestStepAt(stepId)
if( tstep instanceof com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep ) {
//only if this wsdl test do something:
log.info( "label : ${ tstep.getLabel() } " )
log.info( " class : ${ tstep.getClass() } " )
log.info( " props : ${ tstep.getPropertyNames() } " )
}
}