【发布时间】:2018-04-10 16:47:16
【问题描述】:
我尝试使用 Junit Request Sampler 通过使用 CSV 数据集配置登录到多个用户的测试应用程序。例如:我将线程数设置为 2,并在 .csv 文件中设置两个用户登录详细信息,然后运行测试。结果是打开了两个firefox浏览器,一个浏览器登录成功,另一个没有在登录页面的用户名和密码字段中输入用户名和密码。这是我的硒脚本代码。请任何人都可以提出这个问题的原因吗?
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);
}
}
【问题讨论】:
-
你能分享一下你遇到了什么错误吗?
-
我使用了两个 junit 请求采样器。在第一个 junit 请求采样器中,将类名称设置为 testClass,将 setUpBeforeClass 方法设置为测试方法。在第二个 junit 请求采样器中,将类名称设置为 testClass,将登录方法设置为测试方法,然后我运行线程组。结果是打开了两个firefox浏览器并成功加载了url。但是只有一个浏览器完全登录到应用程序成功,而另一个浏览器由于登录数据未插入用户名和密码字段而无法登录。这就是问题所在。