jmeter java请求 csv,如何在jmeter中使用带有junit请求测试的CSV数据集

博主分享了在使用JUnit进行自动化测试并集成到JMeter时遇到的问题,即JMeter不支持带有两个参数的构造函数。通过转向使用JMeter的Java测试,结合CSV数据集配置,实现了不同登录和密码的多会话测试,从而同时自动化界面测试和性能测量。解决方案包括从JUnit请求中传递参数,并从CSV文件获取数据。
摘要由CSDN通过智能技术生成

I have a problem and I stuck in it for two days, how can I add more than one argument constructor in “ Constructor String label” ?????

When I created my test in Junit , I create a constructor using two arguments, but in jmeter , a problem occurred and me telling that it’s impossible to create an instance because of the absence of one String Constructor. So, after that, I discover that jmeter only see one string constructor or an empty one

Please help me on this point or do you suggest another alternative to pass argument to Junit test in jmeter.

For more details, I want to automate IHM tests and at the same time measure the performance and the supporting numbers of users that connect at the same time. To do that, I create my test Case using Junit and Selenium, export the jar file into junit folder under apache jmeter, creating junit request and passing “${login}, ${password}” in Constructor String Label, and finally creating the Csv Data set config to bring login and password from txt file. But I faced the problem of “impossible to create an instance because of the absence of one String Constructor”. I try to use one String constructor with login , it works very well and bring me value form txt file, but with 2 arguments in constructor it doesn’t work because jmeter didn't support it. Do you suggest another alternative :s :s :s please Help.

This is the code i have so far:

public void test() throws InterruptedException {

driver.get(baseUrl + "/"); //clear username filed

driver.findElement(By.id("username")).clear(); //enter user name

driver.findElement(By.id("username")).sendKeys(login); //clear password

driver.findElement(By.id("password")).clear(); //enter password

driver.findElement(By.id("password")).sendKeys(password); //click on submit button

driver.findElement(By.id("submit")).click();

}

解决方案

Finaly and fortunately, I found a solution to my problem. Instead of using junit test I used jmeter-java test to run diffrent session from jmeter with diffrent login and password for each session using CSV Data Set Config and this article was very useful to me :D http://www.javacodegeeks.com/2012/05/apache-jmeter-load-test-whatever-you.html/comment-page-1/#comment-8288 and instead of "testuser" in java request " ${login}" and "${password} instead of "testpasswd" to bring data from txt file related to CSV Data Set Config

And your test method will look like that (In my case i'm using selenium for test on browser)

public SampleResult runTest(JavaSamplerContext arg0) {

// TODO Auto-generated method stub

login = arg0.getParameter("login");

password=arg0.getParameter("password");

SampleResult result = new SampleResult();

boolean success = true;

result.sampleStart();

// Write your test code here.

//

driver.get(baseUrl + "/");

//clear username file

driver.findElement(By.id("username")).clear();

//enter user name

driver.findElement(By.id("username")).sendKeys(login);

//clear password

driver.findElement(By.id("password")).clear();

//enter password

driver.findElement(By.id("password")).sendKeys(password);

//click on submit button;

driver.findElement(By.id("submit")).click();

result.sampleEnd();

result.setSuccessful(success);

return result;

}

And getDefaultParameters

@Override

public Arguments getDefaultParameters() {

// TODO Auto-generated method stub

defaultParameters=new Arguments();

defaultParameters.addArgument("login", "ImenUser1");

defaultParameters.addArgument("password","ImenUser@");

return defaultParameters;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值