Configure WebDriverIO with BrowserMobProxy

Viewed 1570
3 Answers

If you just want to capture the network traffic, then there is one more way to do it.

Webdriverio allows you to use Chrome Dev Tools Protocol.

Please read webdriverio blog

This is one of the examples on how to use chrome dev tools along with webdriverio, do let me know in case you need more help.

const { remote } = require('webdriverio')

    let browser;

    (async () => {
        browser = await remote({
            automationProtocol: 'devtools',
            capabilities: {
                browserName: 'chrome'
            }
        })

        await browser.url('https://webdriver.io')

        await browser.call(async () => {
            const puppeteerBrowser = browser.getPuppeteer()
            const page = (await puppeteerBrowser.pages())[0]
            await page.setRequestInterception(true)
            page.on('request', interceptedRequest => {
                if (interceptedRequest.url().endsWith('webdriverio.png')) {
                    return interceptedRequest.continue({
                        url: 'https://user-images.githubusercontent.com/10379601/29446482-04f7036a-841f-11e7-9872-91d1fc2ea683.png'
                    })
                }

                interceptedRequest.continue()
            })
        })

        // continue with WebDriver commands
        await browser.refresh()
        await browser.pause(2000)

        await browser.deleteSession()
    })().catch(async (e) => {
        console.error(e)
        await browser.deleteSession()
    })
Related