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

el?.isDisplayed is not a function #1507

Open
nextlevelbeard opened this issue Mar 21, 2024 · 9 comments
Open

el?.isDisplayed is not a function #1507

nextlevelbeard opened this issue Mar 21, 2024 · 9 comments

Comments

@nextlevelbeard
Copy link
Member

Versions: latest webdriverio + latest expect-webdriverio, TS 5.4.3

Trigger await expect(await $$('.item')).toBeDisplayed();

Logs:

TypeError: el?.isDisplayed is not a function
    at file:///Users/user/repos/repo/e2e/node_modules/@wdio/runner/node_modules/expect-webdriverio/lib/matchers/element/toBeDisplayed.js:9:74
    at file:///Users/user/repos/repo/e2e/node_modules/@wdio/runner/node_modules/expect-webdriverio/lib/utils.js:55:96
    at Object.executeCommand (file:///Users/user/repos/repo/e2e/node_modules/@wdio/runner/node_modules/expect-webdriverio/lib/util/executeCommand.js:2:26)
    at file:///Users/user/repos/repo/e2e/node_modules/@wdio/runner/node_modules/expect-webdriverio/lib/utils.js:55:45
    at waitUntil (file:///Users/user/repos/repo/e2e/node_modules/@wdio/runner/node_modules/expect-webdriverio/lib/utils.js:26:49)
    at async Object.executeCommandBe (file:///Users/user/repos/repo/e2e/node_modules/@wdio/runner/node_modules/expect-webdriverio/lib/utils.js:54:18)
    at async Object.toBeDisplayed (file:///Users/user/repos/repo/e2e/node_modules/@wdio/runner/node_modules/expect-webdriverio/lib/matchers/element/toBeDisplayed.js:9:20)
    at async Scenario.<anonymous> (file:///Users/user/repos/repo/e2e/steps/my.steps.ts:XX:X)
@christian-bromann
Copy link
Member

@nextlevelbeard do you have a reproducible example for it?

@sangcnguyen
Copy link
Contributor

sangcnguyen commented Jun 14, 2024

Below is my reproducible code example @christian-bromann

await browser.url("https://webdriver.io/");
await expect(await $$(`//a[@class="navbar__item navbar__link"]`)).toBeDisplayed()

It seems the current code accepts $(), not $$(). Should we add support for handling an array of elements?

@christian-bromann
Copy link
Member

Should we add support for handling an array of elements?

What would you think the behavior should be? Should it fail if one of the found elements are not visible?

Generally we only have one matcher that allows passing in WebdriverIO.ElementArrays. I am not sure what if there is an interest in adding more as you usually only assert one element at a time. However I am open for ideas here.

@sangcnguyen
Copy link
Contributor

What would you think the behavior should be?

I used to write with Selenium, Playwright. I'm hesitant because they don't have behavior like this to check if an array is displayed.

Should it fail if one of the found elements are not visible?

I think it makes sense to mark the test as a failure if one of the elements is not visible.

Generally we only have one matcher that allows passing in WebdriverIO.ElementArrays. I am not sure what if there is an interest in adding more as you usually only assert one element at a time. However I am open for ideas here.

I think for now we should improve the error messages when the function does not support taking an array element and include the documentation directly into the types file. That could help users (including myself) better understand how to use the matchers.

@christian-bromann
Copy link
Member

I think for now we should improve the error messages when the function does not support taking an array element

Maybe we can do this for all matchers that expect that? Like having a validateInput method that throws if the input is not an WebdriverIO.Element or a Promise of that. Also agree with your further suggestions.

@htho
Copy link

htho commented Dec 2, 2024

I'd like to mention that the types file suggests, that these matchers should work with WebdriverIO.ElementArrays (the result of $$) as well:

    interface Matchers<R, T> {
        // ===== $ or $$ ===== // << HERE IT IS
        /**
         * `WebdriverIO.Element` -> `isDisplayed`
         */
        // ...
        }

@christian-bromann
Copy link
Member

@htho this is due to the fact that we don't have a better type for these matchers as we currently support matchers for single elements ($) and element arrays ($$). This could be improved. However most matchers are suppose to only work with single elements.

@htho
Copy link

htho commented Dec 2, 2024

Ah. I did not make it clear. It's not about the type definition itself. I meant the normal comment on the first line of the interface.

L491 says the following section is $$ only: // ===== $$ only =====

But L156 claims it is about $ and $$: // ===== $ or $$ =====

Yes - those are not type comments, but I like to look at the d.ts files to better understand the API. And this comment lets me believe that the following matchers are for both.

@christian-bromann
Copy link
Member

But L156 claims it is about $ and $$: // ===== $ or $$ =====

This doesn't seem correct to me, not sure for what this stands for or if there was a plan to support expect($$('elem')).toBeExisting() that would fail if one of the elements would not exist. I doubt that though so it sounds the comment is just wrong.

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

No branches or pull requests

4 participants