DEV Community

Cover image for Interacting with Chrome DevTools from WebDriverIO
Anna
Anna

Posted on

Interacting with Chrome DevTools from WebDriverIO

WebDriverIO is a testing framework that lets you automate web applications. One of its powerful features is the ability to interact with Chrome DevTools, which is very useful when testing websites.

With WebDriverIO, you can:

  • Open and control Chrome DevTools automatically when your website loads.
  • Inspect network requests, console logs, and performance without manually opening DevTools.
  • Test Chrome extensions or plugins installed on your website.
  • Automate UI interactions inside DevTools, like clicking buttons, switching tabs, or checking elements.

*General Steps for Testing Chrome DevTools Extensions with WebDriverIO *

**Setting Up Extension

Get the .crx file of the Chrome extension you want to test.

Set Up WebDriverIO in Your Project
**
Make sure WebDriverIO is installed. If not, you can install it by following the official installation guide here [https://webdriver.io/docs/gettingstarted/#initiate-a-webdriverio-setup]

Create a configuration file (wdio.conf.js).

Configure Chrome for Testing

Specify Chrome as the browser in the config.

Use --auto-open-devtools-for-tabs to automatically open DevTools.

Add your extension through the extensions option (read the .crx file in base64).

Write the Test Script

Open the website where the extension will be tested.

Get all window handles.

Switch to the DevTools window using its handle.

Switch to the extension iframe if applicable.

Interact with the extension (clicks, form input, element checks).

Switch back to the main window after testing.

Use Keyboard Shortcuts for DevTools Navigation

Example: Linux: Key.Control + '[' to switch tabs.

Mac: Key.Meta + '['.

Run the Tests

Execute:

npx wdio run wdio.conf.js

Chrome will open the site, DevTools, load the extension, and run your test.

Maintain and Customize

Modify the script for any extension.

Use browser.switchToFrame() and browser.switchToWindow() to manage windows and iframes properly.

Why it’s useful:

  • Helps catch issues faster by combining automated testing with DevTools inspection.
  • Reduces manual debugging steps.
  • Makes testing more thorough, covering both the website and any extensions/plugins that affect it.

By using WebDriverIO with Chrome DevTools, you can test websites more effectively, catch hidden issues, and ensure everything works smoothly for your end users.

Top comments (0)