Ranorex Logo

How to Use Ranorex With Chrome Dev Tools Through Selenium 4

|
Ranorex With Chrome Dev Tools

With the release of Ranorex 11.0, we’ve introduced support for the Selenium 4 WebDriver protocol, integrating Chrome Dev Tools capabilities. This enhancement allows testers to access and interact with features like Network Condition, Memory Status, Security, and GeoLocation in Chrome using Ranorex. As an example, a user can access and set the geolocation settings, emulate the request from a specific device, and interact with the network requests and responses.

How to Add User Code to Your Solution

To leverage these new capabilities, here’s how you can add user code to your Ranorex solution:

  1. Right-click to add the user code collection
  2. Select ‘insert new user code method”
  3. Make it public static
  4. Save it
  5. Go to the recording module
  6. Click on add new action
  7. Select use code
  8. User-defined methods will display

The Ranorex WebDriver Integration with Selenium 4 can access the Chrome Dev Tools with some simple user code. To get started make sure your header looks like this:

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Threading;
using WinForms = System.Windows.Forms;

using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Repository;
using Ranorex.Core.Testing;

namespace ChromeDevTools

Security Starting Point for the User

public void PlayWithSecurity()
        {
            var devToolsSession = Host.Current.GetDevToolsSession();
            if (devToolsSession != null) {
                var session = (OpenQA.Selenium.DevTools.DevToolsSession) devToolsSession.GetBrowserSession();
                if (session != null) {
                    var domains = session.GetVersionSpecificDomains<OpenQA.Selenium.DevTools.V114.DevToolsSessionDomains>();
                    var security = domains.Security;
                    var command = new OpenQA.Selenium.DevTools.V114.Security.SetIgnoreCertificateErrorsCommandSettings();
                    command.Ignore = true;
                    security.SetIgnoreCertificateErrors(command).Wait();
                }
            }
        } 

GeoLocation Starting Point for the User

 public void PlayWithGeoConditions()
          {
            var devToolsSession = Host.Current.GetDevToolsSession();
            if (devToolsSession != null) {
                var session = (OpenQA.Selenium.DevTools.DevToolsSession) devToolsSession.GetBrowserSession();
                if (session != null) {
                    var domains = session.GetVersionSpecificDomains<OpenQA.Selenium.DevTools.V114.DevToolsSessionDomains>();
                    
                    var emulation = domains.Emulation;
                    var geolocationCommand = new OpenQA.Selenium.DevTools.V114.Emulation.SetGeolocationOverrideCommandSettings();
                    geolocationCommand.Latitude = 50.2334;
                    geolocationCommand.Longitude = 0.2334;
                    geolocationCommand.Accuracy = 1;
                    Report.Log(ReportLevel.Info, "Selenium", "Set geolocation");
                    emulation.SetGeolocationOverride(geolocationCommand).Wait();
                }
            }
        }

Memory Starting Point for the User

  public void PlayWithMemory()
        {
            var devToolsSession = Host.Current.GetDevToolsSession();
            if (devToolsSession != null) {
                var session = (OpenQA.Selenium.DevTools.DevToolsSession) devToolsSession.GetBrowserSession();
                if (session != null) {
                    var domains = session.GetVersionSpecificDomains<OpenQA.Selenium.DevTools.V114.DevToolsSessionDomains>();
                    
                    var memory = domains.Memory;
                    OpenQA.Selenium.DevTools.V114.Memory.GetDOMCountersCommandResponse response = memory.GetDOMCounters().GetAwaiter().GetResult();
                    Report.Log(ReportLevel.Info, "Selenium", response.Nodes.ToString());
                }
            }
        } 

Network Conditions Starting Point for the User

     public void PlayWithNetworkConditions()
        {
            var devToolsSession = Host.Current.GetDevToolsSession();
            if (devToolsSession != null) {
                var session = (OpenQA.Selenium.DevTools.DevToolsSession) devToolsSession.GetBrowserSession();
                if (session != null) {
                    var domains = session.GetVersionSpecificDomains<OpenQA.Selenium.DevTools.V114.DevToolsSessionDomains>();
                    var network = domains.Network;
                    network.Enable(new OpenQA.Selenium.DevTools.V114.Network.EnableCommandSettings()).Wait();
                    
                    var networkConditionsCommand = new OpenQA.Selenium.DevTools.V114.Network.EmulateNetworkConditionsCommandSettings();
                    networkConditionsCommand.Latency = 5000;
                    Report.Log(ReportLevel.Info, "Selenium", "Emulate network conditions");
                    network.EmulateNetworkConditions(networkConditionsCommand).Wait();
                }
            }
        }

Network Request Starting Point for the User

       public void PlayWithNetworkRequests()
        {
            var devToolsSession = Host.Current.GetDevToolsSession();
            if (devToolsSession != null) {
                var session = (OpenQA.Selenium.DevTools.DevToolsSession) devToolsSession.GetBrowserSession();
                if (session != null) {
                    var domains = session.GetVersionSpecificDomains<OpenQA.Selenium.DevTools.V114.DevToolsSessionDomains>();
                    var network = domains.Network;
                    network.ResponseReceived += ResponseReceivedHandler;
                    
                    network.Enable(new OpenQA.Selenium.DevTools.V114.Network.EnableCommandSettings()).Wait();
                }
            }
        }

Get the Most From Chrome Dev Tools and Selenium 4 With Ranorex

Ranorex 11.0’s integration with Selenium 4 and Chrome Dev Tools offers a powerful enhancement to your testing toolkit. By incorporating these functionalities into your Ranorex solutions, you can interact more dynamically with various browser aspects like Security, GeoLocation, Memory, and Network Conditions. This opens up new avenues for comprehensive testing and debugging directly from your Ranorex environment. We encourage you to experiment with these capabilities and see how they can elevate your testing strategies.

In This Article

Sign up for our newsletter

Share this article

Related Articles

DevOps-Test-Automation-5-Best-Practices-and-Essential-Tools-blog-image

DevOps Test Automation: 5 Best Practices and Essential Tools

March 5, 2026

DevOps test automation enables teams to work faster and create better products. These best practices and tools make it easier to implement test automation.

9-Best-Automated-UI-Testing-Tools-Top-Platforms-Compared-blog-image

9 Best Automated UI Testing Tools: Top Platforms Compared

February 19, 2026
UI testing automation should accelerate releases and free QA teams from repetitive tasks.  Instead, many teams struggle with tools that only work for web apps when they need desktop coverage, require programming expertise their testers lack, or generate unreliable tests that...
Playwright-vs-Selenium-Why-Neither-May-Be-the-Right-Choice-blog-image

Playwright vs Selenium: Why Neither May Be the Right Choice

February 5, 2026
The Playwright vs Selenium debate misses the point. Teams argue about execution speed and API design while ignoring something more basic: both tools only work inside web browsers. If your app has a desktop installer, native dialogues, or actual mobile components, you will encount...