I’ve built an automation suite which checks various page elements/interacts with the page and logs some performance metrics using WebdriverIO with devTools enabled. As a final step, I’d like to add some new functionality which essentially opens devTools -> console on the page I’m browsing and then types a command in the console, e.g. window.alert and then checks that the console returns an object/similar. I’m stuck trying to open devTools – > console, some research suggests that browser.cdp(<domain>, <command>, <arguments>) is the way to go, but I don’t know what format the function takes for any arguments, this is the snippet I’ve tried:
var otherData = await browser.cdp('mydomaingoeshere', window.alert);
console.log('Other data = ', otherData);
but that returns Other data = undefined. If I type that manually in the console, window.alert never returns undefined.
As an alternative, I’ve also looked at browser.execute, and I’ve tried this:
async function getSomeData() {
await browser.execute(function () {return window.alert;});}`
but when I try to call that in my describe block, e.g. var otherData = await getSomeData(); console.log(otherData); it doesn’t seem to return/log anything.
Can someone please point me in the right direction?
Many thanks
Please see above – tried to open devTools -> console then type a command using automation, but either got nothing or undefined, expecting an object or some text at least to show.
George is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.