webdriverio/webdriverio

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

Open

#12.717 geöffnet am 18. Apr. 2024

Auf GitHub ansehen
 (7 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)JavaScript (6.029 Stars) (1.793 Forks)batch import
Bug 🐛help wanted

Beschreibung

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

Contributor Guide