What can the Selenium Grid Node API do for you?

The challenge at hand:

I am looking to implement Selenium Grid on AWS and leverage their dynamic scaling feature. However, the issue arises during scale down when instances are terminated abruptly, potentially causing nodes to disappear suddenly. This is not the ideal behavior I want for my setup. By utilizing scripts or lifecycle hooks, I aim to ensure that all active sessions on a node are closed before it gets terminated.

It seems that I can utilize this API to disconnect a node from the hub:

Ideally, I am seeking an API that directly connects to the node to collect data on session activity.

Any other suggestions? What about session logs?

Answer №1

Important Note: This response is specifically applicable to the Selenium 3.x series (specifically version 3.14.1, which as of today is the latest in the Selenium 3 series). It's crucial to highlight that the architecture of Selenium 4 grid is significantly different from that of Selenium 3, hence this answer may not be directly relevant for Selenium 4 grid (given that it is yet to be released).

The concept you are inquiring about appears to require a form of self-repairing mechanism, which isn't inherently available in the standard configuration of selenium grid.

It's important to note that Selenium node lacks the ability to track active sessions running on it.

To implement this functionality, it would need to be constructed at the level of Selenium Hub (where all pertinent information is stored).

At a high level, the following steps would need to be taken:

  1. Create a custom proxy by extending
    org.openqa.grid.selenium.proxy.DefaultRemoteProxy
    with the following features:
    1. Incorporate an API that marks the proxy as quiesced when utilized (indicating that the node is undergoing maintenance and will no longer accept new session requests)
    2. Override
      getNewSession(Map<String, Object> requestedCapability)
      to first verify if a node is not quiesced before enabling a new session.
  2. Develop a customized servlet capable of performing the following functions:
    1. When given a node, invoke the API created in step 1.1 to mark the node as quiesced
    2. Provide a list of nodes without any active sessions. If your servlet extends
      org.openqa.grid.web.servlet.RegistryBasedServlet
      , you should be able to retrieve the URLs of free nodes using the code snippet below
List<RemoteProxy> freeProxies =
    StreamSupport.stream(getRegistry().getAllProxies().spliterator(), false)
        .filter(remoteProxy -> !remoteProxy.isBusy())
        .collect(Collectors.toList());
List<URL> urls =
    freeProxies.stream().map(RemoteProxy::getRemoteHost).collect(Collectors.toList());

With this custom Hub now equipped to handle cleanup tasks, you can use the 2.1 endpoint to initiate shutting down nodes and then continuously check the 2.2 endpoint to fetch IP and Port combinations of nodes no longer supporting test sessions, subsequently triggering

http://NODE-IP:5555/selenium-server/driver/?cmd=shutDownSeleniumServer
on them.

Generally speaking, these actions will address your requirements.

For further guidance on this topic, consider exploring the following resource links (each link directs to a blog authored on related subjects):

  1. Self-healing grid -
  2. Building a bespoke proxy -
  3. Developing a unique servlet for the hub -

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Activate the "Do-Not-Track" feature using Selenium in Python

Is there a way in Selenium (with Python) to activate the "Do-Not-Track" function? I am referring to the restriction of a browser (specifically Firefox geckodriver) from accessing the user's geolocation. I am aware that this is feasible and have come ...

Using selenium to click on the initial link displayed on the search results page

I am currently testing a webpage that functions similarly to Google search. Users input their search terms into a text box, click Search, and are then taken to a page with search results matching their query. These results are links to various doc files, a ...

Python Selenium encountering a UnicodeEncodeError issue

Whenever I write and execute my code in PyCharm, everything runs smoothly. However, when I try to open the code in standard Python, an error occurs. Strangely, it works perfectly fine in PyCharm. from selenium import webdriver import time import random ...

What is the best way to duplicate an entire webpage with all its content intact?

Is it possible to copy an entire page including images and CSS using Selenium? Traditional methods like ctrl + a or dragging the mouse over the page do not seem to work. How can this be achieved with Selenium without requiring an element to interact with? ...

cells set to read-only ... ..

It is essential to include the code What specific data format needs to be entered into an Excel cell, along with an example? The problem involves coding elements and an accompanying image for easy reference. The task at hand requires more than simply using ...

Steps to extract information from a WebElement

While in debugging mode, I noticed that the locator for a particular element on the page is shown as: By.name: NameOfMyElement_123. Now, my query is how can I extract and parse the string (By.name: NameOfMyElement_123) using Java to identify the type of t ...

Leveraging explicit waits to enable autocomplete functionality in Selenium

I'm in the process of updating this code to utilize explicit waits: class InputAutocompleteElement(InputElement): def __set__(self, obj, value): driver = obj.driver element = self.find_element(driver, self.locator) time.sleep ...

What is the process for starting Chrome in landscape mode on a mobile emulator using C# Selenium?

Using this C# code, I successfully launched a web page with the Chrome browser in mobile portrait emulator mode: ChromeOptions options = new ChromeOptions(); options.AddArguments("disable-infobars"); options.AddArguments("start-maximized") ...

Inject a String Parameter into a Selenium project

Incorporating a string parameter from Jenkins into my Selenium project is proving to be challenging. This parameter requires frequent updates, and some users are not comfortable with modifying the file in Git every time it needs to be executed. Unfortunate ...

Using Selenium to Launch Chromedriver

How can I configure chromedriver to prevent the web server from detecting whether the browser is manually launched or launched programmatically using Selenium? Appreciate your help, ...

Scraping the web with Python: Selenium HTML elements may differ from what is shown in the inspect tool

In my current academic project, I am facing an issue with scraping news articles from websites. The problem arises when parsing HTML code in Python because the code obtained from the page source is different from what is shown in the Inspect Element tool. ...

Activating RSpec slumber

Currently, I am in the process of writing a feature test to validate an edit action. It's a bit puzzling to me because when I run RSpec normally, it does not show what I expect. However, when I use the save_and_open_page command, it reveals that the e ...

Unable to interact with a button through JavaScript using execute_script in Selenium

https://i.stack.imgur.com/hJmtK.png I am attempting to remove a cookies popup by accepting the cookies and clicking confirm. While I am able to click an input labeled "zgadzam się na", for some reason, clicking a button with the label "potwierdź" appears ...

Error: Unable to launch Chrome - Version 75.0.3770.100

Our C# selenium tests running on Jenkins are experiencing failures during execution with the latest version of Chrome 75, showing the error message "Chrome failed to start." After researching various articles, I have added the following code as arguments ...

I am working on creating an automated system for a website using Selenium WebDriver. Strangely, the xpath is showing up as underlined. Does anyone have any insight into why

Hey everyone, I am facing a minor issue while trying to automate a daily questionnaire. I was following a tutorial on YouTube and at around the 5:50 mark, the instructor copied an xpath code and pasted it on the side. But when I tried the same, my code got ...

Can Selenium C# tests retrieve a parameter from a batch or PowerShell script?

My Selenium tests navigate to a specified URL using the code: driver.Navigate().GoToUrl("www.blahwhatever.com"); Currently, I am able to execute these Selenium tests using either a batch file or PowerShell script. Ideally, these scripts would be triggered ...

Java Selenium WebDriver encountered an exception: The error is unknown and is related to a missing 'value' in the function result

Help needed! I'm encountering an exception when attempting to run my first Selenium WebDriver test case in Java. Can anyone assist? Thanks! Starting ChromeDriver 2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f) on port 48523 Only local connecti ...

Execute JavaScript code on the web browser console using Selenium through Python

I have a JavaScript code that I want to execute in the console when the page loads. However, I am facing difficulties in opening the console using Selenium in Python. I can access the DevTools using the command --auto-open-devtools-for-tabs, but I am una ...

The Extent report generated by Selenium in C# is failing to create the HTML file in the designated directory

I am having trouble with generating an HTML report using Extent report (version="3.1.3") for Selenium Webdriver C#. After running my test script successfully, I can't seem to find the HTML file in the specified folder. If you could assist me in figur ...

Can you explain the functionalities of appium, selendroid, and selenium and how they operate?

I am feeling perplexed about the differences between Appium, Selendroid, and Selenium and how they interact with each other. Is there anyone who can assist me in resolving this issue? ...