什么是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,输入命令:

 java -jar selenium-server-standalone-2.45.0.jar  -role  hub
 
3.选一台机器作为node,启动dos,输入命令:
 java -jar selenium-server-standalone-2.45.0.jar  -role  node  -hub http://172.16.28.34:4444/grid/register

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的更多相关文章

  1. 搭建selenium grid简单配置

    1.使用selenium提供的服务端独立jar包 :服务端.客户端都是运行于java7环境. 2.启动hub: hub配置文件如下: Java -jar selenium-server-standal ...

  2. Robot Framework + Selenium2Library环境下,结合Selenium Grid实施分布式自动化测试

    最近一段时间,公司在推行自动化测试流程,本人有幸参与了自定义通用控件的关键字封装和脚本辅助编写.数据驱动管理.测试用例执行管理等一系列工具软件的研发工作,积累了一些经验,在此与大家做一下分享,也算是做 ...

  3. Selenium Grid 学习笔记

    Selenium Grid 学习笔记http://www.docin.com/p-765680298.html

  4. 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 ...

  5. selenium Grid(一)

    selenium grid Quick Start selenium-grid是用于设计帮助我们进行分布式测试的工具,其整个结构是由一个hub节点和若干个代理节点组成.hub用来管理各个代理节点的注册 ...

  6. selenium Grid

    Selenium Grid 的机制是启动一个 hub,然后启动多个 Selenium RC 注册到 hub 上, 当测试请求到 hub 时,hub 会将测试分发给 Selenium RC, Selen ...

  7. selenium grid java 资料

    Grid TestNG: 使用Selenium Grid改进Web应用程序的测试: http://www.ithov.com/server/117464.shtml

  8. Selenium Grid跨浏览器-兼容性测试

    Selenium Grid跨浏览器-兼容性测试 这里有两台机子,打算这样演示: 一台机子启动一个作为主点节的hub 和 一个作为次节点的hub(系统windows 浏览器为ie) ip为:192.16 ...

  9. selenium grid的使用与配置

    一.selenium grid的组成与作用:由一个集线器hub和多个客户机node组成,如果你的程序需要在不用的浏览器,不同的操作系统上测试,而且比较多的case需要多线程远程执行,那么一个比较好的测 ...

  10. 初识Selenium(四)

    用Selenium实现页面自动化测试 引言 要不要做页面测试自动化的争议由来已久,不做或少做的主要原因是其成本太高,其中一个成本就是自动化脚本的编写和维护,那么有没有办法降低这种成本呢?童战同学在其博 ...

随机推荐

  1. 泛函编程(17)-泛函状态-State In Action

    对OOP编程人员来说,泛函状态State是一种全新的数据类型.我们在上节做了些介绍,在这节我们讨论一下State类型的应用:用一个具体的例子来示范如何使用State类型.以下是这个例子的具体描述: 模 ...

  2. 常见的几种RuntimeException

    一般面试中java Exception(runtimeException )是必会被问到的问题 常见的异常列出四五种,是基本要求.更多的....需要注意积累了   常见的几种如下:   NullPoi ...

  3. 硅谷新闻4--解决页签手指按下从左到右滑动的bug

    有一种方法可以阻止父层的View截获touch事件,就是调用 getParent().requestDisallowInterceptTouchEvent(true);方法.一旦底层View收到tou ...

  4. DOM笔记整理及应用实例

    一.前言 当网页被加载时,浏览器会创建页面的文档对象模型(Document Object Model).HTML DOM 模型被构造为对象的树 通过可编程的对象模型,JavaScript 获得了足够的 ...

  5. win10应用部署到手机出现问题Exception from HRESULT: 0x80073CFD

    今天把应用部署到手机上时,出现了这样的问题 Exception from HRESULT: 0x80073CFD 具体错误是: Error Error : DEP0001 : Unexpected E ...

  6. Android Http请求框架一:Get 和 Post 请求

    1.HttpUtil package com.app.android01; import java.io.BufferedReader; import java.io.IOException; imp ...

  7. android 多屏幕适配 : 第一部分

    1.在xml布局文件中,控件的宽度和高度用  dp ;   字体大小用 sp 2.根据屏幕的宽高来动态的适配 , 获取屏幕的宽高的两种方法: 第一种方法: /** * 屏幕的宽度 * 屏幕的高度 * ...

  8. 安卓开发_浅谈Service

    一.Service(服务) Service是Android程序中四大基础组件之一,它和Activity一样都是Context的子类,区别在于它没有UI界面,是在后台运行的组件. public abst ...

  9. JAVA基础学习day24--Socket基础一UDP与TCP的基本使用

    一.网络模型 1.1.OIS参考模型 1.2.TCP/IP参考模型 1.3.网络通讯要素 IP地址:IPV4/IPV6 端口号:0-65535,一般0-1024,都被系统占用,mysql:3306,o ...

  10. Linux学习书目

    Linux基础 1.<Linux与Unix Shell 编程指南> C语言基础 1.<C Primer Plus,5th Edition>[美]Stephen Prata著 2 ...