Kong / insomnia

The open-source, cross-platform API client for GraphQL, REST, WebSockets, SSE and gRPC. With Cloud, Local and Git storage.
https://insomnia.rest
Apache License 2.0
34.87k stars 1.97k forks source link

Bug when running a folder of request #8148

Open akramsarkis opened 1 week ago

akramsarkis commented 1 week ago

Expected Behavior

I have a folder of requests, the aim is to run the folder to test scenarios.

Variables set are not used in the next query of the folder - I have a login request from which I am setting variables to use them for my next request ```` insomnia.test("Verify login status code", () => { // Extract values from the response and set them as environment variables console.log(insomnia.response.json().token) // Set variables insomnia.variables.set('token_admin', insomnia.response.json().token.token); insomnia.variables.set('project_id', insomnia.response.json().projects[0].saas_project_id); // Log the values to confirm console.log('token_admin:', insomnia.variables.get('token_admin')); console.log('project_id:', insomnia.variables.get('project_id')); // Verify the response status code insomnia.expect(insomnia.response.code).to.eql(200); }); ```` - When adding a pre request script to my next query to use them, I am expecting to have the values set used ```` // Log the existing variables to ensure they are available console.log(insomnia.variables.get('token_admin')); console.log(insomnia.variables.get('project_id')); ````
In the pre request of a query I am generating I value I want to use as path parameter and it is not In the pre request of a query I am generating I value I want to use as path parameter and I am expecting it to work ```` // Log the existing variables to ensure they are available console.log(insomnia.variables.get('token_admin')); console.log(insomnia.variables.get('project_id')); // Function to generate a random alphanumeric string of specified length function generateRandomString(length) { let result = ''; const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; const charactersLength = characters.length; for (let i = 0; i < length; i++) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); } return result; } // Generate a random string of length 8 const randomString = generateRandomString(8); const sectionname = `section+${randomString}`; // Set the generated section name to a variable insomnia.variables.set("generated_sectionname", sectionname); // Log the generated section name to confirm console.log('Generated Section Name:', sectionname); ````

Actual Behavior

1) For the first point the actual behaviour is to not use set variables in the next query, it is using the values I have set in my environment variable

Here the variable set by the first login query


< HTTP/2 200 
< date: Mon, 04 Nov 2024 15:00:57 GMT
< content-type: application/json; charset=utf-8
< content-length: 677
< access-control-allow-origin: https://sections.geeks.solutions
< cache-control: max-age=0, private, must-revalidate
< x-request-id: 3b95b8b832490e88cad4645cb7c4a9de
< strict-transport-security: max-age=15724800; includeSubDomains

* Received 677 B chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Connection #1 to host api.sections.geeks.solutions left intact
* log: "warning: No environment is selected, modification of insomnia.environment will be applied to the base environment."
* log: {
*   "type": "login",
*   "token": "SFMyNTY.g2gDdAAAAARtAAAADGxvZ2luX2ZpZWxkc3QAAAABbQAAAAVlbWFpbG0AAAAdYS5zYXJraXMrMnU0YTRjcWY1bEBld2Vldi5jb21tAAAAEXByb2plY3RfbG9nZ2VkX2lubQAAABg1ZmE5MzNkMGU4ZGIxOTAwMDE3MWY2NzZtAAAACnRva2VuX3R5cGVtAAAABm5vcm1hbG0AAAAHdXNlcl9pZG0AAAAYNjcxOGIwNzg4NTlmOTUwMDA3MTVjNmE2bgYAhH6x95IBYgABUYA.0KJQn9p5DnSTOtCR9b7_60lHl27P0vTxs43ZQi_DV8g"
* }
* log: "token_admin:"
* "SFMyNTY.g2gDdAAAAARtAAAADGxvZ2luX2ZpZWxkc3QAAAABbQAAAAVlbWFpbG0AAAAdYS5zYXJraXMrMnU0YTRjcWY1bEBld2Vldi5jb21tAAAAEXByb2plY3RfbG9nZ2VkX2lubQAAABg1ZmE5MzNkMGU4ZGIxOTAwMDE3MWY2NzZtAAAACnRva2VuX3R5cGVtAAAABm5vcm1hbG0AAAAHdXNlcl9pZG0AAAAYNjcxOGIwNzg4NTlmOTUwMDA3MTVjNmE2bgYAhH6x95IBYgABUYA.0KJQn9p5DnSTOtCR9b7_60lHl27P0vTxs43ZQi_DV8g"
* log: "project_id:"
* "6718b071f3a99d0007b11478"

And as you can see in the next query it is not using them , the token is not the correct one and project id is the one I set in my env variables


> POST /api/v1/project/6718b071f3a99d0007b11478/section-types/:name HTTP/2
> Host: api.sections.geeks.solutions
> content-type: application/json
> token: SFMyNTY.g2gDdAAAAARtAAAADGxvZ2luX2ZpZWxkc3QAAAABbQAAAAVlbWFpbG0AAAAdYS5zYXJraXMrMnU0YTRjcWY1bEBld2Vldi5jb21tAAAAEXByb2plY3RfbG9nZ2VkX2lubQAAABg1ZmE5MzNkMGU4ZGIxOTAwMDE3MWY2NzZtAAAACnRva2VuX3R5cGVtAAAABm5vcm1hbG0AAAAHdXNlcl9pZG0AAAAYNjcxOGIwNzg4NTlmOTUwMDA3MTVjNmE2bgYAAhDPuJIBYgABUYA.j0CcgeLsv4BDZJMIsfTD4xdsqf_yLLO03SeujQtIUmo
> origin: https://sections.geeks.solutions
> accept: */*
> content-length: 102

2) Fo the second point as you can see below for the name path parameter I have configured the value I am generating in the pre request of the query

Screenshot 2024-11-04 at 17 03 21

And what is happening is that it is trying to create for me a section called ":name" instead of creating a section with the value of name param

Reproduction Steps

A) First point about variables not used in the next query

  1. Configure the login query making sure in your After response script to set token and project id variable
  2. Configure the create static section query making sure in the pre request script you add the necessary to use the variables set
  3. Run the folder including as first request the login one and as second one the create static option

B) Second point about path variable value not taken into consideration

  1. Configure the login query making sure in your After response script to set token and project id variable
  2. Configure the create static section query making sure in the pre request script you add the necessary to use the variables set
  3. Configure the create static section making sure in the pre request script to generate a random alphanumeric value and to use it for your name Path param
  4. Run the folder including as first request the login one and as second one the create static option

Is there an existing issue for this?

Additional Information

No response

Insomnia Version

10.1.1

What operating system are you using?

macOS

Operating System Version

macOS Monterey version 12.7.6

Installation method

From internet, I downloaded it and installed it

Last Known Working Insomnia version

No response

ihexxa commented 1 week ago

It looks like that the lifecycle of insomnia.variables.set effect should be extended to the whole runner execution, thanks for the very detailed report and Ill look into it.

akramsarkis commented 1 week ago

Thank you, waiting for your update

akramsarkis commented 1 day ago

fix(runner): extend insomnia.variables.set lifetime to whole execution period #8157

Hello @ihexxa ,

How are you?

Is the fix above applied and the problem I mentioned is fixed ?

Best regards, Akram

ihexxa commented 1 day ago

Hello @akramsarkis,

Thanks you and I'm doing well. Yes, this is the fix for the UI and hopefully we could release a beta this week.

Best, George