问题描述
我是 Selenium、TestNG 和 Selenium Grid 的新手.我对什么时候需要使用 Selenium Grid 有点困惑.以下是我对此的理解.如果我是对的,请告诉我:
- Selenium Grid 仅用于在另一台机器上远程运行您的测试
- 如果我需要在本地机器上并行运行测试,则无需使用 Grid.这可以通过仅使用 TestNG 来实现
- 如果我需要在不同的远程机器上并行执行我的测试,那么我必须将 selenium Grid 与 TestNG 一起使用.
所以我的理解是,Selenium 网格的目的不是并行执行.它用于远程执行.并行执行是通过 TestNG 实现的.仅使用网格无法并行执行.这是正确的吗?
您的结论非常正确,Selenium Grid 的目的是在远程机器上远程执行测试.分发测试的两个主要原因是:
- 减少测试套件的执行时间.
- 为了避免本地主机上的内存(例如 RAM)紧缩,您可以在以下位置找到一些相关讨论:
启动 Selenium 网格节点:
java -Dwebdriver.chrome.driver=chromedriver.exe -jar selenium-server-standalone-3.141.59.jar -role node -port 7777 -hub http://192.168.1.125:4444/grid/登记
生成的日志:
18:33:55.959 INFO [GridLauncherV3.parse] - Selenium 服务器版本:3.141.59,修订版:e82be7d35818:33:56.112 信息 [GridLauncherV3.lambda$buildLaunchers$7] - 在端口 7777 上启动 Selenium Grid 节点2020-01-02 18:33:56.584:INFO::main:日志初始化@983ms 到 org.seleniumhq.jetty9.util.log.StdErrLog18:33:56.913 信息 [WebDriverServlet.<init>] - 初始化 WebDriverServlet18:33:57.029 INFO [SeleniumServer.boot] - Selenium Server 已启动并在端口 7777 上运行18:33:57.029 INFO [GridLauncherV3.lambda$buildLaunchers$7] - Selenium Grid 节点已启动并准备注册到集线器18:33:57.195 信息 [SelfRegisteringRemote$1.run] - 启动自动注册线程.将尝试每 5000 毫秒注册一次.18:33:57.734 INFO [SelfRegisteringRemote.registerToHub] - 将节点注册到集线器:http://192.168.1.125:4444/grid/register18:33:57.856 INFO [SelfRegisteringRemote.registerToHub] - 节点已注册到集线器并准备使用
通过url
http://localhost:4444/grid/console
再次访问Selenium Grid Console v.3.141.59,查看注册节点:
I am new to Selenium, TestNG and Selenium Grid. I got slightly confused about when exactly I need to use Selenium Grid. Below are my understandings on this. Just let me know if i am right :
- Selenium Grid is only for running your tests remotely on another machine
- If I need to run my tests parallelly in my local Machine, there is no need to use Grid. That can be achieved by using TestNG only
- If I need to execute my test, parallelly on different remote machines, Then i have to use selenium Grid along with TestNG.
So what i understand is, the purpose of Selenium grid is NOT parallel execution. It is for remote execution. Parallel execution is achieved via TestNG. It is not possible to do parallel execution by only using Grid. Is this correct?
解决方案You are pretty correct in your conclusion that the purpose of Selenium Grid is to execute the tests remotely on remote machines. The two main reasons to distribute your tests are:
- Reduce execution time of your Test Suite.
- To avoid memory (e.g. RAM) crunch on your localhost and you can find a couple of relevant discussions in:
Remote WebDriver
As per the official documentation of Remote WebDriver:
A remote WebDriver is composed of two parts: the server and the client. The client is the WebDriver test and the server is simply a Java servlet, which can be hosted in any modern JEE app server.
Remote WebDriver server
The Remote WebDriver server will always run on the machine with the browser you want to test. The server can be initiated either from the command line (or through code configuration).
Remote WebDriver client
To run a Remote WebDriver client you have to first connect to the RemoteWebDriver. We do this by pointing the URL to the address of the server running our tests.
Steps in details
You need to follow the below mentioned steps:
Start the Selenium Grid Hub:
java -jar selenium-server-standalone-3.141.59.jar -role hub
Logs generated:
18:10:13.310 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358 18:10:13.618 INFO [GridLauncherV3.lambda$buildLaunchers$5] - Launching Selenium Grid hub on port 4444 2020-01-02 18:10:14.605:INFO::main: Logging initialized @2136ms to org.seleniumhq.jetty9.util.log.StdErrLog 18:10:15.504 INFO [Hub.start] - Selenium Grid hub is up and running 18:10:15.509 INFO [Hub.start] - Nodes should register to http://192.168.1.125:4444/grid/register/ 18:10:15.510 INFO [Hub.start] - Clients should connect to http://192.168.1.125:4444/wd/hub
Access the Selenium Grid Console v.3.141.59 through the url
http://localhost:4444/grid/console
:
Start the Selenium Grid Node:
java -Dwebdriver.chrome.driver=chromedriver.exe -jar selenium-server-standalone-3.141.59.jar -role node -port 7777 -hub http://192.168.1.125:4444/grid/register
Logs generated:
18:33:55.959 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358 18:33:56.112 INFO [GridLauncherV3.lambda$buildLaunchers$7] - Launching a Selenium Grid node on port 7777 2020-01-02 18:33:56.584:INFO::main: Logging initialized @983ms to org.seleniumhq.jetty9.util.log.StdErrLog 18:33:56.913 INFO [WebDriverServlet.<init>] - Initialising WebDriverServlet 18:33:57.029 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 7777 18:33:57.029 INFO [GridLauncherV3.lambda$buildLaunchers$7] - Selenium Grid node is up and ready to register to the hub 18:33:57.195 INFO [SelfRegisteringRemote$1.run] - Starting auto registration thread. Will try to register every 5000 ms. 18:33:57.734 INFO [SelfRegisteringRemote.registerToHub] - Registering the node to the hub: http://192.168.1.125:4444/grid/register 18:33:57.856 INFO [SelfRegisteringRemote.registerToHub] - The node is registered to the hub and ready to use
Access the Selenium Grid Console v.3.141.59 again through the url
http://localhost:4444/grid/console
to view the registered node:
这篇关于Selenium Grid 的确切用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!