Please study this simple example:
You will notice that the envinroment variable called url
is successfully set to the value "fact"
, but it is ephemeral. The sequence of events is:
- We set the
url
environment variable to"fact"
from the Request’s pre-request script. - We get the
url
environment variable, and receive"fact"
, and log it to the console as evidence. - We make the Request, which binds
url
into the URL, but receiveundefined
; the URL is wrong. - We check the environment afterwards and find that
url
isundefined
The begs the following questions:
- Is the variable in the URL of the request is resolved before the pre-request script executes?
- Given that we retrieved the
url
variable during the pre-request script and logged it to the console, seeing the expected value -"fact"
, why was the environment variableundefined
by the time the Test ran? Was it unset immediately after it was set in the Request’s pre-request script, before the Request actually executed? If so, why?
Given the above example, this following example would suggest that the URL for the request is indeed resolved before the pre-request script is run (which is as confusing as it is vexing):