Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'addCommand' of undefined #504

Closed
DPGZl opened this issue Feb 20, 2023 · 11 comments
Closed

Cannot read property 'addCommand' of undefined #504

DPGZl opened this issue Feb 20, 2023 · 11 comments
Labels

Comments

@DPGZl
Copy link

DPGZl commented Feb 20, 2023

Hi, can anyone help me with this issue?

I wanna get a request header by Intercept Service, but I got this error: ERROR @wdio/utils:shim: TypeError: Cannot read property 'addCommand' of undefined at WebdriverAjax.before, I've tried to find the solution but nothing got.

Here is the related packages version: "wdio-chromedriver-service": "6.0.4", "wdio-intercept-service": "^4.3.1", "webdriverajax": "^2.2.0"

@DPGZl
Copy link
Author

DPGZl commented Feb 20, 2023

btw, I didn't call before and beforeTest / beforeScenario functions manually, could you give a suggestion how to call these functions manually?

@tehhowch
Copy link
Contributor

webdriverajax is an old version of this library, and you should not attempt to use both it and wdio-intercept-service at the same time. You also shouldn't need to invoke before / beforeScenario manually, they should be invoked by the local runner automatically if you have configured the service in wdio.conf.js correctly.

@chmanie can we get webdriverajax archived?

also @DPGZl , what version of WebdriverIO are you using?

@chmanie
Copy link
Member

chmanie commented Feb 24, 2023

Yup, I'll archive it asap.

@DPGZl
Copy link
Author

DPGZl commented Feb 24, 2023

Hi @tehhowch, thanks for your response, according to your suggestion I've removed webdriverajax from my project, and I config as services: ['intercept'], but I still run into the same error.

I'm not using webdriverio directly, instead below are the wdio related packages I'm using:

"@wdio/cli": "6.0.16",
"@wdio/junit-reporter": "^6.3.6",
"@wdio/local-runner": "6.0.16",
"@wdio/mocha-framework": "6.0.16",
"@wdio/selenium-standalone-service": "6.0.16",
"@wdio/spec-reporter": "6.0.16",
"wdio-chromedriver-service": "6.0.4",
"wdio-intercept-service": "^4.3.1",

@tehhowch
Copy link
Contributor

tehhowch commented Feb 24, 2023

Please upgrade from v6 to v7. The signature of the before hook changed, and the 3rd argument is now the browser object. In v6 and earlier, there is no third argument and thus the browser parameter is undefined, and shadows the global browser. This has been broken since 4cb8d0d, apparently.

If you cannot upgrade to the current LTS or higher, please open a PR to this repo that changes the "before" hook in index.js to use either the provided 3rd argument or the global, depending on the presence of the argument.

e.g.

before() {
  const browser = typeof arguments[2] === 'undefined' ? globalThis.browser : arguments[2];
  //...rest is unmodified

@tehhowch
Copy link
Contributor

You don't actually have to upgrade to v7, v6.10 will suffice, as that is when the change was made to start providing browser to the before hook: webdriverio/webdriverio@22ee028

@DPGZl
Copy link
Author

DPGZl commented Feb 24, 2023

@tehhowch , you mean I need to update @wdio/cli to v6.10? (not webdriverio, right? because I'm using @wdio/cli.)

I've tried to update @wdio/cli to v6.10, but the issue still exists.

The issue is resolved when I tried to debug on my local like the example you list above, so I'm wondering if it's ok to open a PR.

@tehhowch
Copy link
Contributor

@tehhowch , you mean I need to update @wdio/cli to v6.10? (not webdriverio, right? because I'm using @wdio/cli.)

I've tried to update @wdio/cli to v6.10, but the issue still exists.

The issue is resolved when I tried to debug on my local like the example you list above, so I'm wondering if it's ok to open a PR.

To update your WDIO packages, you should modify all @wdio/** entries in your package.json to be ^6.10 and then run npm i or yarn, etc.
@wdio/local-runner will be the most important one as that is the part of the framework that is running the tests and invoking the hooks, which is where the issue is occurring.

And yes, feel free to open a PR (with a test!) that restores support for WDIO 5.x, <6.10.

@tehhowch
Copy link
Contributor

@DPGZl were you interested in contributing the fix?

@tehhowch
Copy link
Contributor

tehhowch commented Feb 27, 2024

I've addressed this in 210fdfc

I'll create a new release in the next few days.

@tehhowch
Copy link
Contributor

tehhowch commented Mar 5, 2024

4.4.1 is available in NPM now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants