Support persistent mutable environment to support cross file chaining
Problem to solve
Let's say you have a login.hurl which logins the user and captures the token in a variable. I would like to use this variable with any number of requests after that, possibly in multiple sessions.
Postman supports this using "tests" which is just javascript code where you can modify the environment.
Proposal
Support saving and loading variables to an environment file.
Support a new type of variable:
POST https://foo.com/login
...
HTTP 200
[Captures]
env:token = jsonpath "$.token"
For example:
Below command would load all the env variables from env.json at the beginning and save token to env.json at the end.
hurl --env=env.json login.hurl
A different hurl file could use this env like so:
hurl --env=env.json requests.hurl
requests.hurl
GET https://foo.com/api/things
Authorizaton: Bearer {{env:token}}
Additional context and resources
Tasks to complete
- [ ] ...
Hi @95th , Reading variables from a file is supported with the variable-file option.
Relating to writing variables to a file at the end of the test:
- it can be done currently from the JSON output with an additional command line using jq.
- we could maybe add a dedicated option for that. This seems very similar to reading/writing cookies to a file. Note that the curl/Hurl are not very intuitive (
--cookie, ---cookie-jar)
Note that the detailed steps to achieve this is explained in this comment: https://github.com/Orange-OpenSource/hurl/issues/1208#issuecomment-1405011439
I really wish there's a dedicated option, or a cleaner way to do this. Thanks. Appreciate it.