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:
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:
Related
So I'm trying to setup an automated build and test flow, with Jenkins and Selenium grid on a central EC2-instance and nodes on physical machines located at my office.
I don't have port forwarding available at my office.
So I was thinking that I could use a VPN (not a proxy) to connect the machines, as though they were on the same network.
So my setup is currently:
The hub (EC2) with Wireguard
java -jar selenium-server-4.7.2.jar hub --host 0.0.0.0 --allow-cors true --bind-host false
A linux-laptop node
java -jar selenium-server-4.7.2.jar node --hub http://<wireguard-hub>:4444 --host <wireguard-ip> --port 5555 --bind-host false
A windows desktop node
java -jar selenium-server-4.7.2.jar node --hub http://<wireguard-hub>:4444 --host <wireguard-ip> --port 5555 --bind-host false
The nodes are able to do a GET-request to the hub and get a proper json response and the hub is able to do the opposite. But the Selenium software get stuck on [NodeServer$1.lambda$start$1] - Sending registration event....
I've tried running all parties with --log-level FINEST, but all I see is that the hub isn't receiving the request. Both from linux and windows.
I've tried running both nodes as hubs too and they are able to connect to themselves, but not each other (through WireGuard).
So can anyone tell me why I can, but at the same time can't, connect my grid?
EDIT (4. jan 2022):
I have now tried running the node on the same EC2-instance with docker as the Webdriver and that doesn't work either.
The node starts, connects to docker and gets stuck at the same spot.
This (in my mind) points to it being an issue with the EC2-instance.
For now I'll be running it in standalone mode, to get the rest of the pipeline working.
I want to run the selenium test cases in the remote machine.
These are the steps I have followed:
Steps I did in server machine:
I have downloaded selenium-server-standalone-3.9.1.jar + Chrome Driver & placed it in a folder and added it to $PATH environmental variable.
I have started selenium server using java -jar selenium-server-standalone-3.9.1.jar -role hub in the Terminal.
Steps I did in local machine:
I have installed selenium-webdriver & selenium-server-standalone-3.9.1.jar
I wrote a sample testcase using selenium webdriver.
I have started a node here using command java -jar selenium-server-standalone-3.9.1.ja-role node -hub http://172.24.111.70:4444/grid/register in the terminal. The node got connected to the hub.
I run the command node test.js in the terminal. I expect the chrome instance to open in the remote machine. But it is running in the local machine.
Screenshots:
Hub:(Remote)
Node:(Local)
Can you please explain me the mistake I have did here? Have I understood the concept wrong?
The web browser instance which will run your tests will get created on a node not the hub. The hub is how you can register a number of nodes so you can spread the load between different machines/nodes. From what I can tell, you have a hub on the remote machine which you connect a local node to.
What I think you want is to run the node on the remote machine also, registering to the hub on the same machine (you might have to change the IP address of the hub to localhost when registering the node).
So, the problem is you are wanting the tests to run on the Remote Machine, but they are running locally?
From the sounds of it you have done all the setup correctly, and the Hub/Nodes should be working fine. All you need to do, is instead of running the Node from your local machine, run it from the Remote Machine. You just need to think of the Hub as the Supervisor, who hands out work to the Nodes (their employees) to do. The Hub doesn't run any tests itself, it just sends the data to the Nodes and load balances between multiple Nodes.
We have a set up of 6 Remote Machines. Machine 1 has the Hub and a Node, and the other 5 have Nodes. In our project we are pointing towards the Hub, so when the tests run, they get sent there. The hub does the rest (depending on the nodecfg file and the settings you've got in there)
In Selenium Grid, is there any limit of nodes on the same machine.
I have 500 test suites to run in parallel, and considering to setup a hub with 25 nodes each with MaxSessions of 20 Firefox browsers in the same machine or should I run virtual machines with Linux platform and register my nodes there to the hub?
Thank you for your advises.
Yes, you can limit the number of nodes with selenium grid
you can do something like this:
Start Hub with max number of session (use -maxSession 500)
Start node with limited number browsers. Since you want 25 nodes, with 20 firefox browser. It would look like something like this (assuming you are using java):
Java -jar %SELENIUM_GRID_VERSION% -role node -hub %HUB_URL% -browser browserName=firefox,maxInstances=20,platform=LINUX
This will insure that only 20 firefox browser will open on node1.
I would advice you to use Virtual Machines to run your test suite. Especially since you want run your test suites parallel. Running on same machine will use up a lot of your computer resources and the nodes might not register with hub or give you an error like "Unable to bind to locking port XXXX within 45000 ms", causing your test to fail.
machine1:
java -jar selenium-server-standalone-2.43.1.jar -role hub
machine2:
java -jar selenium-server-standalone-2.43.1.jar -role node -browser browserName=chrome,maxInstances=1
All tests go to web app on the third machine. From fourth machine I run same amount of tests:
locally: 0m27s
remotely through grid: 2m50s
All of them running on the same local network. Why it's so slow then?
What should I check to find the bottleneck?
UPDATE1: ping between all machines ~0.03ms-0.89ms
I'd check the ping times between the servers. (I'm assuming in every case the test are running through the grid.)
If not, the grid is going to be your bottleneck.
You can speed things up if you keep in mind that every time you try to retrieve something from the web page, it has to go through the grid. Many times you can cache information.
I wrote about that here: http://blog.dmbcllc.com/selenium-performance-improvements/
So the problem was in abnormal load at the machine1 with grid server proccess running.
# uptime
14:35:31 up 9 days, 21:55, 2 users, load average: 2.86, 2.18, 2.16
I moved selenium grid server process to other fresh machine and everything speeds up.
I would like to check my selenium grid test cases on a server(any machine other than localhost).I need chrome , firefox and IE browsers in the server. Is there any way to do this ? I checked few sites like koding.com , but it is only offering me unix interface,I need full windows/Ubuntu interface.
Please let me know if there is any other method to execute my test cases ?
VirtualBox is good and works well for grid tests, I expect it to be a fairly common solution. Same IP is not a problem as you make it work with port forwarding on your desktop. For example you should manage to build a grid like the following:
-role hub on your Windows host on port 4444
-role node on an Ubuntu VM with port forward 5556 in VirtualBox, for Firefox
-role node on an OSX VM with port forward 5557 in VirtualBox, for Safari
-role node on a Windows VM with port forward 5558 in VirtualBox, for IE and Chrome
node with socat+flynnid.py on an Android emulator with port forward 5559
maybe also iPhone Simulator from inside OSX VM (I don't remember if I made it work with grid)
The Selenium Grid "user interface" as you say, is the same , whether it is Linux or Windows. The only difference is that on Linux you won't have an IE driver.
What you do is run a Grid Hub on your local machine and then register "Node" servers on each remote machine. Each Node server can run any combination of web browsers that you mentioned and it is also capable of running them simultaneously (if your test suite was programmed carefully).
The .jar file that you start the Grid Hub with is the same .jar file you use to start the Nodes. The only difference is that each Node will have a .json config file with it that explains the configuration of that server such as where the IE and Chrome binary files are located at on the remote server, what browsers it supports, and how many threads it can handle.
Look at the documentation I wrote (for Grid hub config) on the GitHub "Selenium documentation" site.