How to get the number of idle browsers for a node in selenium grid2 - selenium

My current setup is 5 nodes with 10 Firefox browsers each, all connected to a hub.
I am running into a problem where I am exhausting the 10 firefox browsers for each node. So any new selenium runs are getting queued up at the Hub and running when any FF browser for a node becomes available.
What I want to do is somehow query the selenium grid2 hub to get the number of free/idle/available browsers before actually running my tests on that particular grid setup. Based on my result I would redirect the tests to another grid setup (on another machine) or may be not even run the tests.
Of course I can add more nodes or even increase the number of browsers that can be handled by each node. But I am looking for an answer which will help me query the Grid and then allow me to decide on what action I can take rather than muscling my way by brute force (bigger server to handle more browser sessions).
I also sense that this may be a feature not implemented by Selenium Grid 2, so was wondering how others have got around this problem.

It provides sessions information from each selenium node in a selenium grid. You can get the session information of each node like this (assume your selenium node listens to port 5555):
$ curl http://<selenium-node>:5555/wd/hub/sessions
You will get a JSON object response like this:
{"value":[],"sessionId":null,"status":0,"hCode":1542413295,"class":"org.openqa.selenium.remote.Response"}
Then you can calculate how many active sessions from the "value" array value on each selenium node when it hits those nodes. Then you know how many left.

Related

Is it possible to login different nodes with different login ID's parallelly using selenium grid?

I am tiring to login to Gmail account with different user name with selenium grid (java) parallelly. I have 5 nodes each node should use different user name. All the user names are provided in excel. Can anyone help me to do this action?
Selenium Grid allows the execution of WebDriver scripts on remote machines (virtual or real) by routing commands sent by the client to remote browser instances. It aims to provide an easy way to run tests in parallel on multiple machines.
Selenium Grid allows us to run tests in parallel on multiple machines, and to manage different browser versions and browser configurations centrally (instead of in each individual test).
Selenium Grid is not a silver bullet. It solves a subset of common delegation and distribution problems, but will for example not manage your infrastructure, and might not suit your specific needs.
Please note Grid 3 is not supported anymore and the Selenium project recommends to use Grid 4

is selenium grid a solution to my problem with executiontimes?

Hi all I am using TestNG framework for selenium webdriver scripts. I run them on Jenkins on two slaves one being windows the other being linux. I have close to 100 test cases and they take 2hrs 40 mins on each machine. I would want to speed up the execution time. will selenium grid be helpful in this case?
No. Selenium grid would not be the solution. Selenium grid can multiply the same action, not taking different actions in parallel.
You should look for the opportunities in test parallelization.
Selenium grid is designed to allow you to run test in parallel
The page says:
Selenium Grid allows us to run tests in parallel on multiple machines, and to manage different browser versions and browser configurations centrally (instead of in each individual test).
However it's not as easy as installing it and connecting up.
You'll need to ensure the rest of your framework and tests are capable of parallel execution. Most important part is to watch out for your test data e.g. if multiple tests rely on the same data source and they try and update it at the same time you'll get flaky results.
You're also capable of running tests in parallel on a local machine without selenium grid. If i were you i'd start with this first.
Typically most machines have the resources to run more than one browser - get it running locally before you go to far down the grid rabbit hole.
Here's a link for testng
Also worth a review is zalenium - a docker image that contains a grid + auto scaling nodes allowing easier browser control on a single machine.

A way to ping selenium hub to see if node is available?

Does anyone have a shell script or know of a way to ping a selenium hub to see if Nodes are available. Like a way to use wait-for or wait-for-it or another way to check the Selenium Hub for a node before triggering a test?
EDIT: A specific node with a browser version available. So for example if the hub has Chrome 64 attached and Chrome 63 is connecting I'm trying to ping the hub until the Chrome 63 node attaches to the hub and is available for use.
There is an endpoint in the Selenium Hub that can give you some of this info.
way to check the Selenium Hub for a node before triggering a test
Do a GET to http://your-hub-here:4444/grid/api/hub and you should see the free/total slotCounts (look at newSessionRequestCount to see queued tests). It doesn't have the granularity to show different browsers but you can get overview to determine if your grid is saturated.
Or if you are using Selenium Grid Extras there would probably be an API behind their webview, that you would call to get the number of available browsers.
Try this if you run docker on your local machine http://localhost:4444/wd/hub/status
Here is a general from http://{location}:4444/wd/hub/status

Windows Authentication using Selenium Grid and Webdriver

I was asked a question :
Assume I have 4 machines and I need to execute a script in all the machines across all the browsers. How will I achieve that.
I told him the concept of Selenium Grid, where in we could set up a machine which acts like a hub, configure 3 more machines which would act like a node.
Using Desired Capabilities among others we could choose a browser type and version type in that and write a script.
But he asked me two things :
IN all the node machines how do you configure the Windows username and Password if the machine is locked. Can you write windows Authentication in the script.
Can I achieve testing different browser versions of same browser type in a single node?
Can I pass as a the browser type and browser version as a parameter
from hub to the node?
Can someone throw some light on these as I was unable to answer. Thanks.
Question 1: Is it really necessary for the machine to be unlocked for the test to start? The selenium node is a background process that listens for commands, and executes them on the browser, so I do not think this is necessary. If it is necessary due to your specific windows settings however, then no, you cannot do this from the selenium script obviously.
Question 2: Yes, you can test different browser versions of the same type on the same node. You can pass the browser name and version to the node. However, keep in mind that the node cannot know the location of the different browser versions, so you will also have to supply the path to the browser executable for your requested version

Can we set the selection of browser default ?

i am running my suite using selenium grid on different ports parallely. i am passing the port and browser to the defaultselenium method statically. Things are running good but i want to run my tests on different instances of grid on different browser.That is not happening with this setup though it is picking port independently that is good but it runs only on single type of browser that is specified in selenium method.Is there any way that my tests picks the browser value as specified on grid instance. Or any way with which we can set default browser value in selenium method ?
The grid simply makes the browsers available and gives you a single point to connect to (the hub) from your client. It is up to you to make your code request the browser you want and run your tests in parallel.