rest - 如何在jmeter中使http请求中的搜索参数为动态的

标签 rest http testing jmeter jsr223

http 请求:http://ipAddress:Port/SomeResource?Param1=value1&Param2=value2& ……

等等。 这是 jmeter 中的 http 请求示例,它命中 rest api 并获得 JSON 格式的响应。

这里的挑战是 Param1、param2、param3 ....这些搜索参数编号不是恒定的,它可能会根据调用而变化,所以我正在制作一个 csv 文件,其中包含以逗号分隔格式包含搜索参数的行。

CSV file is like
param1,param2
param1,param2,param3
param1

我正在使用 CSV 数据配置从 csv 文件中提取数据并将其放入 http 请求

enter image description here

然后将其放入 http 请求中

enter image description here

现在,如果参数为空,我不想在 http 请求 header 中看到它 那么如何在 jmeter 中执行此操作。

最佳答案

  1. HTTP Request 中删除所有“参数” ,应该是干净的

    enter image description here

  2. 添加JSR223 PreProcessor作为您希望参数化的 HTTP 请求采样器的子级
  3. 将以下代码放入“脚本”区域:

    1.upto(4, {
        if (vars.get('param' + "$it") != null) {
            sampler.addArgument(vars.get('param' + "$it"),'someValue')
        }
    })
    
  4. 添加JSR223 PostProcessor作为您希望参数化的请求的子项
  5. 将以下代码放入“脚本”区域:

    1.upto(4, {
        vars.remove("param" + "$it")
    })
    
  6. 就是这样,你现在应该得到你需要的了。您不会在 JMeter GUI 中看到更改,您只能在运行时使用 View Results Tree 观察它们听众

    enter image description here

关于rest - 如何在jmeter中使http请求中的搜索参数为动态的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53386601/

相关文章:

.net - WebApi 中的条件 DataContract 序列化

java - 休息客户端异常 : Could not write request: no suitable HttpMessageConverter found for request type

http.Redirect 不工作

batch-file - 检查 Windows 批处理中的列表变量是否为空

python - 使用 Python 的 web.py 处理 POST 请求

java - 从 GET 请求中获取 Jersey 中的 header

java - 使用文件协议(protocol)的 Jmeter HTTP 请求未获取所有文件

Django 返回大文件

testing - 我怎么知道我是否可以成为一名优秀的软件测试员?

testing - 使用 dbunit 和 jetty 进行集成测试 - dbunit 不填充表