如何使用beanshell脚本将数据写入jmeter中的csv [英] how to write data to csv in jmeter using beanshell scripting

查看:972
本文介绍了如何使用beanshell脚本将数据写入jmeter中的csv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是jmeter的新手,在我公司中,我们正在使用jmeter进行Web服务测试.我的要求是我正在使用csv数据配置文件进行Web服务测试,在这里我想用测试结果更新csv文件的每一行,并我正在使用beanshell后处理器,请帮助

I am new to jmeter,and in my company we are doing webservices testing using jmeter.My requirement is i am using csv data config file for web services testing and here i want to update each row of csv file with test results and i am using beanshell postprocessor,please help

例如: csv包含:

Test Case,Dates,Numbers,Results
Total test cases are 16 and i want to update as below for each test case
TC_001,9-03-2016,001,PASS
TC_002,9-03-2016,0002,FAIL

还有一个...

Result = "FAIL";
Response = prev.Get....();
If(Response.Contains("Valid"));
Results="PASS";
f = new FileOutputStream("/tmp/oders.csv", true);
p = new PrintStream(f); 
this.interpreter.setOut(p); 
print(Results + "," + Result);
f.close();
P.Close();

推荐答案

可能不是最好的主意,因为:

It might not be the best idea as:

  • 您可能在重新使用此文件时遇到问题
  • 您可能会遇到2个或更多线程同时写入文件的情况,这将导致数据丢失,文件损坏或IO异常

我建议您将测试用例",日期"和数字"变量添加到JMeter的.jtl结果文件中,而不要使用样本变量属性,例如:

I would recommend adding your "Test Case", "Dates" and "Numbers" variables to JMeter's .jtl results file instead using Sample Variables property like:

  1. 鉴于您有3个变量:TestCaseDateNumber
  2. 将以下行添加到 user.properties 文件(位于JMeter安装的/bin文件夹下)

  1. Given you have 3 variables: TestCase, Date and Number
  2. Add the following line to user.properties file (it is located under /bin folder of your JMeter installation)

sample_variables=TestCase,Date,Number

  • 在下一次重新启动JMeter时,您会看到"TestCase","Date"和"Number"变量值附加到.jtl结果文件中.
  • 也可以将设置作为命令行参数传递,例如:

    It is also possible to pass the setting as a command-line parameter like:

    jmeter -Jsample_variables=TestCase,Date,Number -n -t /path/to/testplan.jmx -l /path/to/results.jtl 
    

    参考文献:

    • Sample Variables
    • Apache JMeter Properties Customization Guide

    这篇关于如何使用beanshell脚本将数据写入jmeter中的csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆