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安装步骤
安装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
下载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可以有多个。