Selenium Webdriver 学习总结-Selenium Grid & Webdriver(九)

晒酷学院qq群:979438600

Google教程:https://code.google.com/p/selenium/wiki/Grid2
Hub / Node
系统要求:JDK、firefox、chrome、internetExplorer
所需工具:selenium-server-standalone-xxx.jar
下载地址:http://code.google.com/p/selenium/downloads/list

Start Hub
IP: 192.168.0.22
命令行启动Hub
C:>java -jare:\selenium-server-standalone-2.37.0.jar –role hub –port 4444

可选参数
l -port (缺省 4444)为默认hub所在服务器(jetty)端口为4444,服务启动之后,可以通过 http://localhost:4444/grid/console 访问Grid Console已查看各节点状态
l -timeout (缺省 30 s),当某节点在指定时间未收到任何请求时,该节点会被释放加入到其它队列中,可以使Client不会一直处于挂起状态
l -maxSession (缺省 5) ,在节点最大并行运行的浏览器个数,这个不同于节点中浏览器的maxInstance
前者为最大启动的浏览器个数,后者为同一版本浏览器最大实例数

使用Json配置Hub:
C:>java -jar selenium-server-standalone-2.37.0.jar-role hub -hubConfig hubconfig.json

hubConfig.json如下:

{
 "host": null,
 "port": 4444,
 "newSessionWaitTimeout": -1,
 "servlets" : [],
 "prioritizer": null,
 "capabilityMatcher":"org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
 "throwOnCapabilityNotPresent": true,
 "nodePolling": 5000,
 
 "cleanUpCycle": 5000,
 "timeout": 60,
 "browserTimeout": 60,
 "maxSession": 5,
 "jettyMaxThreads":-1
}

配置超时
为了维持测试运行完整性,在grid中提供了另外两种超时设置,如下:
-timeout: 单位(秒),在启动hub命令行参数中指定,当客户端崩溃指定时间后,grid会回收所有资源
-browserTimeout:单位(秒),在启动hub命令行参数中指定,当Node浏览器处于挂起状态指定时间后,grid会回收所有资源
注:webdriver API中,webDriver.manage().timeouts()设置不同操作的超时在grid中同样生效;
在Hub中配置两个参数值后,会对所有Node生效,当然也可以局部地在Node上配置(官方不推荐);
对于browserTimeout应该高于socket锁超时(45 s),另外,由于该超时是最后防线,也应高于webDriver.manage().timeouts()指定的超时时间

Start Node
IP: 192.168.0.143

命令行启动节点
C:>java -jar e:\selenium-server-standalone-2.30.0.jar-role node –hub http://192.168.0.22:4444/grid/register
注:缺省情况下,Node默认端口为5555;
-hub参数指定Grid Hub接受节点注册的地址;
为了兼容Selenium1.0,-role 的参数值可以使用(wd / rc),当使用node时可以接受webdriver 和 RC两者的连接实例

命令行配置节点
缺省情况,grid会启动11个浏览器实例, 5 Firefox, 5 Chrome, 1 Internet Explorer.,最大并发执行测试数目为5,
我们可以通过配置-browser参数来更改关于浏览器的默认配置,一旦更改将覆写缺省配置
Example_1: 以下配置将在Linux环境下启动5个Firefox3.6实例

-browser browserName=firefox,version=3.6,maxInstances=5,platform=LINUX
Example_2: 如果你的远程机器有多个版本的Firefox或其他浏览器,可以使用如下配置

-browser browserName=firefox,version=3.6,firefox_binary=/home/myhomedir/firefox36/firefox,maxInstances=3,platform=LINUX
-browser browserName=firefox,version=4,firefox_binary=/home/myhomedir/firefox4/firefox,maxInstances=4,platform=LINUX
注:如果参数中的value字符串中包含空格,可以使用双引号包裹字符串。

使用JSon配置节点
C:>java -jar e:\selenium-server-standalone-2.30.0.jar -role node -nodeConfige:\selenium\node.json
Node.json如下:

{
	"capabilities":[
		{
			"browserName":"firefox",
			"maxInstances": 2,  //当前版本浏览器实例化最大个数
			"seleniumProtocol":"WebDriver"
		},
	{
		"browserName": "internet explorer",
		"maxInstances": 1,
		"seleniumProtocol": "WebDriver"
	}
	],
	"configuration":
		{
			"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
			"maxSession": 2,  //最大并行执行的测试任务
			"port": 5555,
			"host": 192.168.0.143,
			"register": true,
			"registerCycle": 5000,  //该节点向hub发出注册请求的频率,单位毫秒ms
			"hubPort": 4444,
			"hubHost": 192.168.0.22
		}
	}

使用Grid运行测试
对于WebDriver而言,你需要使用RemoteWebDriver和DesiredCapabilities对象来定义你将要在什么平台下运行测试,例如浏览器,浏览器版本,操作系统,示例如下

DesiredCapabilities capability =DesiredCapabilities.firefox();
capability.setBrowserName(“firefox” );  
capability.setPlatform(“LINUX”); 
capability.setVersion(3.6);
WebDriver driver = new RemoteWebDriver(newURL("http://localhost:4444/wd/hub"), capability);

以上脚本将会匹配如下配置的节点
-browser browserName=firefox,version=3.6,platform=LINUX

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值