简体   繁体   English

我如何在 jmeter groovy 脚本中使用 csv 变量?

[英]How do i use csv variables inside of a jmeter groovy script?

I have a test plan with a csv data set config set up like so: CSV Data set Config我有一个带有 csv 数据集配置的测试计划,设置如下: CSV 数据集配置

My csv file looks likes: CSV file我的 csv 文件看起来像: CSV 文件

My JSR223 Assertions looks like: JSR223 Assertion我的 JSR223 断言看起来像: JSR223 断言

I want to use those values in DJ for my assetions.我想在 DJ 中使用这些值作为我的资产。 I tried using vars.get("phmDownloadStatus") and ${phmDownloadStatus} inside of the groovy script but neither gets the value from the file.我尝试在 groovy 脚本中使用vars.get("phmDownloadStatus")${phmDownloadStatus} ,但都没有从文件中获取值。 How do i go about using these values?我该如何使用这些值?

You have to specify the variable names inside your csv data set config.您必须在 csv 数据集配置中指定变量名称。 Add the variable names for each column in your csv file separated by a comma delimiter as below为您的 csv 文件中的每一列添加变量名称,以逗号分隔符分隔,如下所示

在此处输入图片说明

Make sure to select ture for ignore first line as well if you are using headers.如果您使用标题,请确保为ignore first line选择ture

Now you should be able to use these values in your JSR223 Assertion.现在您应该能够在 JSR223 断言中使用这些值。

  1. To get variables from a CSV file first of all you need to create a CSV file configuration tab using Jmeter UI.要从 CSV 文件中获取变量,您首先需要使用 Jmeter UI 创建一个 CSV 文件配置选项卡。
  2. Then provide the source path of the SCV file and provide the names for variables as you want.然后提供 SCV 文件的源路径并根据需要提供变量的名称。

在此处输入图片说明

  1. When you are done with the configurations window should be something similar to this.当您完成配置窗口时,应该类似于此。 Then specify a delimiter to separate the data points for variables.然后指定一个分隔符来分隔变量的数据点。
  2. Then create a CSV file that aligns properly with the configurations you have defined.然后创建一个与您定义的配置正确对齐的 CSV 文件。 (Example set of data in the CSV according to the attached config is provided here) (此处提供了根据所附配置的 CSV 中的示例数据集)
 /t/3wso2.com/customers_3_1/1.0.0,3wso2.com,rkheSO1QK8DWLXKfYUJFrqXtHvAa,3bNiqxKVMAtpg9zdbcZQODP6qK4a /t/3wso2.com/customers_3_1/1.0.0,3wso2.com,f6inOQocRxm2qTmAkG3z9dNboOMa,CVsZlaVlg0WVlyqHc97bHQ6WCOca /t/3wso2.com/customers_3_1/1.0.0,3wso2.com,ZYJW0i02wSuyqlGB3WPWSvZGHYca,_cJLdQaeTo0j9gci5S2ELvaT_Yca

Your approach looks okayish, just make sure that your J_phmDownloadStatus and phmDownloadStatus JMeter Variables exist and have their respective anticipated values, you can check which variables are available for JMeter using Debug Sampler and View Results Tree listener combination您的方法看起来不错,只需确保您的J_phmDownloadStatusphmDownloadStatus JMeter 变量存在并具有各自的预期值,您可以使用Debug Sampler 和 View Results Tree 侦听器组合检查哪些变量可用于 JMeter

Just make sure:只要确保:

  1. To declare variable names which will be 100% matching the column names in your CSV file including case of every single letter because foo and Foo are absolutely different beasts from JMeter Variables perspective声明将与 CSV 文件中的列名 100% 匹配的变量名称,包括每个字母的大小写,因为从JMeter 变量的角度来看, fooFoo是完全不同的野兽
  2. Don't refer JMeter Variables in Groovy scripts as ${phmDownloadStatus} as JSR223 sampler will cache the first occurrence and will use it for all subsequent iterations不要将 Groovy 脚本中的 JMeter 变量作为${phmDownloadStatus}因为JSR223 采样器将缓存第一次出现并将其用于所有后续迭代

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

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