前言
一直想学习自动化测试,但是都没行动,业余时间学习零零碎碎并记录20210423。
9、Selenium Grid 分布式测试
9、Selenium Grid 分布式测试
- Selenium Grid简介
- Selenium Grid下载安装
- Selenium远程测试-客户端
- Selenium分布式测试Grid
- Selenium 注册node节点
- Selenium实现远程测试
- Selenium Grid实现分布式测试
1、创建一个grid文件夹,以前对应文件
2、command_line.md中写的是命令启动hub和node节点
java -jar selenium-server-standalone-3.141.59.jar -role hub -hubConfig hub_config.json
java -jar selenium-server-standalone-3.141.59.jar -role node -nodeConfig node_config.json
3、hub_config.json:配置信息
{
"port": 8888,
"newSessionWaitTimeout": -1,
"servlets" : [],
"withoutServlets": [],
"custom": {},
"capabilityMatcher": "org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
"registry": "org.openqa.grid.internal.DefaultGridRegistry",
"throwOnCapabilityNotPresent": true,
"cleanUpCycle": 5000,
"role": "hub",
"debug": false,
"browserTimeout": 0,
"timeout": 1800
}
4、node_config.json:node节点配置信息
{
"capabilities":
[
{
"browserName": "firefox",
"marionette": true,
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
},
{
"browserName": "chrome",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
},
{
"browserName": "internet explorer",
"platform": "WINDOWS",
"maxInstances": 1,
"seleniumProtocol": "WebDriver"
},
{
"browserName": "safari",
"technologyPreview": false,
"platform": "MAC",
"maxInstances": 1,
"seleniumProtocol": "WebDriver"
}
],
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 5,
"port": -1,
"register": true,
"registerCycle": 5000,
"hub": "http://localhost:8888",
"nodeStatusCheckTimeout": 5000,
"nodePolling": 5000,
"role": "node",
"unregisterIfStillDownAfter": 60000,
"downPollingLimit": 2,
"debug": false,
"servlets" : [],
"withoutServlets": [],
"custom": {}
}
5、把node_config.json和hub_config.json和selenium-server-standalone-3.141.59.jar复制存到到同一个目录下
6、启动服务端(也叫hub启动)。cmd切换到这个路径下重新运行:
java -jar selenium-server-standalone-3.141.59.jar -role hub -hubConfig hub_config.json
dembp selenium-server % java -jar selenium-server-standalone-3.141.59.jar -role hub -hubConfig hub_config.json
22:19:30.614 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358
22:19:30.697 INFO [GridLauncherV3.lambda$buildLaunchers$5] - Launching Selenium Grid hub on port 8888
2021-04-23 22:19:31.063:INFO::main: Logging initialized @656ms to org.seleniumhq.jetty9.util.log.StdErrLog
22:19:31.206 INFO [DefaultGridRegistry.assignRequestToProxy] - Shutting down registry.
22:19:31.216 ERROR [Hub.start] - Port 8888 is busy, please choose a free port for the hub and specify it using -port option
dembp selenium-server %
报错8888端口要钱,把配置里的端口换成默认4444,重启再试下,成功了
dembp selenium-server % java -jar selenium-server-standalone-3.141.59.jar -role hub -hubConfig hub_config.json
22:22:18.257 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358
22:22:18.366 INFO [GridLauncherV3.lambda$buildLaunchers$5] - Launching Selenium Grid hub on port 4444
2021-04-23 22:22:18.769:INFO::main: Logging initialized @740ms to org.seleniumhq.jetty9.util.log.StdErrLog
22:22:18.969 INFO [Hub.start] - Selenium Grid hub is up and running
22:22:18.969 INFO [Hub.start] - Nodes should register to http://192.168.1.4:4444/grid/register/
22:22:18.969 INFO [Hub.start] - Clients should connect to http://192.168.1.4:4444/wd/hub
访问看下,http://localhost:4444/grid/
点击wiki,有一些详细说明
7、再启动客户端(也叫node节点注册),再打开一个终端。
java -jar selenium-server-standalone-3.141.59.jar -role node -nodeConfig node_config.json
再访问看下,http://localhost:4444/grid/console
点击configuration
这就是配置链接好了 。虽然在命令行可以配置 但是参数太多了 还是推荐这种配置文件来配置。
另:记得web驱动要配置环境变量要不然会找不到。我是放到/usr/local/bin下