javascriptinitializationrunscope

Runscope init timestamp variable before every request


I am using Initial Script to initialize few variables, one of them is a UTC timestamp connected value. I have 5 requests in my Test, first requests executed correct but last are not, because time connected variable is expired for API I test. I mean while first tests executed this variable is expired because my API is time sensitive.

Can I initialize some variables before every request, but not before all of them?

I know that I can create separate tests for every request but it's not cool and I want to hold all of them under one test.


Solution

  • One way is to update that variable with the current UTC at the ā€‹endā€‹ of each request using a script. You typically use the script to perform assertions; however, you can also use variable.set in a request's script.

    Another way is to use the {{timestamp}} function which returns the unix timestamp/epoch (seconds, not milliseconds).

    If you require the ISO-8601 format of UTC, you can also use {{utc_datetime}}.