Error instantiating class:class:null java.lang.reflect.InvocationTargetException

1.7k views Asked by At

Use Selenium JUnit Java + JMeter for Load testing.

In Eclipse started the test, everything is ok, after make a JAR file and put it in apache/lib/junit directory, starting JMeter choose this JAR file, and it's crashed with error. I was reading a lot of answer on stackoverflow and other siter, but nothing find that can help me.

Here's log:

2015/06/10 18:10:41 INFO  - jmeter.threads.JMeterThread: Thread started: Thread Group 1-1 
2015/06/10 18:10:49 ERROR - jmeter.protocol.java.sampler.JUnitSampler: Error instantiating class:class LoadTestGuppy.LoadTestGuppy.AppTest:null java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

and code:

package LoadTestGuppy.LoadTestGuppy;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import java.util.concurrent.TimeUnit;

import junit.framework.TestCase;


public class AppTest extends TestCase {
    private WebDriver driver = new FirefoxDriver();

    public AppTest(){}

    public AppTest(String text){
        super(text);
    }

    @Before
    public void setUp() throws Exception {
        driver.get("http://barracuda-qa.ko.kodak.com/d2l/faces/Login.jsp");
        driver.manage().window().maximize();
    }

    @Test
    public void testTestLoad() throws Exception {
        driver.findElement(By.id("loginForm:authLogin")).sendKeys("some222");
        driver.findElement(By.id("loginForm:authPassword")).sendKeys("222");
        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
        driver.findElement(By.id("loginForm:btnLogin")).click();
        driver.manage().timeouts().implicitlyWait(2000, TimeUnit.SECONDS);
        driver.findElement(By.xpath("//a[@class='log']")).click();
        driver.manage().timeouts().implicitlyWait(2000, TimeUnit.SECONDS);
        driver.findElement(By.xpath("//a[@class='logout']")).click();

    }

    @After
    public void tearDown() throws Exception {
        driver.close();
    }

}

What it can be?

2

There are 2 answers

3
Ritesh  Karwa On

Try removing these line

InvocationTargetException is a checked exception that wraps an exception thrown by an invoked method or constructor

public AppTest(){}

        public AppTest(String text){
            super(text);
        }

You can try reinstalling the jar file see if that works

11
Dmitri T On

Have you added Selenium jars into JMeter's /lib folder? If not - copy them there, restart JMeter and retry.

By the way, there is WebDriver Sampler which could be more handy for Selenium and JMeter integration.

If you decide to go JUnit way I would recommend adding debug command line argument to JMeter startup script, something like

set JVM_ARGS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 %JVM_ARGS%

After that you can connect to JMeter JVM instance with Eclipse and, what exactly is "null" and resolve it. See How to debug your Apache JMeter script guide for more clues and exact configuration instructions for JMeter and Eclipse sides.