如何根据用户输入使用 Jmeter 动态更改变量或值?
How to change variable or values on the fly with Jmeter based on user input?
我正在使用 JMeter
来测试一个 Web OE
站点,用户可以在其中 select 产品然后 select 宽度、高度、颜色和其他选项。根据宽度和高度返回不同的价格。
我使用脚本记录器记录了创建产品的步骤,但是在 HTTP Request
中,参数是使用设定值设置的。我可以使用 CSV
数据集更改 Width
和 Height
,但价格值似乎是硬编码的或基于脚本记录器设置的。我想不出让价格变量动态变化并根据变化进行更新或在宽度和高度变化时重新计算的方法。
我需要根据 CSV
引入的不同宽度和高度更改价格。测试的原因是我可以测试定价是否每次都相同对站点进行代码更改后。任何建议或示例都会有所帮助。
很可能 ItemPrice
值正在使用客户端 JavaScript 计算。
JMeter is not a browser, it works at protocol level. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages. Nor does it render the HTML pages as a browser does (it's possible to view the response as HTML etc., but the timings are not included in any samples, and only one sample in one thread is ever displayed at a time).
所以如果我的假设是正确的并且这个 ItemPrice
来自 JavaScript 你将无法通过修改参数来触发更改。
- 以某种方式获得根据维度计算价格的算法(查看页面源代码,四处询问,联系开发人员)
- 将 JSR223 PreProcessor 添加为请求的子项
- 即使 JavaScript 存在于 "language" 下拉列表
中,也请在 Groovy language 中实施您的登录
- 用生成的值替换记录的硬编码价格
我正在使用 JMeter
来测试一个 Web OE
站点,用户可以在其中 select 产品然后 select 宽度、高度、颜色和其他选项。根据宽度和高度返回不同的价格。
我使用脚本记录器记录了创建产品的步骤,但是在 HTTP Request
中,参数是使用设定值设置的。我可以使用 CSV
数据集更改 Width
和 Height
,但价格值似乎是硬编码的或基于脚本记录器设置的。我想不出让价格变量动态变化并根据变化进行更新或在宽度和高度变化时重新计算的方法。
我需要根据 CSV
引入的不同宽度和高度更改价格。测试的原因是我可以测试定价是否每次都相同对站点进行代码更改后。任何建议或示例都会有所帮助。
很可能 ItemPrice
值正在使用客户端 JavaScript 计算。
JMeter is not a browser, it works at protocol level. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages. Nor does it render the HTML pages as a browser does (it's possible to view the response as HTML etc., but the timings are not included in any samples, and only one sample in one thread is ever displayed at a time).
所以如果我的假设是正确的并且这个 ItemPrice
来自 JavaScript 你将无法通过修改参数来触发更改。
- 以某种方式获得根据维度计算价格的算法(查看页面源代码,四处询问,联系开发人员)
- 将 JSR223 PreProcessor 添加为请求的子项
- 即使 JavaScript 存在于 "language" 下拉列表 中,也请在 Groovy language 中实施您的登录
- 用生成的值替换记录的硬编码价格