mcdcorp / opentest

Open source test automation tool for web applications, mobile apps and APIs
https://getopentest.org
MIT License
446 stars 107 forks source link

Use the response from an API in the dataSet #632

Open adrian2096 opened 9 months ago

adrian2096 commented 9 months ago

Hi, I tried to use the JSON response of an Api in the dataSet but I get the message "Caused by: jdk.nashorn.internal.runtime.ParserException: :7:0 Invalid return statement return $output.body;"

dataSet: | $runAction("org.getopentest.actions.HttpRequest", { url: url, verb: GET }); return $output.body;

Would there be a way to use the API response in the dataSet?

adrianth commented 9 months ago

I never tried it, but I think an IIFE might do the trick:

dataSet: |
  (function() {
    var output = $runAction("org.getopentest.actions.HttpRequest", {
      url: url,
      verb: GET
    });

    return output.body;
  })();

Or a shorter syntax:

dataSet: |
  $runAction("org.getopentest.actions.HttpRequest", {
    url: url,
    verb: GET
  }).body;

Let me know if it worked.

adrian2096 commented 9 months ago

It worked, thanks for the help!

adrian2096 commented 9 months ago

Hello, I am using the solution from this issue and I am seeing that the call is being repeated in each iteration, I was expecting that the call to the dataSet would be made only once, is it possible to change this behavior?