jmeter java csv,如何通过使用程序(Java代码)运行Jmeter测试来在Java代码中设置CSV文件?...

I have previously ask the question that how to log the results after running the jmeter test using a java program and then I have got this by myself so I am going to share the link of that question with answer for future references. So here is the link... How can I save a result set after running the Jmeter Test using a program (JAVA CODE)?

But now I have another question for this, How can I set a CSV file

here with a multiple logins, I have tried some code but it not

happened as I want. Can anyone please help me out from this ? And

please see the following code that I have tried.

package com.solitera.automation.controller;

import org.apache.jmeter.engine.StandardJMeterEngine;

import org.apache.jmeter.reporters.ResultCollector;

import org.apache.jmeter.reporters.Summariser;

import org.apache.jmeter.save.SaveService;

import org.apache.jmeter.testbeans.gui.TestBeanGUI;

import org.apache.jmeter.testelement.TestElement;

import org.apache.jmeter.util.JMeterUtils;

import org.apache.jorphan.collections.HashTree;

import java.io.File;

import java.io.FileInputStream;

public class JMeterFromExistingJMX {

public static void main(String[] argv) throws Exception {

//Set jmeter home for the jmeter utils to load

String jmeterHomelocation = "D:/apache-jmeter-5.1.1";

String jmeterPropertieslocation = jmeterHomelocation + "/bin/jmeter.properties";

// JMeter Engine

StandardJMeterEngine jmeter = new StandardJMeterEngine();

// Initialize Properties, logging, locale, etc.

JMeterUtils.loadJMeterProperties(new File(jmeterPropertieslocation).getPath());

JMeterUtils.setJMeterHome(new File(jmeterHomelocation).getPath());

// you can comment this line out to see extra log messages of i.e. DEBUG level

JMeterUtils.initLogging();

JMeterUtils.initLocale();

// Initialize JMeter SaveService

SaveService.loadProperties();

HashTree testPlanTree = SaveService.loadTree(new File("D:/apache-jmeter-5.1.1/extras/slt_auto_test_java_blaze_script.jmx"));

Summariser summer = null;

String summariserName = JMeterUtils.getPropDefault("summariser.name", "summary");

if (summariserName.length() > 0) {

summer = new Summariser(summariserName);

}

CSVDataSet csvDataSet = new CSVDataSet();

csvDataSet.setName("CSV Data Set Config");

csvDataSet.setProperty("delimiter",",password,submitLogin,userName");

csvDataSet.setProperty("filename", "D:/apache-jmeter-5.1.1/extras/CSVData.csv");

csvDataSet.setProperty("ignoreFirstLine", false);

csvDataSet.setProperty("quotedData", false);

csvDataSet.setProperty("recycle", true);

csvDataSet.setProperty("shareMode", "shareMode.all");

csvDataSet.setProperty("stopThread", false);

csvDataSet.setProperty("variableNames", "foo");

csvDataSet.setProperty(TestElement.TEST_CLASS, csvDataSet.getClass().getName());

csvDataSet.setProperty(TestElement.GUI_CLASS, TestBeanGUI.class.getName());

String logFile = "D:/apache-jmeter-5.1.1/extras/resultss.xml";

ResultCollector logger = new ResultCollector(summer);

logger.setFilename(logFile);

testPlanTree.add(testPlanTree.getArray()[0], logger);

// Run JMeter Test

jmeter.configure(testPlanTree);

jmeter.run();

}

}

Below is the images in which I have recorded a script using Blazemeter and add it to Jmeter GUI and please refer for the same for more information how my TestPlan actually looks like.

qL7Df.png

6pWJB.png

lR4P7.png

CSVData.csv file :

C2V1G.png

NOTE : This whole script I am trying to run through the Java code that I have shared above, If I run without CSV file with only one user login and set the No. of threads = 3 then the script runs fine.

解决方案

Just Remove everything from the "Variable Names" section of the CSV Data Set Config:

QlwoY.png

and your setup should start working as expected. Given you have "Ignore first line" set to False and the first line of your CSV file is the header, not the data you don't need to set any variable names there, JMeter will do it automatically.

You also don't need this CSVDataSet declaration/configuration in the code because:

It is not configured properly

It doesn't add any value as you're not adding it to the Test Plan

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值