初识selenium-grid
什么是selenium-grid,官方解释:takes Selenium Remote Control to another level by running tests on many servers at the same time, cutting down on the time it takes to test multiple browsers or operating systems。
个人理解是分布式测试,即在不同的操作系统、浏览器上并发执行测试用例,那如何使用呢,这两天研究了一下,初步能调用起来,也算刚入门,今天做下总结。
首先要知道grid是有一个hub和若干个node组成,hub负责管理node和接收代码的request,并把request分发给node,让node去执行。
1.下载selenium-server-standalone-XXX.jar,可以去官网下载最新的,我这里是2.47版本的,下载地址:http://pan.baidu.com/s/1kT3rK5T
2.选一台机器作为hun,启动dos,输入命令:

172.16.28.34为hub的ip
4.如果电脑有限,可使用虚拟机或者在hub所在的机器,也启动一个node,启动dos,输入命令
java -jar selenium-server-standalone-2.45.0.jar -role node -hub http://localhost:4444/grid/register
5.启动成功后,可在hub所在的机器的浏览器中输入http://localhost:4444/grid/console,查看所连接的node信息
6.测试代码
/*
启动火狐浏览器
*/ public static void testFireFox() {
String key = "webdriver.firefox.bin";
String value = "C:/Program Files (x86)/Mozilla Firefox/firefox.exe";
System.setProperty(key, value);
//DesiredCapabilities aDesiredcap = DesiredCapabilities("firefox", "22", Platform.LINUX)
DesiredCapabilities test = DesiredCapabilities.firefox();
test.setVersion("");
test.setPlatform(Platform.WINDOWS);
WebDriver dr;
try {
dr = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),test);
dr.get("http://www.baidu.com");
Thread.sleep(3000);
dr.quit();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }
/*
启动火狐浏览器
*/ public static void testChrome() {
DesiredCapabilities aDesiredcap = DesiredCapabilities.chrome();
//aDesiredcap.setBrowserName("chrome");
aDesiredcap.setPlatform(Platform.WINDOWS);
WebDriver dr;
try {
dr = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), aDesiredcap);
dr.get("http://www.baidu.com");
dr.findElement(By.id("kw")).sendKeys("test");
Thread.sleep(3000);
dr.quit();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/*
启动IE浏览器
*/ public static void testIE() { DesiredCapabilities aDesiredcap = DesiredCapabilities.internetExplorer();
aDesiredcap.setPlatform(Platform.WINDOWS); WebDriver dr;
try {
dr = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), aDesiredcap);
dr.get("http://www.baidu.com");
Thread.sleep(3000);
dr.quit();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }
调用以上3个方法,hun会自动分配由哪个node去执行。
需要注意的是:
1.node所在机器的chromedriver.exe、IEDriverServer.exe需放在C盘的system32下,或者配置classpath,再或者用命令行指定路径
java -jar selenium-server-standalone-2.45.0.jar -D webdriver.firefox.bin=”D:/Program Files/Mozilla Firefox/firefox.exe” -role node -hub http://172.16.28.34:4444/grid/register
java -jar selenium-server-standalone-2.45.0.jar -D webdriver.chrome.driver="D:/chromedriver.exe" -role node -hub http://172.16.28.34:4444/grid/register
2.关闭hub和node机器的防火墙
3.异常
selenium.common.exceptions.WebDriverException: Message:
Error forwarding the new session cannot find : Capabilities [{browserName=htmlunit, javascriptEnabled=true, version=, platform=ANY}]
指定一下 browsername:
java -jar selenium-server-standalone-2.44.0.jar -role node -hub http://IP:4444/grid/register -browser browserName=htmlunit
关于grid的官网介绍:
https://github.com/SeleniumHQ/selenium/wiki/Grid2
初识selenium-grid的更多相关文章
- 搭建selenium grid简单配置
1.使用selenium提供的服务端独立jar包 :服务端.客户端都是运行于java7环境. 2.启动hub: hub配置文件如下: Java -jar selenium-server-standal ...
- Robot Framework + Selenium2Library环境下,结合Selenium Grid实施分布式自动化测试
最近一段时间,公司在推行自动化测试流程,本人有幸参与了自定义通用控件的关键字封装和脚本辅助编写.数据驱动管理.测试用例执行管理等一系列工具软件的研发工作,积累了一些经验,在此与大家做一下分享,也算是做 ...
- Selenium Grid 学习笔记
Selenium Grid 学习笔记http://www.docin.com/p-765680298.html
- Selenium Grid 运行报错 Exception thrown in Navigator.Start first time ->Error forwarding the new session Empty pool of VM for setup Capabilities
Selenium Grid 运行报错 : Exception thrown in Navigator.Start first time ->Error forwarding the new se ...
- selenium Grid(一)
selenium grid Quick Start selenium-grid是用于设计帮助我们进行分布式测试的工具,其整个结构是由一个hub节点和若干个代理节点组成.hub用来管理各个代理节点的注册 ...
- selenium Grid
Selenium Grid 的机制是启动一个 hub,然后启动多个 Selenium RC 注册到 hub 上, 当测试请求到 hub 时,hub 会将测试分发给 Selenium RC, Selen ...
- selenium grid java 资料
Grid TestNG: 使用Selenium Grid改进Web应用程序的测试: http://www.ithov.com/server/117464.shtml
- Selenium Grid跨浏览器-兼容性测试
Selenium Grid跨浏览器-兼容性测试 这里有两台机子,打算这样演示: 一台机子启动一个作为主点节的hub 和 一个作为次节点的hub(系统windows 浏览器为ie) ip为:192.16 ...
- selenium grid的使用与配置
一.selenium grid的组成与作用:由一个集线器hub和多个客户机node组成,如果你的程序需要在不用的浏览器,不同的操作系统上测试,而且比较多的case需要多线程远程执行,那么一个比较好的测 ...
- 初识Selenium(四)
用Selenium实现页面自动化测试 引言 要不要做页面测试自动化的争议由来已久,不做或少做的主要原因是其成本太高,其中一个成本就是自动化脚本的编写和维护,那么有没有办法降低这种成本呢?童战同学在其博 ...
随机推荐
- 与众不同 windows phone (48) - 8.0 其它: C# 调用 C++
[源码下载] 与众不同 windows phone (48) - 8.0 其它: C# 调用 C++ 作者:webabcd 介绍与众不同 windows phone 8.0 之 其它 C# 中调用 W ...
- python代码风格-PEP8
转载自http://www.douban.com/note/134971609/ Python 的代码风格由 PEP 8 描述.这个文档描述了 Python 编程风格的方方面面.在遵守这个文档的条件下 ...
- Maven初步搭建 (一)
什么是maven? 也许很多人开始的时候跟我一样,在看了很多工程之后都不知道这个鸟东西到底是用来干嘛用的!:-D 一个东西之所以会出现是有其原因的,譬如Linus大神写git. Maven项目对象模型 ...
- S2 易买网总结
易买网项目总结 --指导老师:原玉明 不知不觉,又到了S2结业的时间了,S1的项目KTV项目还历历在目.一路走来,感觉时间过的好快,我们离就业也越来越近... 展示: 1.主页面(首页) 01.商品分 ...
- python3.5.2爬虫
话不多说,都在代码里 #下载斗鱼颜值栏目主播照片 #author:ives #date:2016-8-28 21:58 #e-mail:renhanlinbsl@163.com import urll ...
- C++之函数重载
函数重载定义: 如果同一作用域内的几个函数名字相同但形参列表不同; 重载与const形参: Record (Phone); = Record(const Phone); Record(Phone*) ...
- android.widget.RadioButton 单选按钮(转)
大家好,我们今天这一节要介绍的是RadioGroup 的组事件.RadioGroup 可将各自不同的RadioButton ,设限于同一个Radio 按钮组,同一个RadioGroup 组里的按钮,只 ...
- winform(ListView及数据库连接)
一.ListView:列表展示数据1.视图 - 在其右上方小箭头点击将视图改为Largelcon:或右键属性在外观View将其改为Details2.设置列头 - 在其右上方小箭头点击选择编辑列,然后添 ...
- [ASP.NET MVC] 使用Bootsnipp样式
[ASP.NET MVC] 使用Bootsnipp样式 前言 在「[ASP.NET MVC] 使用Bootstrap套件」这篇文章中,介绍了如何在Web项目里使用Bootstrap套件,让用户界面更加 ...
- FEE Development Essentials
FEE Development Essentials JS Basic function call() and apply() func1.bind(thisObj,arg1...argn) Cust ...