Registry / testing / wdio-intercept-service

wdio-intercept-service

JSON →
library4.4.1jsnpmunverified

A WebdriverIO plugin for capturing and asserting HTTP AJAX calls (XHR and fetch) during e2e tests. Current stable version is 4.4.1, targeting WebdriverIO v8+. It works by injecting a script into the browser after page load to intercept requests initiated by user actions within test code. Key differentiators: supports both XMLHttpRequest and fetch APIs, allows asserting request method, URL (string or regex), status code, and response details. Cannot intercept requests made on initial page load.

npm install wdio-intercept-service
INSTALL
IMPORT
SIG · WDIO-INTERCEPT-SER
W
wdio-intercept-service
testingjavascriptv4.4.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (function)
import WebdriverAjax from 'wdio-intercept-service'
const WebdriverAjax = require('wdio-intercept-service').default
ESM default export. Do not use .default with require() – you will get an object with a default property instead of the function.
setupInterceptor
browser.setupInterceptor()
browser.setupinterceptor()
Case-sensitive command added to browser object after service is initialized. Must be called before making requests you want to intercept.
expectRequest
browser.expectRequest('GET', '/api/foo', 200)
browser.expectRequest('GET', '/api/foo')
Third argument (statusCode) is required. Can use string or RegExp for URL.
assertRequests
browser.assertRequests()
browser.assertRequests({ timeout: 2000 })
assertRequests does not accept options. Use separate pause() or wait strategies before calling it.

Demonstrates setting up the service manually with WebdriverIO standalone, intercepting an XHR/fetch request, and asserting it.

import { remote } from 'webdriverio'; import WebdriverAjax from 'wdio-intercept-service'; async function run() { const browser = await remote({ logLevel: 'warn', capabilities: { browserName: 'chrome' } }); const serviceLauncher = WebdriverAjax(); serviceLauncher.before(null, null, browser); serviceLauncher.beforeTest(); await browser.url('https://example.com'); await browser.setupInterceptor(); await browser.expectRequest('GET', '/api/data', 200); await browser.click('#load-data'); await browser.pause(1000); await browser.assertRequests(); const request = await browser.getRequest(0); console.log('Request method:', request.method); await browser.deleteSession(); } run().catch(console.error);
Debug
Known issues
gotchaRequests initiated on page load cannot be intercepted. Only requests triggered within test code after calling setupInterceptor() are captured.
fix
Ensure that setupInterceptor() is called before the user action that triggers the desired HTTP request.
affects: >=1.0
breakingVersion 4.x requires WebdriverIO v8. Compatibility with WDIO v5-v7 is dropped.
fix
Upgrade to WebdriverIO v8 or use wdio-intercept-service v3.x (if available) for older versions.
affects: >=4.0.0
gotchaWhen using fetch, requests with 'no-cors' mode may not be intercepted due to browser limitations.
fix
Use CORS-enabled endpoints or switch to XMLHttpRequest if interception is required.
affects: >=1.0
gotchaThe getRequest(index) method returns undefined if the index is out of range. No error is thrown.
fix
Check the return value or use getRequests() to iterate.
affects: >=4.0.0
deprecatedassertRequests() does not accept options for timeout or retries. Use manual pauses or WebdriverIO waits instead.
fix
Use browser.pause() or browser.waitUntil() before calling assertRequests() to ensure requests have completed.
affects: >=4.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'before')
Calling serviceLauncher.before before the service is initialized or with incorrect arguments.
fix
Ensure the service is initialized with `const serviceLauncher = WebdriverAjax();` and then call `serviceLauncher.before(null, null, browser);` passing the browser instance.
Error: expectRequest requires a method, url, and statusCode.
Calling expectRequest with missing or invalid arguments (e.g., no statusCode).
fix
Use `browser.expectRequest('GET', '/api/foo', 200);` – all three arguments are required.
AssertionError: expected 0 to equal 1
Request was not intercepted because setupInterceptor() was not called or the request was made before it was called.
fix
Ensure browser.setupInterceptor() is called before the action that triggers the request.
SyntaxError: Unexpected token 'export'
Using ES module import syntax in a CommonJS environment (e.g., Node.js without 'type': 'module' or .mjs extension).
fix
Use `const WebdriverAjax = require('wdio-intercept-service');` or configure your project for ESM.
Upgrade
Version history
4.4.1latest on npm
Audit
Dependencies
webdriveriorequiredPeer dependency; must be installed in the project with a compatible version (v5+ for current plugin, v8+ recommended).
Agent activity
16 hits · last 30 days
node
12
Resources
wdio-intercept-service — npm install wdio-intercept-service · libregistry