簡體   English   中英

SoapUI - 使用Groovy Script在標記之間提取XML值

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM