I tried to use Junit Request Sampler for login to my test application with multiple users by using CSV data set config. Ex : I set number of thread count as 2 and set two user login details in .csv file and i run the test. The result was open the two firefox browsers and one browser logged successfully and other one is not get username and password into username and password fields in login page. This is my selenium script code. Please anyone can suggest the reason for this issue ?
import org.apache.jmeter.protocol.java.sampler.JUnitSampler;
import org.junit.Assert;
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 testClass {
static WebDriver driver;
JUnitSampler sampler = new JUnitSampler();
String userName = sampler.getThreadContext().getVariables().get("username");
String password = sampler.getThreadContext().getVariables().get("password");
String Empnamecsv = sampler.getThreadContext().getVariables().get("Empname");
@BeforeClass
public static void setUpBeforeClass() throws Exception
{
System.setProperty("webdriver.gecko.driver", "D:\\Automation\\Geckodriver\\V0.19.0\\geckodriver.exe");
driver = new FirefoxDriver();
}
@Test
public void loadHomePage() throws InterruptedException
{
driver.get("http://localhost/testWeb");
Thread.sleep(1000);
}
@Test
public void login() throws InterruptedException
{
driver.findElement(By.id("txtusername")).sendKeys(userName);
driver.findElement(By.id("txtpassword")).sendKeys(password);
driver.findElement(By.id("btnsubmit")).click();
Thread.sleep(1000);
String name = driver.findElement(By.xpath("/html/body/div[1]/div[2]/div[3]/span[1]/span[1]")).getText();
Assert.assertEquals(name,namecsv);
}
}