您的位置:軟件測試 > 開源軟件測試 > 開源功能測試工具 > Selenium
Selenium測試框架中使用grid
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2015/6/12 14:25:38 ] 推薦標(biāo)簽:功能測試 Selenium

  之前的測試框架:http://www.cnblogs.com/tobecrazy/p/4553444.html
  配合Jenkins可持續(xù)集成:http://www.cnblogs.com/tobecrazy/p/4529399.html
  在測試框架中使用Log4J 2 :http://www.cnblogs.com/tobecrazy/p/4557592.html
  首先介紹一下grid ,selenium grid 是一種執(zhí)行測試用例時(shí)使用的包含不同平臺(tái)(windows、Linux、Android)的框架,并且
  這些平臺(tái)是由一個(gè)中心點(diǎn)控制,這個(gè)中心點(diǎn)稱之為HUB,而那些不同的平臺(tái)稱之為NODE
  其結(jié)構(gòu)如下:

  為什么使用selenium grid:
  如果你的程序需要在不用的瀏覽器,不同的操作系統(tǒng)上測試,而且比較多的case需要多線程遠(yuǎn)程執(zhí)行,那么一個(gè)比較好的solution是使用grid.selenium-grid是用于設(shè)計(jì)幫助我們進(jìn)行分布式測試的工具,其整個(gè)結(jié)構(gòu)是由一個(gè)hub節(jié)點(diǎn)和若干個(gè)代理節(jié)點(diǎn)組成。hub用來管理各個(gè)代理節(jié)點(diǎn)的注冊和狀態(tài)信息,并且接受遠(yuǎn)程客戶端代碼的請求調(diào)用,然后把請求的命令再轉(zhuǎn)發(fā)給代理節(jié)點(diǎn)來執(zhí)行。
  怎么使用:
  首先啟用HUB:
  在A機(jī)器下載:selenium standalone 4.6:http://pan.baidu.com/s/1qWE7SD2
  然后創(chuàng)建HUB.bat
  內(nèi)容為:
  java -jar selenium-server-standalone-2.46.0.jar -role hub
  其默認(rèn)監(jiān)聽端口4444,默認(rèn)IP localhost  如果要修改,只需要加-port 參數(shù)和-Hubhost
  java -jar selenium-server-standalone-2.46.0.jar -role hub  -port 1235 -Hubhost 192.168.2.45
  接下來在B機(jī)添加node ,創(chuàng)建Node.bat,這里使用的是默認(rèn)的Hubhost Ip 和端口
  java -jar selenium-server-standalone-2.46.0.jar -role node -hub http://localhost:4444/grid/register
  為了使用chrome和IE driver,我們需要這樣設(shè)置
  java -Dwebdriver.ie.driver="C:UsersworkspaceDemowebDriverIEDriverServer.exe" -Dwebdriver.chrome.driver="C:UsersworkspaceDemowebDriverchromedriver.exe" -jar selenium-server-standalone-2.46.0.jar -role node -hub http://localhost:4444/grid/register
  分別啟動(dòng)這兩個(gè)bat
  若使用remote Driver,需要設(shè)置這樣的參數(shù)
  DesiredCapabilities capability = DesiredCapabilities.firefox();
  WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
  capability.setBrowserName("firefox" );
  capability.setVersion("3.6");
  所以我們索性創(chuàng)建一個(gè)bean
1 /**
2  *
3  */
4 package com.dbyl.libarary.utils;
5
6 /**
7  * for remote browser bean
8  * @author Young
9  *
10  */
11 public class RemoteBrowserBean {
12     private String browserName;
13     private String version;
14     private String[] platform;
15     private String hubURL;
16     public String getBrowserName() {
17         return browserName;
18     }
19
20     public RemoteBrowserBean()
21     {
22         this.browserName="firefox";
23         this.version="38";
24         this.platform=new String[]{"VISTA", "windows 7"};
25         this.hubURL="http://localhost:4444/wd/hub";
26
27     }
28
29     public RemoteBrowserBean(String browser)
30     {
31         this.browserName=browser;
32         this.version="42";
33         this.platform=new String[]{"VISTA", "windows 7"};
34         this.hubURL="http://localhost:4444/wd/hub";
35
36     }
37
38     public void setBrowserName(String browserName) {
39         this.browserName = browserName;
40     }
41     public String getVersion() {
42         return version;
43     }
44     public void setVersion(String version) {
45         this.version = version;
46     }
47
48
49     public String[] getPlatform() {
50         return platform;
51     }
52
53     public void setPlatform(String[] platform) {
54         this.platform = platform;
55     }
56
57     public String getHubURL() {
58         return hubURL;
59     }
60     public void setHubURL(String hubURL) {
61         this.hubURL = hubURL;
62     }
63
64
65 }

上一頁12下一頁
軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd