Use todays date as a variable in Jmeter
Solution 1
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:
Solution 2
- Add User Defined Variables configuration element somewhere to your Test Plan
-
Add the following entry there:
- Name:
Today
- Value:
${__groovy(new Date().format('yyyy-MM-dd'),)}
- Name:
- Once done you will be able to refer today's date as
${Today}
where required
More information:
- __groovy() function
-
SimpleDateFormat documentation (explanation of
yyyy-MM-dd
pattern)
nhrcpt
QA Automation Engineer Area of expertise: Python, Java, JavaScript, Protractor, Robot Framework, Karma, NightwatchJS
Updated on June 14, 2022Comments
-
nhrcpt almost 2 years
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.