webdriverio/webdriverio

[🐛 Bug]: custom element commands doesn't work with browser runner

Open

#12.717 aperta il 18 apr 2024

Vedi su GitHub
 (7 commenti) (0 reazioni) (0 assegnatari)JavaScript (1793 fork)batch import
Bug 🐛help wanted

Metriche repository

Star
 (6029 star)
Metriche merge PR
 (Merge medio 9g 6h) (33 PR mergiate in 30 g)

Descrizione

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

latest

Node.js Version

18.12.1

Mode

Standalone Mode

Which capabilities are you using?

{
  browserName: 'chrome'
}


### What happened?

Custom commands added to the element don't work with the `browser` runner, but correctly works with `local` runner.

### What is your expected behavior?

I expect that my element custom command should works correctly in `browser` runner.

### How to reproduce the bug.

```js
// wdio.conf.js
export const config = {
    runner: "browser",
    specs: [
        './src/**/*.test.js'
    ],
    capabilities: [{
        browserName: 'chrome',
    }],
    mochaOpts: {
        ui: 'bdd',
    },
    before: function (capabilities, specs, browser) {
        browser.addCommand("elemCmd", () => {
            console.log('inside my element command');
        }, true);
    },
}

// src/bro.test.js
it('test', async () => {
    await $("body").elemCmd();
})
./node_modules/.bin/wdio run ./wdio.conf.js

Relevant log output

[0-0] Error in "test"
Error: Can't call "elemCmd" on element with selector "body", it is not a function


### 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

Guida contributor