webdriverio icon indicating copy to clipboard operation
webdriverio copied to clipboard

[🐛 Bug]: cannot read property 'selenoid:options' of undefined - during watch mode

Open Badisi opened this issue 3 years ago • 6 comments

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

latest

Node.js Version

14.17.5

Mode

Standalone Mode

Which capabilities are you using?

{
    browserName: 'chrome',
    acceptInsecureCerts: true
}

What happened?

Using the mock api during watch mode will work fine during the first run but will trigger the following error the second time :

[chrome (unknown) #0-0] Cannot read property 'selenoid:options' of undefined
[chrome (unknown) #0-0] TypeError: Cannot read property 'selenoid:options' of undefined
[chrome (unknown) #0-0]     at Browser.getPuppeteer (/Users/test/app-test/node_modules/webdriverio/build/commands/browser/getPuppeteer.js:71:52)
[chrome (unknown) #0-0]     at Browser.wrapCommandFn (/Users/test/app-test/node_modules/@wdio/utils/build/shim.js:131:38)
[chrome (unknown) #0-0]     at async Browser.mock (/Users/test/app-test/node_modules/webdriverio/build/commands/browser/mock.js:119:9)
[chrome (unknown) #0-0]     at async Browser.wrapCommandFn (/Users/test/app-test/node_modules/@wdio/utils/build/shim.js:131:29)

This seems related to https://github.com/webdriverio/webdriverio/issues/7086

What is your expected behavior?

No response

How to reproduce the bug.

Simply use a basic mock example (as from the doc):

it('should modify http responses', async () => {
    const mock = await browser.mock('http://localhost:4200')
    mock.respond('test');
});

Then:

  1. Start your test in watch mode
wdio run wdio.config.ts --watch
  1. Wait for the test to run
=> result: passing !
  1. Save your test file to trigger a new test run
=> result: cannot read property 'selenoid:options' of undefined

Relevant log output

[chrome (unknown) #0-0] Cannot read property 'selenoid:options' of undefined
[chrome (unknown) #0-0] TypeError: Cannot read property 'selenoid:options' of undefined
[chrome (unknown) #0-0]     at Browser.getPuppeteer (/Users/test/app-test/node_modules/webdriverio/build/commands/browser/getPuppeteer.js:71:52)
[chrome (unknown) #0-0]     at Browser.wrapCommandFn (/Users/test/app-test/node_modules/@wdio/utils/build/shim.js:131:38)
[chrome (unknown) #0-0]     at async Browser.mock (/Users/test/app-test/node_modules/webdriverio/build/commands/browser/mock.js:119:9)
[chrome (unknown) #0-0]     at async Browser.wrapCommandFn (/Users/test/app-test/node_modules/@wdio/utils/build/shim.js:131:29)

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

Is there an existing issue for this?

  • [X] I have searched the existing issues

Badisi avatar Dec 03 '21 22:12 Badisi

Thanks for reporting!

It seems that we don't correctly pass in the arguments when we rerun a session. My first guess is in watcher.ts but not entirely sure.

Any contributions that resolves the bug are highly appreciated. Please take a look into our contribution guidelines and let us know if you have any questions. Cheers!

christian-bromann avatar Dec 06 '21 09:12 christian-bromann

I think so, because when the method getPuppeteer.ts#L45 is called:

The first time

Both capabilities and requestedCapabilities are properly set.

Screen Shot 2021-12-06 at 12 34 06

The second time

Most of the previous info are lost.

Screen Shot 2021-12-06 at 12 35 26

I would be glad to help, as always, but unfortunately after further investigation I think it requires more knowledge of the library than I have..

Badisi avatar Dec 06 '21 11:12 Badisi

Could this be related to #7086 ?

I can still repro this right now with Chrome 100.

ari-meetai avatar Apr 06 '22 22:04 ari-meetai

@ari-meetai any contribution that helps fixing the issue is welcome!

christian-bromann avatar Apr 07 '22 07:04 christian-bromann

@ari-meetai, yes I think so (that's what I said in the What happened? section)

Badisi avatar Apr 07 '22 09:04 Badisi

@ari-meetai, are you still facing this issue ?

Because I don't know what fixed it, but I got it working with the following configuration:

  "@wdio/cli": "^7.19.5",
  "@wdio/jasmine-framework": "^7.19.5",
  "@wdio/local-runner": "^7.19.5",
  "@wdio/spec-reporter": "^7.19.5",
  "chromedriver": "^100.0.0",

Badisi avatar Apr 13 '22 23:04 Badisi

I will close this due to inactivity. We've done various further improvements to the watch mode so if this bug still seems to be valid I am happy to re-open.

christian-bromann avatar Mar 30 '23 04:03 christian-bromann

I'm experiencing the same issue when trying to mock API calls in component tests.

TypeError: Cannot read properties of undefined (reading 'selenoid:options')
    at Browser.getPuppeteer (http://localhost:52696/node_modules/@wdio/browser-runner/node_modules/webdriverio/build/commands/browser/getPuppeteer.js?v=7bf5bdff:67:52)
    at Browser.wrapCommandFn (http://localhost:52696/node_modules/@wdio/utils/build/shim.js?v=7bf5bdff:88:38)
    at Browser.<anonymous> (http://localhost:52696/node_modules/@wdio/utils/build/shim.js?v=7bf5bdff:240:24)
    at Browser.mock (http://localhost:52696/node_modules/@wdio/browser-runner/node_modules/webdriverio/build/commands/browser/mock.js?v=7bf5bdff:115:20)
    at Browser.wrapCommandFn (http://localhost:52696/node_modules/@wdio/utils/build/shim.js?v=7bf5bdff:88:38)
    at Browser.mock (http://localhost:52696/node_modules/@wdio/utils/build/shim.js?v=7bf5bdff:240:24)
    at Context.<anonymous> (http://localhost:52696/Users/[redacted]:96:45)

The line of code that is breaking is when I call browser.mock

const apiPOSTMock = await browser.mock("**/api", {
  method: "post",
});

I tried to set selenoid:options in the capabilities object in wdio.conf.ts, but that doesn't work

capabilities: [
    {
      // capabilities for local browser web tests
      browserName: "chrome", // or "firefox", "microsoftedge", "safari"
      "selenoid:options": {
        enableVNC: true,
        enableVideo: true,
      },
      "moon:options":{}
    },
  ],

I've attached my wdio config file and package json below for additional context. Any advice would be appreciated. configs.zip

kenchen-asurion avatar Jan 18 '24 22:01 kenchen-asurion

@kenchen-asurion can you raise a new issue titled: "Support mock command for browser-runner"? This capability is not yet enabled when running tests within the browser. We definitely want to make this experience seamless now that the command will allow mocking cross browser at some day.

In the meantime I recommend to mock the complete fetch command from the global window scope.

christian-bromann avatar Jan 18 '24 22:01 christian-bromann

Thanks for the quick response. I have opened a new issue for this.

kenchen-asurion avatar Jan 19 '24 16:01 kenchen-asurion