如何在jmeter中将CSV数据集与junit请求测试一起使用 [英] How to use CSV Data Set with junit request test in jmeter

查看:570
本文介绍了如何在jmeter中将CSV数据集与junit请求测试一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了问题,困了两天,如何在构造函数字符串标签"中添加多个自变量构造函数? 当我在Junit中创建测试时,我使用两个参数创建了一个构造函数,但是在jmeter中,出现了一个问题,我告诉我由于没有一个String构造函数而无法创建实例.因此,在那之后,我发现jmeter只看到一个字符串构造函数或一个空的构造函数 请在这一点上帮助我,或者您是否建议其他方法将参数传递给jmeter中的Junit测试.

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.

有关更多详细信息,我想自动化IHM测试,并同时测量同时连接的用户的性能和支持人数.为此,我使用Junit和Selenium创建测试用例,将jar文件导出到apache jmeter下的junit文件夹中,创建junit请求并在构造函数字符串标签中传递"$ {login},$ {password}",最后创建Csv数据集配置,以从txt文件中获取登录名和密码.但是我遇到了由于缺少一个String构造函数而无法创建实例"的问题.我尝试将一个String构造函数与login一起使用,它可以很好地工作,并为我带来了txt文件形式的值,但是在构造函数中带有2个参数时,它不起作用,因为jmeter不支持它.您是否建议另一种替代方法:s:s:s请帮助.

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(); 
}

推荐答案

最后,幸运的是,我找到了解决问题的方法.我没有使用junit测试,而是使用jmeter-java测试来使用CSV数据集配置为每个会话使用不同的登录名和密码从jmeter运行不同的会话,并且本文对我非常有用:D

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;
}

这篇关于如何在jmeter中将CSV数据集与junit请求测试一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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