Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...