New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pm.sendRequest in collection level global function #4404
Comments
@harryi3t Thank you for the sample and quick response.
Then call this global function from "Tests" tab of the request:
|
@andriikhmelkov Now I see what the issue is. Sharing scripts (in this case a global function) across scripts is not supported. It might look like it's working but that is due to an implementation bug. As mentioned here
Related issues There is a (not so good) workaround for this, putting the common functions into a variable (global, env or temp) and then // Collection pre-request script
function globalFunction () { ... }
pm.variables.set('globalFunction', globalFunction.toString())
// Request-1 test-script
var globalFunction = eval(pm.variables.get('globalFunction'));
globalFunction() Note: Above code is written on the fly and not tested so might require some tweeking. |
if you want to call
Note that, I declared function using arrow style |
Been a year, do we have something in progress so that we don't have to update a test in every request? |
I've worked around this issue in the following way
and then you can call it like this
|
App Details:
Issue Report:
requester.js:173357 foo
requester.js:173357 1
requester.js:173357 753348
requester.js:173357 386
Basically, after each pm.test pass/failure send a request to TestRail API with test case id and result pass/fail. In order to do so, I need a reusable function that will accept arguments "test case id" and "test case result" and send a request to the TestRail server.
The following code does the job if placed to the "Tests" tab of a single request, but doesn't work if placed into the collection level "Pre-request Scripts" or "Tests" tabs.
foo
gets printed to the console, along withtest case id
,status
, andtest run id
, butpm.sendRequest
doesn't work nor a reason whypm.sendRequest
failed printed to the console.There are no indications that simple requests to
https://postman-echo.com/get?test=123
from global collection level functions are successful as well. Seems likepm.sendRequest
doesn't like being placed into global collection level functions.The text was updated successfully, but these errors were encountered: