What is the exact purpose of Selenium Grid?
Asked Answered
W

1

3

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?

Wakerly answered 8/1, 2020 at 14:27 Comment(0)
M
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:


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:

SeleniumGridConsole

  • 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:

SeleniumGridConsole_NodeRegistered

Monkhmer answered 8/1, 2020 at 14:46 Comment(1)
For extra info: I used selenium grid to do some repeated tasks on a filtered website (on port 80 and 443) in my hell country Iran. My c# app usingRemoteWebDrive, connects to local Hub and the local Hub connects to my external VPS as my node & run the tasks freely.Burier

© 2022 - 2024 — McMap. All rights reserved.