我如何使用我的JUnit测试(硒的webdriver)使用JMeter(How can i use

2019-10-29 19:07发布

我创建了功能测试使用JUnit 4和硒的webdriver和它的作品。
现在,我想用这个测试使用JMeter进行性能测试。

我复制selenium-server-standalone-2.0b2.jar在JMeter的图书馆,然后我出口我的测试从Eclipse来.jar文件。

这我硒测试

public class TestLoginWithFF {   
  private WebDriver driver;
  private String baseUrl;
  private StringBuffer verificationErrors = new StringBuffer();

  @Before
  public void setUp() throws Exception {
    driver = new FirefoxDriver();
    baseUrl = "http://localhost:8080/";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

  @Test
  public void test() throws Exception {
    driver.get(baseUrl + "/pages/accueil/login.xhtml#loaded");

    driver.findElement(By.id("login")).clear();
    driver.findElement(By.id("login")).sendKeys("admin");
    driver.findElement(By.id("password")).clear();
    driver.findElement(By.id("password")).sendKeys("admin");
    driver.findElement(By.id("loginButton")).click();
  }

  @After
  public void tearDown() throws Exception {
    //driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
      fail(verificationErrorString);
    }   
  } 
}

Answer 1:

也许你可以使用某种类型的场景记录的。 我知道加特林提供了这样的功能。 JMeter的应该有它。

我们的想法是通过刻录机,这样他们就会被记录在JMeter的语言,随时可以用来执行你的测试。



Answer 2:

现在,您可以在JMeter的使用本身具有的webdriver插件: http://jmeter-plugins.org/wiki/WebDriverSampler/



Answer 3:

我认为这个问题是

driver = new FirefoxDriver();

注释掉此行; 那么JMeter会知道你的方法。



文章来源: How can i use my Junit test (selenium webdriver) with Jmeter