在 Jmeter 中使用今天的日期作为变量
Use todays date as a variable in Jmeter
我需要使用 Jmeter 为一些 api 创建一个负载测试脚本,包括这个:
https://myserver01.net/alert/bydate/${今天}
现在我手动使用日期值,例如每天我手动更改请求中的日期值,例如今天我向 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 发送请求但不理解这些方法。就像第一种方法所说的在命令行中定义今天,这意味着我必须每年在每次启动 Jmeter 时都这样做。我想避免它并使其在脚本中自动化。
就像使用JMeter __time函数一样简单:
https://myserver01.net/alert/bydate/${__time(yyyy-MM-dd,)}
要测试功能,您可以使用功能助手对话框,它允许您测试:
- 在测试计划的某处添加 User Defined Variables 配置元素
在此处添加以下条目:
- 姓名:
Today
- 值:
${__groovy(new Date().format('yyyy-MM-dd'),)}
- 完成后,您可以在需要时将今天的日期称为
${Today}
更多信息:
- __groovy() function
- SimpleDateFormat 文档(
yyyy-MM-dd
模式的解释)
我需要使用 Jmeter 为一些 api 创建一个负载测试脚本,包括这个:
https://myserver01.net/alert/bydate/${今天}
现在我手动使用日期值,例如每天我手动更改请求中的日期值,例如今天我向 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 发送请求但不理解这些方法。就像第一种方法所说的在命令行中定义今天,这意味着我必须每年在每次启动 Jmeter 时都这样做。我想避免它并使其在脚本中自动化。
就像使用JMeter __time函数一样简单:
https://myserver01.net/alert/bydate/${__time(yyyy-MM-dd,)}
要测试功能,您可以使用功能助手对话框,它允许您测试:
- 在测试计划的某处添加 User Defined Variables 配置元素
在此处添加以下条目:
- 姓名:
Today
- 值:
${__groovy(new Date().format('yyyy-MM-dd'),)}
- 姓名:
- 完成后,您可以在需要时将今天的日期称为
${Today}
更多信息:
- __groovy() function
- SimpleDateFormat 文档(
yyyy-MM-dd
模式的解释)