Forum Discussion

RohitBBorse's avatar
RohitBBorse
Contributor
15 years ago

GroovyUtils.getXmlHolder - returning java.lang.NullPointerEx

Hi

The below script is returning java.lang.NullPointerException.


def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )

TestCase = context.testCase
StepCnt = TestCase.testStepCount

for (int i in 1..<StepCnt)
{
teststep=context.testCase.getTestStepAt(i).getLabel()
holder = groovyUtils.getXmlHolder(""+teststep+"#Response")
}


Any help is greatly appreciated.


Thanks
Rohit Borse

2 Replies

  • Hi!

    I think the reason for this is that you are assuming that

    ""+teststep+"#Response"

    will always resolve to an actual response; if the teststep has not been run or if the testStep is of a type that doesn't have a response you will get this error

    maybe you could modify your script to contain:

    ...

    for (int i in 1..<StepCnt)
    {
    def step = context.testCase.getTestStepAt(i)
    if( step instanceof com.eviware.soapui.model.testsuite.SamplerTestStep && step.testRequest.response != null )
    {
    holder = groovyUtils.getXmlHolder( step.name+"#Response")
    }
    }

    ...

    Does that help?

    regards,

    /Ole
    eviware.com
  • Hi,

    Sorry for late reply. I was away from office for the days.

    This have helped me and i have successfully stepped up to the next level.

    Thanks a lot

    Here is a code snippet


    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )

    for (int i in 0..<context.testCase.testStepCount)
    {
    step=context.testCase.getTestStepAt(i)
    if( step instanceof com.eviware.soapui.model.testsuite.SamplerTestStep && step.testRequest.response != null )
    {
    Response = groovyUtils.getXmlHolder(step.name+"#Response")
    Severity = Response.getNodeValue("//*:Severity")
    log.info (Severity)
    }
    }



    Thanks
    Rohit Borse