初识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,输入命令:
http://172.16.28.34:4444/grid/register172.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实现页面自动化测试 引言 要不要做页面测试自动化的争议由来已久,不做或少做的主要原因是其成本太高,其中一个成本就是自动化脚本的编写和维护,那么有没有办法降低这种成本呢?童战同学在其博 ...
随机推荐
- Java文件编码自动转换工具类(只改变编码,不会改变文件内容)
本篇随笔主要介绍了一个用java语言写的将一个文件编码转换为另一个编码并不改变文件内容的工具类: 通过读取源文件内容,用URLEncoding重新编码解码的方式实现. public class Cha ...
- linux下导入、导出mysql数据库命令 下载文件到本地
一.下载到本地 yum install lrzsz sz filename 下载 rz filename 上传 linux下导入.导出mysql数据库命令 一.导出数据库用mysqldump命 ...
- 【Asphyre引擎】关于AsphyreTypes中OverlapRect的改动,都是泪啊!!!
OverlapRect改动:两个参数对调了.想问问LP,这样真的好吗? Sphinx304版本的代码: function OverlapRect(const Rect1, Rect2: TRect): ...
- PHP学习笔记:伪静态规则的书写
这里以阿帕奇为服务器软件,直接上案例: 1.把index.html重定向到index.php RewriteEngine On Options -Indexes ReWriteRule ^index. ...
- Mac OSX 下用 Homebrew 安装 MongoDB 并配置到 WebStorm 中
1. 安装 Ruby OSX 操作系统内置 Ruby,但如果没有 Ruby,则需先输入以下命令安装能够进行多版本ruby环境安装.管理和切换的命令行工具 RVM. 1.1 安装 RVM 打开终端输入以 ...
- 单例(Singleton pattern)模式的七种写法
转载请注明出处:http://www.cnblogs.com/smbk/ One: public class Singleton { private static Singleton instance ...
- 趣味题:恺撒Caesar密码(c++实现)
描述:Julius Caesar 生活在充满危险和阴谋的年代.为了生存,他首次发明了密码,用于军队的消息传递.假设你是Caesar 军团中的一名军官,需要把Caesar 发送的消息破译出来.并提供给你 ...
- WCF实战2
上一篇中,我们创建了一个简单的WCF服务,在测试的时候,我们使用VS2008自带的WCFSVCHost(WCF服务主机)发布WCF服务,以便进行测试.这种VS2008内置的WCFSVCHost只适用于 ...
- Mssql链接mysql数据库
最近在做mysql数据库实时同步到mssql数据库的方案,花了一周时间,测试通过了,在实际机器上测试出现了若干问题.第一个问题就是在mssql上链接mysql的问题. 第一步,安装 Mysql ODB ...
- sublime text 3 安装
sublime text 3 下载地址 http://www.sublimetext.com/3 下载windows版本,然后解压缩就可以直接使用了,不错不错哦, 为了更加便捷的管理,安装 packa ...