OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Open Dev Tools and Type Command Automatically in WebdriverIO

  • Thread starter Thread starter George
  • Start date Start date
G

George

Guest
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:

Code:
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:

Code:
async function getSomeData() {

Code:
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.

<p>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:</p>
<pre><code>var otherData = await browser.cdp('mydomaingoeshere', window.alert);
console.log('Other data = ', otherData);
</code></pre>
<p>but that returns Other data = undefined. If I type that manually in the console, window.alert never returns undefined.</p>
<p>As an alternative, I've also looked at browser.execute, and I've tried this:</p>
<pre><code>async function getSomeData() {
</code></pre>
<pre><code>await browser.execute(function () {return window.alert;});}`
</code></pre>
<p>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.</p>
<p>Can someone please point me in the right direction?</p>
<p>Many thanks</p>
<p>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.</p>
 

Latest posts

Top