JMeter中使用Selenium进行测试

凉秀策 测试分享评论146字数 1813阅读模式
摘要  JMeter是使用非常广泛的性能测试工具,而Selenium是ThroughtWorks 公司一个强大的开源Web 功能测试工具。Jmeter和Selenium结合使用,

  JMeter是使用非常广泛的性能测试工具,而Selenium是ThroughtWorks 公司一个强大的开源Web 功能测试工具。Jmeter和Selenium结合使用,就可以实现对网站页面的自动化性能测试。
  这里有两种方式在Jmeter中调用Selenium测试用例。可以使用 Jmeter JUnit sampler 或者 BeanShell sampler,后一种方式包含了Selenium client 和 server,因此不需要单独启动Server。
  方法一
  准备工作:
  将文件selenium-server-standalone-2.*.jar拷贝到JMeter类库安装目录%JMETER_HOME%/lib/下,手动启动Selenium server。
  Jmeter JUnit sampler
  将Selenium测试用例打包成.jar文件,并拷贝到%JMETER_HOME%/lib/junit/目录下,注意:测试用例应该继承TestCase or SeleniumTestCase类,从而允许JMeter获取到该测试用例,且测试方法名称应该以test开头。
  在Jmeter中创建test group和JUnit sampler测试计划,并在JUnit sampler中选择测试用例的名称,选择测试方法并运行。当然还可以根据需求设置其他参数。
  一个测试用例例子:

package com.example.tests;
import com.thoughtworks.selenium.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.After;
public class selenium extends SeleneseTestCase {
@Before
public void setUp() throws Exception {
. . .
}
@Test
public void testSelenium_test() throws Exception {
. . .
}
@After
public void tearDown() throws Exception {
selenium.stop();
}
}

  方法二
  准备工作:
  将文件selenium-server-standalone-2.*.jar拷贝到JMeter类库安装目录%JMETER_HOME%/lib/下,不需要启动Selenium server.
  Jmeter JUnit sampler
  将Selenium测试用例打包成.jar文件,并拷贝到%JMETER_HOME%/lib/junit/目录下,注意:测试用例应该继承TestCase or SeleniumTestCase类,从而允许JMeter获取到该测试用例,且测试方法名称应该以test开头。
  在Jmeter中创建test group和JUnit sampler测试计划,并在JUnit sampler中选择测试用例的名称,选择测试方法并运行。当然还可以根据需求设置其他参数。
  一个测试用例例子:文章源自玩技e族-https://www.playezu.com/185095.html

import junit.framework.TestCase;
import org.openqa.selenium.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.After;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
public class selenium extends TestCase {
WebDriver driver;
@Before
public void setUp() {
FirefoxProfile profile = new FirefoxProfile();
. . .
driver = new FirefoxDriver(profile);
}
@Test
public void testSelenium_test() throws Exception {
. . .
}
@After
public void tearDown() {
driver.quit();
}
}
文章源自玩技e族-https://www.playezu.com/185095.html文章源自玩技e族-https://www.playezu.com/185095.html
玩技站长微信
添加好友自动发送入群邀请
weinxin
rainbow-shownow
玩技官方公众号
官方微信公众号
weinxin
PLAYEZU
 
  • 版权提示:本站仅供存储任何法律责任由作者承担▷诈骗举报◁▷新闻不符◁▷我要投稿◁
    风险通知:非原创文章均为网络投稿真实性无法判断,侵权联系2523030730
    免责声明:内容来自用户上传发布或新闻客户端自媒体,切勿!切勿!切勿!添加联系方式以免受骗。
  • 原创转载:https://www.playezu.com/185095.html
    转载说明: 点我前往阅读>>>
匿名

发表评论

匿名网友
确定