简体   繁体   English

如何从 csv 文件中读取一行中的多个值以将正文作为 Jmeter 中的变量发布

[英]How to read multiple values in one row from csv file to post body as variable in Jmeter

How to make an Post HTTP request Body from multiple values in a single column from a CSV file?如何从 CSV 文件的单个列中的多个值创建 Post HTTP 请求正文?
In CSV file, under the transactional_currencies , I need to insert two or more values as per requirement.在 CSV 文件的transactional_currencies下,我需要根据要求插入两个或更多值。
在此处输入图像描述

This is the Json Body need to pass in Post HTTP request Body这是 Json Body 需要在 Post HTTP 请求 Body 中传递

{
    "country_name": "${country}",
    "status": "$ {status}",
    "transactional_currencies": ["${transactional_currencies[0]", "${transactional_currencies[1]"]
}``

在此处输入图像描述 `` ``

I'm not sure about what did you ask but let's give it a try我不确定你问的是什么,但让我们试一试

You should define a delimiter character in your CSV dataset config element.您应该在 CSV 数据集配置元素中定义一个分隔符。

For example例如


Single Line in our CSV: sample@sample.com,testusername,testpassword我们 CSV 中的单行:sample@sample.com,testusername,testpassword

  1. After adding a CSV data config to your project, open the configuration panel.在您的项目中添加 CSV 数据配置后,打开配置面板。
  2. Choose your delimiter character as ", " since the line above has some commas.选择您的分隔符作为“,”,因为上面的行有一些逗号。
  3. Choose variable names as "email", "username" and "password"选择变量名称为“电子邮件”、“用户名”和“密码”
  4. Now you have splitted a single csv line into 3 different variables.现在您已将单个 csv 行拆分为 3 个不同的变量。
  5. On your request's body, write these variables as ${email}, ${username}, ${password}在您的请求正文中,将这些变量写为 ${email}、${username}、${password}

Not with the CSV Data Set Config不适用于 CSV 数据集配置

If you have fixed number of entries in the transactional_currencies (ie always 2) you can use __CSVRead() function where you will be able to decide when to go to the next entry/row.如果您在transactional_currencies中有固定数量的条目(即始终为 2),您可以使用__CSVRead() function ,您可以在其中决定何时将 go 转到下一个条目/行。

If the number of entries in the transactional_currencies is dynamic, you can go for JSR223 PreProcessor and build your request body using Groovy language as it's described in the Apache Groovy - Parsing and producing JSON article如果transactional_currencies中的条目数是动态的,您可以 go 用于JSR223 预处理器并使用Groovy 语言构建您的请求主体,如Apache Groovy - 解析和生成 JSON文章中所述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM