qileilove

          blog已經轉移至github,大家請訪問 http://qaseven.github.io/

          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中選擇測試用例的名稱,選擇測試方法并運行。當然還可以根據需求設置其他參數。
            一個測試用例例子:
          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();
          }
          }

          posted on 2014-06-05 13:49 順其自然EVO 閱讀(3028) 評論(0)  編輯  收藏 所屬分類: jmeter and badboyselenium and watir webdrivers 自動化測試學習

          <2014年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 新宾| 河北区| 张北县| 大渡口区| 麦盖提县| 石门县| 龙海市| 枣阳市| 渭源县| 新疆| 介休市| 永丰县| 宁海县| 卢湾区| 大同县| 盐池县| 凯里市| 昌邑市| 公安县| 扬中市| 井陉县| 邯郸市| 石棉县| 登封市| 望都县| 贵州省| 乌拉特中旗| 阿拉尔市| 永仁县| 睢宁县| 施甸县| 阿城市| 贡觉县| 东乡| 华安县| 平阴县| 招远市| 南漳县| 建瓯市| 长汀县| 宝应县|