-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Environment variables don't get set from after-response scripts when using the test runner #7927
Comments
@ihexxa to take a look. |
Hello @suttonb as the difference between underlying mechanism, script capability is not supported in the original test tab at the moment. But the collection runner feature will be released in week so probably you could have a try with it, which supports all scripting interfaces. |
Ah, I totally missed that this was about the test suites. @suttonb we are in the process of supporting the new SDK into the test feature as well, but it's not ready yet. |
That sounds great, thank you! Will the collection runner have the ability to create customized run orders from the requests in the collection? For example, say I have a set of requests labeled A - F. I have one workflow where I want to run them all A - F in order, but I may have another workflow where I want to run A B C A D B F. Or another where I want to run D B E C F C A. Insomnia's test suites allow me to create those custom orders without needing to maintain multiple copies of the same requests, will the collection runner work the same way? |
The collection runner supports re-ordering requests, while it requires workaround if one request appears more than 1 time in the workflow. There are some minor differences between the original tests and the runner. |
Ok, thank you for the clarification! |
Hi! Can we use the collection runner for CI with inso CLI? we need to execute pre-request script and using test suites is not posible. |
@arkaitzosa within 30 days you will be able to do so. |
@subnetmarco hello. Could you please provide an update on fixing this issue? As I understand it, this issue is related to my problems as well: I can’t get folder environment variables in after-response scripts to execute tests there. I can only get global environment variables. However, if this variable is declared as a Variable from Response -> Body Attribute, it is read as a formula, not a value from the response. However, if I check this variable in Edit Tag - Live Preview, I see the correct value. |
Hello @NadjaKvalit, this issue is mainly related to the "test tab" and I believe your request is related to the scripting capability. We may prioritize the folder-level environment variables accessing after the collection runner is fully completed. However regarding the response body formula, it is only evaluated after the pre-request script has been executed together with other tags and so it is by design. |
Hello. I have a similar issue and don't know if this is related. If I set a variable in after-response, the value is not set to collection variables to be used in the next request I run by hand. But if I add a pre-request scirpt where I read the variable and add try to get it the the variable seems to be set just fine. This is my example:
Test two - pre-request script
And this works, but I would still like to add this through Headers or Auth part of the request. |
Hello @nomeaning25 , hm if you can't find the persisted variable in the environment modal, probably you could check the "base environment", as it is mapped from Postman's sdk. |
Where can I find that. If I click on my main folder and go under environment, the variable is there but its empty. It is not changed during the post-response script. |
@nomeaning25 You can find environment modal by clicking edit icon in the left-top part: Then choose the "base environment" (the top one but it could be renamed) and see if the variable field in the right json content. Besides, |
Yes, I can see the value here. How can I fetch it to the Headers tab? From base environment? Since _.variable is empty. I get nothing in Live Preview. Could the issue be in variable name? It's "access_token". Neither {{access_token}} under Custom or "_.access_token" works |
@nomeaning25 Here is a more detailed doc: https://docs.insomnia.rest/insomnia/environment-variables |
Yes, that is how I'm trying to access them but they are not filling from environment. Maybe the problem is that I also have the same variables set in Folder envirnomnet? This was created when I imported my Postman Collection. Can I save the variables there? Upon the After-response that was created after import was:
And it created the folder environment. EDIT: Yes, if I delete them from my Folder Settings and change my after-response script to store the variable in environment insetad od collectonVariables, then it works. But in case I import a large collection from Postman this would be a pain to fix all by hand. |
@nomeaning25 I removed the screenshot may might contain your credentials.
Yes, Insomnia reads variables by this order: folder envs -> selected workspace's environment (if exists) -> workspace base environment -> global selected env -> global base env.
There might be workaround currently, you could move content from "the top folder environment" to the base environment, that should work. |
Thank you. Will try that for now. |
I had the same issue, and the solution was create a Collection Environment, select it and execute the typical script after-response, var response = JSON.parse(insomnia.response.body)
insomnia.environment.set("variable", response.variable) |
Expected Behavior
I have a request that sets an environment variable in an after-response script. When running that request as part of a test run, I would expect the environment variable to be set after the request has run.
Actual Behavior
No environment variables have been set after the request has run.
Reproduction Steps
insomnia.environment.set("variable_name", "variable_value");
variable_name
Is there an existing issue for this?
Additional Information
No response
Insomnia Version
Version: Insomnia 9.3.3
Build date: 7/31/2024
What operating system are you using?
Windows
Operating System Version
Windows 11 Home version 23H2
Installation method
download from insomnia.rest
Last Known Working Insomnia version
No response
The text was updated successfully, but these errors were encountered: