Selenium Grid允许同时并行地、在不同的环境上运行多个测试任务。这里主要演示一下怎么使用Selenium Grid。
准备:
1、需要两台机子
2、两台机子分别安装好JDK环境
3、两台机子需要从 http://code.google.com/p/selenium/downloads/list下载selenium-server-standalone-*.jar包
开始:
Grid需要一台机子做为主节点,然后其它机子做为子节点连接到这个主节点上来。所以首先要启动主节点。
选一台机子做为主节点。打开命令行,cd至selenium-server-standalone-*.jar包的目录下,然后用下面的命令启动主节点服务:
java -jar selenium-server-standalone-2.24.1.jar -role hub
默认启动默认端口为4444。如果要改这个端口,可以再上面的命令后面加上 -port XXXX。启动完后,你可以用浏览 器 打开 http://localhost:4444/grid/console 这个网址查看主节点的状态。
启动完主节点之后,要做的就是启动子节点。
先另一台机子做为子节点。同样打开命令行,cd至selenium-server-standalone-*.jar包的目录下,然后用下面的命令启动次节点服务:
java -jar selenium-server-standalone-2.24.1.jar -role node -hub http://192.168.40.24:4444/grid/register
其中192.168.40.24为主节点机子的ip地址,可以使用ipconfig命令在命令行查看得到。上面命令默认启动5555端口,可使用-port 更改。启动完成连接到主节点后,可以在主节点机子上
,http://localhost:4444/grid/console网址查看到这个子节点状态。使用同样的方法,可以链接其它的子节点。
上面已经把grid弄成功了,现在我们用Grid来运行一个很简单的例子。代码如下:
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class GridTest {
/**
* @throws MalformedURLException
*/
public static void main(String[] args) throws MalformedURLException {
DesiredCapabilities test = DesiredCapabilities.firefox();
WebDriver dr = new RemoteWebDriver(new URL("http://192.168.40.67:5555/wd/hub"),test);
dr.get("http://www.51.com");
}
}
在主节点机子上运行上面的代码,你可以在次节点机子上看到firefox浏览器被启动,然后打开了www.51.com这个网址。
值得注意的是:
WebDriver dr = new RemoteWebDriver(new URL("http://192.168.40.67:5555/wd/hub"),test);
这一句中的192.168.40.67为次节点的ip地址。
分享到:
相关推荐
Selenium WebDriver Practical Guide will guide you through the various APIs of WebDriver which should be used in automation tests, followed by a discussion of the various WebDriver implementations ...
Selenium WebDriver 3 Practical Guide will walk you through the various APIs of Selenium WebDriver, which are used in automation tests, followed by a discussion of the various WebDriver implementations...
精通Selenium WebDriver 3.0,第二版 这是Packt发行的的代码库。... 并学习如何使用Docker容器快速启动Selenium Grid。 在最后的几章中,您将通过一系列场景来演示如何扩展Selenium以使其与外部库和应用程序一起使用,
selenium 是一套完整的web应用程序测试系统,包含了测试的录制(selenium IDE),编写及运行(Selenium Remote Control)和测试的并行处理(Selenium Grid)。 Selenium的核心Selenium Core基于JsUnit,完全由...
Moving on, the book shows you how to utilize the Advanced User Interactions API, how you can run any JavaScript you need through Selenium, and how to quickly spin up a Selenium Grid using Docker ...
开始使用Java进行Selenium WebDriver测试[视频] 这是发行的的代码存储库。 它包含从头到尾完成视频课程所需的所有支持项目文件。 关于视频课程 本课程将使您了解Selenium WebDriver的功能。 您将通过实践测试步骤并...
Selenium 也是一个用于Web应用程序测试的工具。Selenium测试直接运行在浏览器中,就像真正的用户在操作一样。支持的浏览器包括IE、Mozilla Firefox、Google Chrome等。这个工具的主要功能包括:测试与浏览器的兼容性...
Cucumberjvm-webdriver-example ... 在本地启动 selenium Grid Hub(根据需要更改 selenium-server 版本) java -jar selenium-server-standalone-2.44.0.jar -role hub 在本地启动一个 selenium 网
The Selenium WebDriver 3.x Technology is an open source API available to test both Browser and Mobile applications. It is completely platform independent in that tests built for one browser or mobile ...
Selenium WebDriver TestNg 魅力2 Maven执行命令要运行测试并生成魅力报告: mvn clean site -P [singleThreaded,nogrid,grid,parallelSuite]singleThreaded-按顺序执行测试,省略并行执行nogrid-在本地执行测试grid...
The second edition of Mastering Selenium 3.0 WebDriver starts by showing you how to build your own Selenium framework with Maven. You’ll then look at how you can solve the difficult problems that you...
通过将客户端发送的命令路由到远程浏览器实例,Selenium Grid允许在远程计算机(虚拟或真实)上执行WebDriver脚本。它旨在提供一种在多台计算机上并行运行测试的简便方法。 Selenium Grid允许我们在多台计算机上并行...
Selenium Server (Grid) The Selenium Server is needed in order to run Remote Selenium WebDriver (Grid).
Explore the Selenium WebDriver API for easy implementations of small to complex operations on browsers and web applications Packed with easy and practical examples that get you started with Selenium...
You'll design and build a Selenium grid from scratch to enable the framework to scale and support different browsers, mobile devices, and platforms.You'll strategize and handle a rich web UI using the...
使用Selenium Grid和Docker Swarm进行并发Web抓取 想学习如何建立这个项目? 查看。 要使用这个项目吗? 货叉/克隆 创建并激活虚拟环境 安装要求 Digital Ocean并访问令牌 将令牌添加到您的环境中: (env)$ ...
Set up Selenium Grid for faster and parallel running of tests, increasing test coverage and reducing test execution time for cross-browser testing Build extended Selenium WebDriver tests for ...
Over 90 recipes to help you build and run automated tests for your web applications with Selenium WebDriver About This Book Learn to leverage the power of Selenium WebDriver with simple examples that...
Selenium WebDriver is a popular automated testing tool for web applications. Python is one of the top programming languages and when used with Selenium it can automate and test web applications. Using...
Selenium网格 安装selenium-webdriver节点包【需要设置 package.json】 启动集线器 java -jar ... 启动[many] phantom 实例phantomjs --webdriver=8910 --webdriver-selenium-grid-hub= 运行测试节点 index.js