Forum Discussion

rajs2020's avatar
rajs2020
Frequent Contributor
4 years ago

ReadyAPI - Understanding the result returned by a groovy script?

The docs say that a groovy script can return a result named as "result". See link - https://support.smartbear.com/readyapi/docs/functional/steps/groovy.html


I have some test steps which run/call a test case which contains a groovy script. I need to access the result of the script inside the custom properties of the test which calls that script. My questions -

1 - How to access the result returned by a groovy script ?
2 - How to return multiple values in the result & access them ?

thanks!

  • rajs2020 : By below way you can access the result returned by Groovy Script:

     

    def val = 1
    
    return val;

     How you can use:

    ${GROOVY_TEST_STEP_NAME#result}

     

    M not sure on how to return multiple value, my guess is you can use array for it or else you can use run time context variable

     

    set the context variable property,

    context.setProperty("val1",val1)
    context.setProperty("val2",val2)


    How to fetch it,

    log.info context.getProperty("val1")
    log.info context.getProperty("val2")

     

  • rajs2020 : By below way you can access the result returned by Groovy Script:

     

    def val = 1
    
    return val;

     How you can use:

    ${GROOVY_TEST_STEP_NAME#result}

     

    M not sure on how to return multiple value, my guess is you can use array for it or else you can use run time context variable

     

    set the context variable property,

    context.setProperty("val1",val1)
    context.setProperty("val2",val2)


    How to fetch it,

    log.info context.getProperty("val1")
    log.info context.getProperty("val2")