selenium grid能够让测试脚本在不一样平台、不一样浏览器执行,是测试用例分发的框架。html
selenium grid 分为两种角色:hub 和 node.java
http://selenium-release.storage.googleapis.com/index.html 下载selenium-server-standalone-2.53.0.jarnode
java -jar selenium-server-standalone-2.53.0.jar -role hub
这个命令的含义是让当前电脑当作hub,并启动服务git
控制台输出 "Selenium Grid hub is up and running" 说明已经启动成功。github
浏览器中打开grid控制台 http://localhost:4444/grid/console
chrome
1.直接经过命令修改: java -jar selenium-server-standalone-2.53.0.jar -role hub -port 4445
json
2.经过Json文件修改: java -jar selenium-server-standalone-2.53.0.jar -role hub -hubConfig hub.json
windows
https://github.com/SeleniumHQ/selenium/wiki/Grid2#configuring-the-nodes-by-json Configuring the hub by JSON java -jar selenium-server-standalone.jar -role hub -hubConfig hubconfig.json A sample hubconfig.json file can be seen at https://github.com/SeleniumHQ/selenium/blob/master/java/server/src/org/openqa/grid/common/defaults/DefaultHub.json
java -jar selenium-server-standalone-2.53.0.jar -role node -hub http://192.168.1.110:4444/grid/register
api
hub的地址是注册hub成功后控制台返回的地址浏览器
经过命令修改: java -jar selenium-server-standalone-2.53.0.jar -role rc -port 6666
经过JSON文件修改
Configuring the nodes by JSON java -jar selenium-server-standalone.jar -role node -nodeConfig nodeconfig.json A sample nodeconfig file for server version 3.x.x (>= beta4) can be seen at https://github.com/SeleniumHQ/selenium/blob/master/java/server/src/org/openqa/grid/common/defaults/DefaultNodeWebDriver.json A sample nodeconfig file for server version 2.x.x can be seen at https://github.com/SeleniumHQ/selenium/blob/selenium-2.53.0/java/server/src/org/openqa/grid/common/defaults/DefaultNode.json Note: the configuration { ... } object in version 2.x.x has been flattened in version 3.x.x (>= beta4)
DesiredCapabilities capabilities = DesiredCapabilities.chrome(); WebDriver driver = new RemoteWebDriver(new URL("http://192.168.29.79:4444/wd/hub"), capabilities); driver.get("http://www.baidu.com");