#selenium grid2 初探 ##0 what is selenium grid? 简单说grid是一个分布式的应用,通过注册不同的节点(hub),提高用例执行效率。
##1 when to use selenium grid? +不同浏览器,不同版本,不同操作系统下执行用例 +减少用例执行时间,提高执行效率
##2 selenium grid1 VS. selenium grid2 ##3 Hub and node - Hub:总控节点,连接调用Node,负责分配用例到对应的Node节点所在的执行器上Node
- Node:负责执行TestCase,启动浏览器
##4 Starting Selenium-Grid 接下来如何启动Selenium-Grid并注册节点呢?windows下我用的批处理实现,以下未经说明,代码均为批处理。 ###4.1 start Grid Hub - @echo off
- echo "now start selenuim grid hub server"
- c:/apps/jdk1.7.0_55/bin/java -jar c:/apps/selenium-server/selenium-server.jar -role hub -port 4200
- PAUSE
复制代码
###4.2 register Grid Node with default - @echo off
- echo "now register selenuim grid node server"
- c:/apps/jdk1.7.0_55/bin/java -jar c:/apps/selenium-server/selenium-server.jar -role node -hub http://127.0.0.1:4200/grid/register -port 5555
- PAUSE
- ```
- ###4.3 register Grid node with self-settings
- ```
- @echo off
- echo "now register selenuim grid node Chrome browser server"
- c:/apps/jdk1.7.0_55/bin/java -jar c:/apps/selenium-server/selenium-server.jar -role node -hub http://127.0.0.1:4200/grid/register -port 5557 -Dwebdriver.chrome.driver="c:/apps/selenium-server/chromedriver.exe"
- PAUSE
- ```
- **Dwebdriver.chrome.driver** 参数允许你指定对应的chrome或者IE browser驱动。
- ###4.4 check and view grid status
- you can visit this url to check grid status `http://localhost:4200/grid/console`
- ##5 总结
- 这里只是完成了基本的Grid hub启动和注册,接下来看如何结合selenium实现具体需求。
- 附上一个用python写的启动脚本
- ```
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # @Date : 2016-03-03 16:48:31
- # @Author : Jeff.Sui
- # @Link : http://jeffsui.github.io
- # @Version : $Id$
- import os
- from subprocess import Popen
- import sys
- import urllib2
- import printTm
- DEBUG = True
- hubStartStr="c:/apps/jdk1.7.0_55/bin/java -jar c:/apps/selenium-server/selenium-server.jar -role hub -port 4200"
- html=''
- try:
- response=urllib2.urlopen('http://127.0.0.1:4200/wd/hub')
- html=response.read()
- if 'Browsers' in html:
- printTm('already running')
- exit
- else:
- Popen(hubStartStr,shell=True)
- exit
- except urllib2.URLError as e:
- Popen(hubStartStr,shell=True)
- exit
- except urllib2.HTTPError:
- printTm('HTTPError')
- exit
- ```
复制代码
|