Debugging remotely in Chrome within a Selenium grid

Currently, I am managing a selenium-grid setup that consists of multiple chrome instances. The selenium grid is spread across 2 Windows machines with several nodes. The test executions are carried out from a separate machine that connects to the grid. In order to utilize remote debugging functionality, it is necessary for me to establish connections from the executing machine (which can access the session host and the drivers' debugUrl) to the other machines and ultimately the chrome instances.

However, Chrome strictly prohibits any connection that is not local.

I have come across solutions where individuals have used tunneling or port forwarding, but these methods seem suitable only for single instance setups. Operating within a grid environment means I do not have static ports or rules in place for consistent forwarding.

In my specific scenario, the grid is created automatically and is not a continuously running system.

If anyone has any valuable insights on how to resolve this issue, I would greatly appreciate it.

Answer №1

I came across a solution on my own and wanted to share it. I will provide snippets of code instead of the entire code to give hints, as it can be quite extensive. An experienced developer should find this information sufficient.

To target the correct browser and access its remote-debug websocket, I created a custom servlet for my nodes.

Here is the servlet:

public class DebugServlet extends RegistryBasedServlet

The servlet is registered through node.json like so:

"servlets" :["com.....ui.util.DebugServlet"],

To access the node (on the appropriate machine), I request the selenium session using the following method:

"http://" + hubHost + ":" + hubPort + "/grid/api/testsession?session=" + sessionId

Where the "sessionId" can be obtained from chromedriver.

From the JSON response received, we can extract the node information of the session, particularly the URL.

url = JSONUtil.get(response.getBody(), "proxyId")

Now we can call the servlet of the correct host and provide the WebSocket URL for the browser and any necessary data. For example, adding a default network header for BasicAuth in my case.

url+ "/extra/DebugServlet"

With the header specified in Java (which can also include parameters or other HTTP provided options):

new BasicHeader("BrowserUrl", webSocketDebuggerUrl), new BasicHeader("Name", name),
                new BasicHeader("Value", value)

In the servlet, we extract the data and establish a WebSocket connection to the browser with the given URL to make our calls.

In the servlet:

public static final String networkDebugging = "{\"id\": 1,\"method\": \"Network.enable\",\"params\": {\"maxTotalBufferSize\": 10000000,\"maxResourceBufferSize\": 5000000 }}";

public static final String addHeader = "{\"id\": 2,\"method\": \"Network.setExtraHTTPHeaders\",\"params\": { \"headers\": {\"${key}\": \"${value}\"}}}";


ws.connect();
ws.setAutoFlush(true);
ws.sendText(networkDebugging);

String payload = TemplateUtil.replace(addHeader, name, value);
ws.sendText(payload);

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

I seem to be facing some issues with SkipException in testNG. Can anyone provide guidance on what might be

As a newcomer to selenium UI automation, I am currently experimenting with a simple application using Java and TestNG. My goal is to integrate this test with Continuous Integration (CI), but the test environment URL will vary with each deployment. The ke ...

Refreshing frequency and reattempts when using selenium on a webpage

I am currently utilizing selenium with python to download a file from a URL. from selenium import webdriver profile = webdriver.FirefoxProfile() profile.set_preference('browser.download.folderList', 2) # custom location profile.set_preference(& ...

Are there alternative, more dependable methods for executing a click command on an element in Headless Chrome using Selenium?

For the past two days, I have been struggling with a frustrating issue involving the click() command in Headless Chrome. Specifically, I have been trying to click on an Anchor (a) element with a href tag, and despite trying various suggestions found in dif ...

Encountering a null pointer exception when attempting to declare a WebElementFacade within a page object

While attempting to implement the page object model in Serenity BDD, I encountered a null pointer exception when declaring WebElementFacade in my page object. Below is the code for my page object class: package PageObjects; import net.serenitybdd.core.an ...

Selenium testing with Python on a React.js frontend results in an outdated error message appearing when attempting to enter text into an input field

I am facing an issue with Selenium where the React-js frontend updates the DOM on every character input in the input field. This causes my variable reference to become stale as it no longer points at the correct DOM element. Even though the element still e ...

adjusting the request process in scrapy

import scrapy from selenium import webdriver from scrapy.loader import ItemLoader from scrapy.loader.processors import Join,MapCompose from scrapy.crawler import CrawlerProcess from scrapy.http import HtmlResponse class DemoSpider(scrapy.Spider): name ...

FileDetector feature in Selenium for Java RemoteWebDriver

I'm encountering an issue with file uploads using Selenium's RemoteWebDriver (specifically the Chrome driver, set up with Selenium Grid). A problem similar to the one discussed in this thread: Sending Keys to Input WebElement fails as it is not ...

Extracting information from Trading View with the help of Selenium

I'm facing a challenge while attempting to web scrape data from a trading view chart using an infinite loop – I keep encountering the StaleElementReferenceException error. Despite my efforts to address this by making the program wait explicitly, I r ...

Can a string be separated into an array using Selenium IDE?

Can anyone help me figure out how to separate the numbers "1 out of 20" into two variables? I'm looking for a way to assign 1 to one variable and 20 to another variable. Any suggestions? ...

Discovering text within HTML tags without any separators using PHP and Selenium

Here is the HTML code that I am working with: <div id="infos"> NAME COMANY <br> 35 South , Wimbledon <br>SA51 8RR London <br>***United Kingdom Phone: +##-##-####.#### Fax: +##-##-###.####*** <br> & ...

I attempted to access the website through selenium using this code, but to my surprise, the site shut down immediately upon opening

Upon running this code, the webpage quickly opens and then just as swiftly closes. Despite using the most up-to-date version, I am unable to access the page. It is worth noting that I am a Windows user. The intention behind running this code was to access ...

We are encountering a 503 error while working with AWS Lambda and Python Selenium

I encountered an issue while attempting to scrape a website using AWS lambda. The unique nature of the website prompted me to opt for AWS lambda as my scraping tool. The process involves receiving a request containing information required to access the tar ...

Automating Jenkins interfaces using selenium automation techniques

I am looking to create a system that can automatically detect any flakiness in my test scripts. I need to track the pass percentage of a certain number, let's say n builds, for a specific job. Unfortunately, using Xpaths to collect this data is not pr ...

Incorporating an HTML file into the manifest.json file

As a beginner in google chrome extension development, I am excited to start coding and creating my own chrome extension. Currently, I have already created the necessary files like manifest.json, rotate.html, and basic.html. Now, I just need to add these tw ...

When attempting to capture an element screenshot as PNG, a TypeError occurs indicating that the 'bytes' object is not callable

Can someone please help me figure out how to save a screenshot of a specific element in Selenium using Python3? Here is the code I am trying: from selenium import webdriver import pyautogui as pog import time options = webdriver.ChromeOptions() options ...

Selenium tips: Tricks to get past Cloudflare's bot protection

For educational purposes, I am looking to extract information from a website. However, I am facing obstacles due to the protection measures in place. Every time I try to send requests, I encounter the familiar "Checking-your-browser" page followed by con ...

My code is encountering the issue of "element click intercepted" when not using WebDriverWait. On the other hand, when utilizing WebDriverWait, the error message states that 'None

Code Proposal: To simplify the process of gathering links to all games on a given day from the page , I am looking to create a script that allows me to dynamically change the date, such as 2021/08/01 or any other date. This way, I can easily loop through ...

Angular4 ChromeDriver Selenium Protractor

I am facing an issue while trying to run 'ng e2e'. The error message I encounter is as follows: WebDriverError: unknown error: cannot find Chrome binary I am using Protractor which is pre-installed with Angular CLI. Despite reinstalling ChromeD ...

Unable to maximize windows in Firefox on Windows and Chrome on macOS

When using Selenium and the command driver.manage().window().maximize();, I am able to maximize my browser in Windows Chrome successfully. However, when I run the test case on a Mac PC using Chrome or any Mozilla browser, the browser does not maximize. I ...

Using selenium, you can easily download a file without needing the direct URL

I need assistance with using Selenium for website automation in Chrome using vb.net. I am trying to download files from a website that does not have direct URLs for download buttons, as the downloads are triggered by JavaScript. How can I accomplish this i ...