每个线程是否可以从CSV文件中选择同一行?
例如:我的CSV文件中只有5个用户和5条记录(行)。在每次迭代中,来自CSV的第一个值应该分配给User1,对于所有用户也是如此。
User1: myID1,pass1,item1,product1
User2: myID2,pass2,item2,product2
User3: myID3,pass3,item3,product3
User4: myID14,pass4,item4,product4
User5: myID15,pass5,item5,product5。。有解决办法吗?
发布于 2016-10-03 15:15:37
- Add setUp Thread Group to your Test Plan (with 1 thread and 1 iteration)
- Add Beanshell Sampler and put the following code into "Script" area:导入org.apache.commons.io.FileUtils;列表行=FileUtils.readLines(新文件(“test.csv”));bsh.shared.lines =行;
上面的代码将读取test.csv文件的内容(用CSV文件的相对路径或完整路径替换它),并将其存储到bsh.shared命名空间中。
- Add Beanshell PreProcessor as a child of the request where you need to use the values from the CSV file and put the following code into "Script" area:int user = ctx.getThreadNum();String line = bsh.shared.lines.get(user);String[]令牌= line.split(",");vars.put("ID",令牌);vars.put("pass",tokens1);vars.put("item",tokens2);vars.put(“产品”,tokens3);
上面的代码将从列表中提取行,并根据当前虚拟用户号存储在bsh.shared命名空间中,用逗号将其拆分,并将值存储到JMeter变量中,以便您能够访问它们,如下所示:
- `${ID}`
- `${pass}`
- `${item}`
- `${product}`
有关在如何使用BeanShell: JMeter最喜欢的内置组件测试中使用Beanshell脚本的更多信息,请参见JMeter指南。
https://stackoverflow.com/questions/39828727
复制相似问题