我如何在Jmeter中使用Junit测试(Selenium Webdriver) [英] How can i use my Junit test (selenium webdriver) with Jmeter

查看:250
本文介绍了我如何在Jmeter中使用Junit测试(Selenium Webdriver)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用JUnit 4和Selenium Webdriver创建了功能测试,并且可以正常工作.
现在,我想将此测试与JMeter一起用于性能测试.

I created my functional tests with JUnit 4 and Selenium Webdriver and it works.
Now I want to use this test with JMeter for performance tests.

我在JMeter的库中复制了selenium-server-standalone-2.0b2.jar,然后将测试从Eclipse导出到.jar文件.

I copied selenium-server-standalone-2.0b2.jar at JMeter’s library, then I exported my test from Eclipse to .jar file.

这是我的硒测试

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);
    }   
  } 
}

推荐答案

您现在可以在JMeter中通过插件原生使用webdriver: http://jmeter-plugins.org/wiki/WebDriverSampler/

You can now use webdriver natively in JMeter with a plugin: http://jmeter-plugins.org/wiki/WebDriverSampler/

这篇关于我如何在Jmeter中使用Junit测试(Selenium Webdriver)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆