[英]SoapUI - Extract XML value between tags using Groovy Script
我想迭代x个测试步骤并在Groovy中提取XML值
我在StackOverflow上发现了一些工作并实际提取了值的东西。 但是,我无法实现循环。
这是一个链接 ! 我发现哪个非常有用; 我仍然无法实施。
这是我在这里找到的脚本是:
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")
输出结果为:Script-result: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() } " )
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.