webdriverio/webdriverio

[🐛 Bug]: Cannot add custom `scroll` element command

Open

#12.915 aberto em 20 de mai. de 2024

Ver no GitHub
 (3 comments) (0 reactions) (0 assignees)JavaScript (6.029 stars) (1.793 forks)batch import
Bug 🐛help wanted

Description

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

7.35.0

Node.js Version

18.16.1

Mode

WDIO Testrunner

Which capabilities are you using?

No response

What happened?

I am attempting to add a custom element command named scroll like:

export class MyExtensions implements Services.ServiceInstance {
  async before(_capabilities: Capabilities.RemoteCapability, _specs: string[], browser: any) {
    // ...
    browser.addCommand('scroll', performScroll, true);
  }
}

However running a test which uses this scroll command fails with the error:

elem[prop] is not a function
TypeError: elem[prop] is not a function
  at async Context.<anonymous>

Changing this to any other name seems to avoid the bug.

What is your expected behavior?

The test should pass and the function passed to the scroll command should be invoked.

How to reproduce the bug.

Create and add a service:

export class MyExtensions implements Services.ServiceInstance {
  async before(_capabilities: Capabilities.RemoteCapability, _specs: string[], browser: any) {
    browser.addCommand('scroll', () => 123, true);
  }
}

Then add a test that calls this command on an element:

it('should scroll', async () => {
  const element = await browser.$('~some-id');
  expect(element.scroll).not.toBeUndefined();
  expect(element.scroll()).toBe(123);
});

Relevant log output

elem[prop] is not a function
TypeError: elem[prop] is not a function
  at async Context.<anonymous> path/to/command/invocation.ts

Code of Conduct

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

Is there an existing issue for this?

  • I have searched the existing issues

Guia do colaborador