null object error when calling code from script assertion - soapui (creating test Runner in script assertion)

1.8k Views Asked by At

In a soapui groovy script test step I've this.

context.setProperty("searchA", new searchA());
class searchA{

    def testRunner
    def searchA(testRunner){
        this.testRunner=testRunner
        }

    def search(a,b){

        def search_TestCase = testRunner.testCase.testSuite.getTestCaseByName("Search")
          search_TestCase.setPropertyValue("ABC", a)
          search_TestCase.setPropertyValue("DEF", b)
          search_TestCase.run(new com.eviware.soapui.support.types.StringToObjectMap(), false)

        }
    }

and in an assertion script in a different test suite I am calling the above code like this.

scripts = messageExchange.modelItem.testStep.testCase.testSuite.project.testSuites["Test"]
scripts.testCases["Lib123"].testSteps["TestLib123"].run(context.getTestRunner(),context)
context.searchA.search("value1","value2")

but this gives me error "can not get property testCase on null object". whats wrong here?

1

There are 1 best solutions below

0
On BEST ANSWER

I am not seeing null object error now. The issue was that testRunner is not available in script assertion so we need to create it like this in script assertion and then pass it in the caller method.

import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner
import com.eviware.soapui.support.types.StringToObjectMap
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext

testCase = messageExchange.modelItem.testStep.testCase
tcRunner = new WsdlTestCaseRunner( testCase, new StringToObjectMap() );

context.searchA.search("value1","value2",tcRunner)

This thread helped me.