Forum Discussion

shriya12's avatar
shriya12
Occasional Contributor
7 years ago

Unable to run groovy at test case level

I am unable to get response for groovy at test case level. While separately running the groovy getting response.

 

I am using groovy to trim the token from the email link. Need to use groovy result in next test step.

8 Replies

  • JHunt's avatar
    JHunt
    Community Hero

    If you don't use return, a groovy script returns the last thing it evaluated. In your case it's the info() method on Logger, which returned void.

     

    If you want to keep your log statement, just get your script to

     

    return a

     

    • shriya12's avatar
      shriya12
      Occasional Contributor

      I have added it but not working, only when individually I will run the script I am getting the result. I need to pass the script result in next test step.

       

      Please find the attached test case and the details for groovy script.

  • JHunt's avatar
    JHunt
    Community Hero

    Instead of returning a, try putting it into the context.

     

    context.a = a

     

    then in your request body:

     

    ${a} or ${=context.a}

  • raviraj's avatar
    raviraj
    Occasional Contributor

    Remove your 3rd line [log.info a]  from your code and then execute  your application
    you should get the result.

     

    regards,

    Raviraj.

    • shriya12's avatar
      shriya12
      Occasional Contributor

      I have deleted it but not working, only when individually I will run the script I am getting the result. I need to pass the script result in next test step.

       

      Please find the attached test case and the details for groovy script.

      • raviraj's avatar
        raviraj
        Occasional Contributor

        Hi,

         

        So in your next request [REST Request] add the following code 

         

        ${Copy of code_trim#result}

         

        in post payload section - and in Response view it in Outline tab.

         

        Regards,

        Raviraj.

  • shriya12's avatar
    shriya12
    Occasional Contributor

    I have added code to save the output in a file and getting data from the file. I am getting success response now.

     

    Thank you for your help.