grafana/postman-to-k6

"Missing Postman environment" error message from the converted script

TamiTakamiya opened this issue · 6 comments

Hello. I converted a Postman collection using postman-to-k6 tool and tried to execute the generated script, but got the error message "Missing Postman environment". I used the postman-to-k6 tool before and did not see that message at that time and I think that this would be related to the changes made with #13 but I have no idea what I should do. Any suggestions are appreciated.

Hello Tami. Good find. That happens when the postman environment variable APIs are used when no environment has been supplied. The docs say it's unavailable in that case, but perhaps it is valid and should default to an empty environment.

You should be able to workaround by switching from postman.*EnvironmentVariable() to pm.environment.set() etc. The pm APIs don't have that restriction.

Or alternatively, you could use -e to supply an environment file.

@bookmoons Thank you very much for your quick reply. I could resolve the error by supplying an environment file, but got another error message SyntaxError: invalid character '<' looking for beginning of value. Even though might be specific to our test case, if you know anything on this, please let me know. Thanks again.

@bookmoons Actually it was my mistake. I mis-typed a variable name and it was not found in the environment provided. I am closing this issue as resolved. Thank you for your assistance.

Good deal Tami. 👍

For future references:

  1. The original issue Missing Postman environment was actually resolved by changing the following portion of the generated code:
postman[Symbol.for("initial")]({
  options
});

to

postman[Symbol.for("initial")]({
  options,
  environment: {}
});
  1. The second problem SyntaxError: invalid character '<' looking for beginning of value was not related to Postman environment at all. The error was from the following line
        var jsonData = JSON.parse(responseBody);

and it simply meant the given string is not in JSON format.