webdriverio icon indicating copy to clipboard operation
webdriverio copied to clipboard

[📖 Docs]: Limitations for nth selector using TypeScript does not work

Open a2f0 opened this issue 3 years ago • 5 comments

Pre-check

  • [X] I know I can edit the docs but prefer to file this issue

Describe the improvement

Unclear documentation

Description of the improvement / report

It appears that the documentation for limitations to select the nth element of an array using waitUnitl does not work when using TypeScript, or at least fails TypeScript validation because the success case returns an object of type WebdriverIO.Element where waitUntil only accepts a function that returns boolean | Promise<boolean>. The error with the example verbatim is in the attached screenshot.

Screen Shot 2022-01-17 at 8 49 56 AM

Code of Conduct

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

a2f0 avatar Jan 17 '22 13:01 a2f0

Thanks for reporting!

I believe waitUntil returns the truthy value returned by the callback. The typings and docs should reflect that.

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 Jan 17 '22 21:01 christian-bromann

HI @christian-bromann ,

Looks like the typing's are fine, as waitUntil should return a Boolean value.

waitUntil(this: WebdriverIO.Browser | WebdriverIO.Element, condition: () => boolean|Promise< boolean >, { timeout, interval, timeoutMsg }?: Partial<WaitUntilOptions>): Promise<true | void>;

Looks like code sample in docs should be updated , like below

    await browser.waitUntil(
      async () => {
        const elems = await $$('div');
        return elems.length === 2;
      }, {
        timeoutMsg: 'Never found enough div elements'
      })

Please suggest, will give the PR for this in docs!

harsha509 avatar Feb 24 '22 07:02 harsha509

@harsha509 thanks for investigating. I think the types might be wrong here. I believe waitUntil is implemented so it returns the truthy value, e.g.:

const value = await browser.waitUntil(() => 'foobar');
console.log(value); // outputs: "foobar"

Can you confirm? If so I suggest to not expect a boolean as return value but a generic.

christian-bromann avatar Feb 24 '22 10:02 christian-bromann

@christian-bromann @harsha509 Was any other progress made on this?

nextlevelbeard avatar Apr 15 '22 11:04 nextlevelbeard

@nextlevelbeard I don't think so, would you like to pick it up?

christian-bromann avatar Apr 19 '22 18:04 christian-bromann

fixed by https://github.com/webdriverio/webdriverio/pull/9767

christian-bromann avatar Feb 14 '23 21:02 christian-bromann