1
votes

I would like to iterate through an x amount of Test Steps and extract an XML value in Groovy

I have found something on StackOverflow that has worked and actually extracted the value. However, I was unable to implement a loop.

Here's a link! I found which was really useful; still I could not implement.

This is the script that I had found on here is :

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")

The Output of this is : Script-result : 023903122

The answer can be found here!

If anyone could help that would be great !

1
Can you show the screen shot of your test case? You want only process a particular step as you mentioned in your script? If so, iterate through an x amount of Test Steps is confusing. Please clarify. Use edit question to update. - Rao
Sorry, I would like to iterate through approximately 14 TestSteps and retrieve ("//*:number") - Armz
Well, please add the requested info - Rao
Hi Rao, here is the image imgur.com/PhxReAM - Armz
@Rao could you please help. Thank you. - Armz

1 Answers

0
votes

in your case the variable tcase references to TestCase object.

and you can use tcase.getTestStepCount() to get steps count and tcase.getTestStepAt(int index) to get step by index.

so to loop through the steps you can do like this

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() } " )
    }
}