What is the exact purpose of Selenium Grid?

人走茶凉 提交于 2021-01-29 22:40:31

问题


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 :

  1. Selenium Grid is only for running your tests remotely on another machine
  2. 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
  3. 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?


回答1:


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:
    • Limit chrome headless CPU and memory usage
    • Many process of Google Chrome (32 bit)
    • Selenium using too much RAM with Firefox
    • Is it possible to reduce memory RAM consumption when using Selenium GeckoDriver and Firefox

Remote WebDriver

As per the official documentation of Remote WebDriver:

You can use WebDriver remotely the same way you would use it locally. The primary difference is that a remote WebDriver needs to be configured so that it can run your tests on a separate machine.

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:



来源:https://stackoverflow.com/questions/59647961/what-is-the-exact-purpose-of-selenium-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!