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

落花浮王杯 提交于 2020-01-06 14:53:08

问题


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:


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.



来源:https://stackoverflow.com/questions/30738157/null-object-error-when-calling-code-from-script-assertion-soapui-creating-tes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!