0
votes

I am trying to integrate jmeter with selenium. I wrote a script, exported it as jar, saved it in lib/junit. Then added a Junit request sampler to my thread. I can find the relevant class name, but the Test Method list is empty. Here is the code:

import java.util.concurrent.TimeUnit;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.junit.Test;


public class SeleniumTest extends TestCase{

    WebDriver driver=null;
@Before
public void setUp()  {
    driver=new FirefoxDriver();

    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
    public void login()
    {

       driver.get("http://www.website.com/");
       try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
       driver.findElement(By.id("inputEmail")).clear();
       driver.findElement(By.id("inputEmail")).sendKeys("username");
       driver.findElement(By.id("inputPassword")).clear();
       driver.findElement(By.id("inputPassword")).sendKeys("password");
       driver.findElement(By.cssSelector("div.controls > button.btn")).click();
    }

@After
public void tearDown()  {
    driver.quit();
}

}
1
what version of junit are you using? junit 4 annotations will only be recognised if you tick the box. junit 3 methods must follow naming conventions - CharlieS

1 Answers

2
votes

I think that you need to change your method name to start with test, i.e. to testLogin

Also by default JMeter's JUnit Request Sampler is looking for JUnit3-style test cases naming. Looking into your code I see that you're using JUni4 annotations so you need to check "Search for JUnit4 annotations" box.

For more details on JUnit Request Sampler you can refer to How to Use JUnit With JMeter guide.