1

I am stuck at this point. I have used JUnit Sampler before successfully many times. But this time I get following error while trying to run simple program.

I have tried different version of jemeter. I copied the selenium server file to jemeter/lib I copied the jar file to lib/junit

I tried their test class and I tried my class

2014/11/05 16:27:23 INFO  - jmeter.protocol.java.sampler.JUnitSampler: Trying to find constructor with one String parameter returned error: test.BeforeAnnotatedTest.<init>(java.lang.String)** 

whole stack trace:

2014/11/05 16:27:23 INFO  - jmeter.engine.StandardJMeterEngine: Running the test! 
2014/11/05 16:27:23 INFO  - jmeter.samplers.SampleEvent: List of sample_variables: [] 
2014/11/05 16:27:23 INFO  - jmeter.gui.util.JMeterMenuBar: setRunning(true,*local*) 
2014/11/05 16:27:23 INFO  - jmeter.engine.StandardJMeterEngine: Starting ThreadGroup: 1 : Thread Group 
2014/11/05 16:27:23 INFO  - jmeter.engine.StandardJMeterEngine: Starting 1 threads for group Thread Group. 
2014/11/05 16:27:23 INFO  - jmeter.engine.StandardJMeterEngine: Thread will stop on error 
2014/11/05 16:27:23 INFO  - jmeter.threads.ThreadGroup: Starting thread group number 1 threads 1 ramp-up 1 perThread 1000.0 delayedStart=false 
2014/11/05 16:27:23 INFO  - jmeter.threads.ThreadGroup: Started thread group number 1 
2014/11/05 16:27:23 INFO  - jmeter.engine.StandardJMeterEngine: All thread groups have been started 
2014/11/05 16:27:23 INFO  - jmeter.threads.JMeterThread: Thread started: Thread Group 1-1 
**2014/11/05 16:27:23 INFO  - jmeter.protocol.java.sampler.JUnitSampler: Trying to find constructor with one String parameter returned error: test.BeforeAnnotatedTest.<init>(java.lang.String)** 
2014/11/05 16:27:23 INFO  - jmeter.threads.JMeterThread: Stop Thread detected by thread: Thread Group 1-1 
2014/11/05 16:27:23 INFO  - jmeter.threads.JMeterThread: Thread finished: Thread Group 1-1 
2014/11/05 16:27:23 INFO  - jmeter.engine.StandardJMeterEngine: Notifying test listeners of end of test 
2014/11/05 16:27:23 INFO  - jmeter.gui.util.JMeterMenuBar: setRunning(false,*local*) 

Here is my class:

package jmeter;

import java.io.File;    
import java.util.Iterator;    
import java.util.Set;    
import java.util.concurrent.TimeUnit;    
import org.apache.log4j.Logger;    
import org.junit.Before;    
import org.junit.BeforeClass;    
import org.junit.Test;    
import org.openqa.selenium.By;    
import org.openqa.selenium.WebDriver;    
import org.openqa.selenium.firefox.FirefoxDriver;

public class ShoppingCartTest {

  public  WebDriver driver=null;

  //Initializes/loads  the driver based on type of browser defined in config file
  @Before
  public void initDriver(){
      driver =new FirefoxDriver();
      driver.manage().timeouts().pageLoadTimeout(120, TimeUnit.SECONDS);
      driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

  @Test
  public void verifyAnItemToWishList() throws InterruptedException{
    driver.get("http://www.google.com")     
    System.out.println("done");

  } 
}   
рüффп
  • 5,172
  • 34
  • 67
  • 113
user2113098
  • 131
  • 1
  • 2
  • 10
  • A quick fix is to create two constructors in your class, one with no parameter, another with a string parameter, i think there is a bug in JUnitSample.java. Find another time to read the code. – Alan Zhong Jan 18 '16 at 08:01

3 Answers3

0

Your code looks good and there are no issues there. Make sure that following conditions are met:

  1. Your class is packaged into .jar file and dropped into /lib/junit folder of your JMeter installation (or alternatively under location specified by user.classpath property)
  2. Looking into your @Before and @Test annotations - you're using JUnit4. In that case you need to tick Search for JUnit4 annotations box in your JUnit Request Sampler as below:

JUnit4 annotations

See How to Use JUnit With JMeter guide for comprehensive walkthrough on all aspects of using JUnit in JMeter.

P.S. It may be easier to consider WebDriver Sampler available via JMeter Plugins instead?

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • There is no problem to create the Junit Request (detected the Junit 4, classname and Test Method). The error is when running it. – Alan Zhong Jan 18 '16 at 07:26
0

I had similar issue. It got resolved on Downloading fresh instance of Jmeter, installing Selenium/WebDriver Support plugin and Selenium Server Standalone jar. So this error might be just because of not having required Jar in Jmeter Lib folder.

Jim
  • 1
  • this should be comment. – jjj Feb 17 '17 at 11:43
  • I was searching through Stackoverflow for issue I was facing but answer didn't resolve the issue. I got it resolved with fresh installation, so thought to sign up and post suggestion. Didn't know difference between answer and comment. . Thanks for letting me know difference between them! – Jim Feb 17 '17 at 15:54
0

I was facing the same issue, it got resolved with added System.setProperty and i dint add any other constructors (default constructor and any parameter constructor, i had tried with even these 2 constructor even then it was not working, then i added System.setProperty it worked),

For firefox,

    System.setProperty("webdriver.gecko.driver", "D:\\geckodriver.exe");
    WebDriver driver = new FirefoxDriver();

this resolved my issue.

Suhail Ahmed
  • 504
  • 1
  • 9
  • 19