部署Selenium Grid + Selenium RC + Webdriver

本文介绍如何配置Selenium Grid环境,包括GridHub与SeleniumRC的安装步骤、所需软件及其版本,并提供示例脚本说明如何利用Grid进行自动化测试。
Grid Hub:Ubuntu12.10_x64(自动化脚本所在的机器,也是 selenium  server所在的机器)
  Selenium RC: Windows 7_x32(接收hub的命令并启动浏览器运行 测试脚本的机器,称为节点)
   1、Hub需要安装的软件及包:Python2.7.3+Selenium2+Java1.7.0_25+selenium-server-2.39.0.jar+chromedriver_linux64.zip
   2、RC需要的软件及包:Java1.7.0_25+selenium-server-standalone-2.39.0.jar+Firefox+Chrome28+IEDriverServer_Win32_2.39.0.zip+chromedriver_win32_13.0.775.0
   3、Grid Hub安装步骤
   Python(Ubuntu自带了,无需额外安装)
  安装setuptools
  下载路径:http://pypi.python.org/pypi/setuptools
  安装:sudo python  easy_install.py install
  安装pip
  下载 pip-1.4.1.tar.gz
  安装:sudo python setup.py install
  在线安装selenium
  pip install selenium
   Java(Ubuntu自带了,无需额外安装)
  下载selenium-server-2.39.0.jar
  解压selenium-server-2.39.0.zip,在selenium-server-2.39.0目录下找到 selenium-server-standalone-2.39.0.jar
  下载chromedriver_linux64.zip。解压得到chromedriver,用root用户将chromedriver复制到/usr/bin目录
  进入selenium-server-standalone所在的目录
  在终端输入java -jar selenium-server-standalone-2.39.0.jar -role hub启动Grib Hub
  浏览器端可打开http://localhost:4444/grid/console页面
   终端显示如下:
irene@shuixian:~/Downloads/selenium-2.39.0$ java -jar selenium-server-standalone-2.39.0.jar -role hubDec 24, 2013 6:28:00 PM org.openqa.grid.selenium.GridLauncher main
INFO: Launching a selenium grid server
2013-12-24 18:28:01.513:INFO:osjs.Server:jetty-7.x.y-SNAPSHOT
2013-12-24 18:28:01.564:INFO:osjsh.ContextHandler:started o.s.j.s.ServletContextHandler{/,null}
2013-12-24 18:28:01.571:INFO:osjs.AbstractConnector:Started SocketConnector@0.0.0.0:4444
   4、Selenium RC安装步骤(Windows 7)
  下载安装JAVA
  下载selenium-server-standalone-2.39.0.jar,同上
  下载并安装Firefox
  下载并安装Chrome,版本33会有错,可下载28这个版本
  下载IEDriverServer.exe,解压包并将IEDriverServer.exe复制到IE的安装目录下如:C:\Program Files\internet Explorer
  把C:\Program Files\internet Explorer增加到机器的环境变量PATH中,即编辑PATH,在后面加上;C:\Program Files\internet Explorer
  下载chromedriver_win32_13.0.775.0.zip,解压得到chromedriver.exe,将chromedriver.exe放在chrome的安装目录如:C:\Users\irene\AppData\Local\Google\Chrome\Application。


把C:\Users\irene\AppData\Local\Google\Chrome\Application追加到机器的环境变量PATH中
  将Selenium RC注册到Grib Hub中,并指定浏览器为IE
java -jar selenium-server-standalone-2.39.0.jar -role node -hub http://192.168.88.183:4444/register -browser browserName="internet explorer" naxInstance=1,platform=WINDOWS
  将Selenium RC注册到Grib Hub中,并指定浏览器为Firefox
java -jar selenium-server-standalone-2.39.0.jar -role node -hub http://192.168.88.183:4444/register -browser browserName="firefox" naxInstance=1,platform=WINDOWS
  将Selenium RC注册到Grib Hub中,并指定浏览器为Chrome
java -jar selenium-server-standalone-2.39.0.jar -role node -hub http://192.168.88.183:4444/register -browser browserName="chrome" naxInstance=1,platform=WINDOWS
   5、Selenium RC的启动(与Grid Hub在同台机器)
  将Selenium RC注册到Grib Hub中,并指定浏览器为Firefox
java -jar selenium-server-standalone-2.39.0.jar -role node -hub http://localhost:4444/register -browser browserName="firefox" naxInstance=1,platform=LINUX
  将Selenium RC注册到Grib Hub中,并指定浏览器为Chrome
java -jar selenium-server-standalone-2.39.0.jar -role node -hub http://localhost:4444/register -browser browserName="chrome" naxInstance=1,platform=LINUX
   6、示例脚本
from selenium import webdriver
from selenium.webdriver.remote.command import Command
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
browser = webdriver.Remote('http://192.168.88.183:4444/wd/hub', DesiredCapabilities.FIREFOX)
browser.get("http://www.baidu.com")
browser.find_element_by_name("wd").send_keys("scutech")
browser.find_element_by_id("su").click()
browser.quit()
   7、注意:运行脚本前Selenium Grid 和Selenium RC都要启动。Hub只有一个,RC可以有多个。
最新内容请见作者的GitHub页:http://qaseven.github.io/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值