Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
166 views
in Technique[技术] by (71.8m points)

How to use CSV Data Set with junit request test in jmeter

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(); 
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...