之前的測試框架: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í)行測試用例時使用的包含不同平臺(windows、Linux、Android)的框架,并且
這些平臺是由一個中心點控制,這個中心點稱之為HUB,而那些不同的平臺稱之為NODE
其結(jié)構(gòu)如下:
為什么使用selenium grid:
如果你的程序需要在不用的瀏覽器,不同的操作系統(tǒng)上測試,而且比較多的case需要多線程遠程執(zhí)行,那么一個比較好的solution是使用grid.selenium-grid是用于設(shè)計幫助我們進行分布式測試的工具,其整個結(jié)構(gòu)是由一個hub節(jié)點和若干個代理節(jié)點組成。hub用來管理各個代理節(jié)點的注冊和狀態(tài)信息,并且接受遠程客戶端代碼的請求調(diào)用,然后把請求的命令再轉(zhuǎn)發(fā)給代理節(jié)點來執(zhí)行。
怎么使用:
首先啟用HUB:
在A機器下載: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機添加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
分別啟動這兩個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)建一個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 }