nhrcpt
nhrcpt

Reputation: 872

Use todays date as a variable in Jmeter

I need to create a load test script using Jmeter for the some apis including this one:

https://myserver01.net/alert/bydate/${Today}

Now I use the date value manually , e.g everyday I manually change the date value in the request , e.g today I sent a request to https://myserver01.net/alert/bydate/2018-02-09. I want to make it automated so that whenever I run the test it will take todays date by default. I have seen this answers in the link http://www.jmeter-archive.org/way-to-get-current-date-into-a-variable-td512937.html but did not understand the methods. Like the first method says to define today in command line, which means I have to do it annually every time I initiate Jmeter. I want to avoid it and make it automated inside the script.

Upvotes: 2

Views: 14613

Answers (2)

Dmitri T
Dmitri T

Reputation: 168147

  1. Add User Defined Variables configuration element somewhere to your Test Plan
  2. Add the following entry there:

    • Name: Today
    • Value: ${__groovy(new Date().format('yyyy-MM-dd'),)}
  3. Once done you will be able to refer today's date as ${Today} where required

More information:

Upvotes: 4

UBIK LOAD PACK
UBIK LOAD PACK

Reputation: 34566

It is as simple as using JMeter __time function:

https://myserver01.net/alert/bydate/${__time(yyyy-MM-dd,)}

To test functions, you can use Function Helper Dialog which allows you to test:

Function Helper Dialog

Upvotes: 3

Related Questions