Forum Discussion

sboris's avatar
sboris
Occasional Contributor
4 years ago

How to reuse a groovy teststep inside the project assertion scripts

I have a working groovy test script (a helper Cookie class with instance creation inside the script):

context.setProperty("Cookie", new Cookie(log, context, testRunner))

and re-using the Cookie:

 

project = testRunner.testCase.testSuite.project;
testStep = project.testSuites["Helpers"].testCases["Objects"].testSteps["Cookie"];
testStep.run(testRunner, context);

log.info context.Cookie.info()

 

 

Runs fine from other groovy scripts in the project. But I need to re-use the code in the assertion scripts as well.
Tried

 

 

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

//def Runner = new WsdlTestCaseRunner(messageExchange.modelItem.testStep.testCase, new StringToObjectMap());
def Runner = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner(
    messageExchange.modelItem.testStep.testCase, new com.eviware.soapui.support.types.StringToObjectMap());
    
def mySteps= messageExchange.modelItem.testStep.testCase.testSuite.project.testSuites["Helpers"].testCases["Objects"].testSteps["Cookie"];
mySteps.run(Runner,context);

log.info mySteps.name
log.info context.Cookie.info()

 

 

but got 

name is ok; Runner is a valid instance. But Cookie is null.

 

Error in assertion script of the [Login - Unregistered Mobile User Login] test step: Cannot invoke method info() on null object

 

 

Can anyone help me solve the problem, please...
Script library works fine but is not an appropriate case as it requires additional permissions to write to the destination folder - a jenkins job on a cluster...

  • I didn't find the problem during step-by-step debugging. It started working (have no explanation):

    import com.eviware.soapui.support.types.StringToObjectMap
    import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner
    
    def runner = new WsdlTestCaseRunner(messageExchange.modelItem.testStep.testCase, new StringToObjectMap());
    
    def mySteps = messageExchange.modelItem.testStep.testCase.testSuite.project.testSuites["Helpers"].testCases["Objects"].testSteps["Cookie"];
    mySteps.run(runner,context);
    
    log.info context.Cookie.info()
    def cookies = context.Cookie;
    log.info cookies.info()
    log.info context.getProperty("Cookie").info()

     

  • sboris's avatar
    sboris
    Occasional Contributor

    I didn't find the problem during step-by-step debugging. It started working (have no explanation):

    import com.eviware.soapui.support.types.StringToObjectMap
    import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner
    
    def runner = new WsdlTestCaseRunner(messageExchange.modelItem.testStep.testCase, new StringToObjectMap());
    
    def mySteps = messageExchange.modelItem.testStep.testCase.testSuite.project.testSuites["Helpers"].testCases["Objects"].testSteps["Cookie"];
    mySteps.run(runner,context);
    
    log.info context.Cookie.info()
    def cookies = context.Cookie;
    log.info cookies.info()
    log.info context.getProperty("Cookie").info()