WebdriverIO
WebdriverIO has no cross-browser pre-navigation hook, so call injectChaos() after browser.url(). Initial-load requests are not intercepted in this adapter.
npm install @chaos-maker/core @chaos-maker/webdriverioThe fastest start is a named preset - drop a scenario into the config and run:
import { browser, expect, $ } from '@wdio/globals';import { injectChaos } from '@chaos-maker/webdriverio';
describe('checkout', () => { it('works under degraded mobile network', async () => { await browser.url('/checkout'); await injectChaos(browser, { presets: ['mobile-3g', 'checkout-degraded'], seed: 42 }); await $('[data-testid="checkout-form"]').waitForDisplayed(); });});See the Presets catalog for the full list. When several tests should share the same named scenario, wrap it into a scenario profile - the one built-in demo profile composes both presets above into a single name:
await injectChaos(browser, { profile: 'mobile-checkout', seed: 42 });Pass profileOverrides alongside profile to tune one parameter for this call without forking the profile. When you need precise control, drop down to explicit rules:
import { browser, expect, $ } from '@wdio/globals';import { injectChaos, getChaosLog } from '@chaos-maker/webdriverio';
describe('orders', () => { it('shows error state when the API fails', async () => { await browser.url('/orders'); await injectChaos(browser, { seed: 42, network: { failures: [{ urlPattern: '/api/orders', statusCode: 503, probability: 1 }], }, });
await $('#reload-orders').click(); await expect($('[data-testid="error-state"]')).toBeDisplayed();
const log = await getChaosLog(browser); expect(log.some((event) => event.type === 'network:failure' && event.applied)).toBe(true); });});Log the replay seed only when a test fails. WDIO’s afterTest runner hook (in wdio.conf.ts) is the reliable place: passed is supplied directly, with no Mocha-internal state to inspect.
import { formatSeedReproduction, getChaosSeed } from '@chaos-maker/webdriverio';
export const config = { // … async afterTest(_test, _context, { passed }) { if (passed) return; console.error(formatSeedReproduction(await getChaosSeed(browser))); },};Custom commands
Section titled “Custom commands”Call registerChaosCommands(browser) in a WDIO setup hook if you prefer browser.injectChaos(config), browser.getChaosLog(), and related commands.