TypeError: screen.findByTestId(...).click is not a function
InduKrish opened this issue ยท 3 comments
await screen.findByTestId('Edit Group Codes').click();;
TypeError: screen.findByTestId(...).click is not a function
await screen.findByTestId('Edit Group Codes').click();;
Since we now use the locator API, Can you please advise why click() function is still not resolved?
We expect playwright testing library to behave something like how playwright behaves. click() function after locator is found like below.
-----> await page.locator('input#password').click()
Code that worked - Only increases no of lines in the test and assigning to a variable before performing click() action does not let a user to interact like how playwright allows as above, so the code would be less maintainable and not user friendly.
const form = await screen.findByTestId('Edit Group Codes');
await form.click();
Do you have any plan to let findByTestId behave the same way like how playwright official library behaves to perform click action in a single line like this await page.locator('input#password').click() ?
Example: Cypress example using playwright testing library, We expected something like this.
cy.findByTestId('menu-option-dashboard-link').click().wait(1000);
I think you're asking for the same thing I mentioned here (and I think it will be implemented in some shape).
Although, I think we're not going to make findBy* behave exactly the same way as locator as if you await with only this we want it to wait for the element to become visible instead of immediately returning.
Thanks, @sebinsua โ yes, I think I will probably incorporate support for this sort of thing in #501
await screen.findByTestId('Edit Group Codes').click();Until we sort out exactly how we want to support the snippet above, you can still achieve this in a single line like so:
await (await screen.findByTestId('Edit Group Codes')).click();
// or use a `query*` query which synchronously returns a `Locator`,
// but allows Playwright to poll the query with a lazy `click()`
// (note: this will use Playwright's `timeout`, not `asyncUtilTimeout`)
await screen.queryByTestId('Edit Group Codes').click();As I mentioned in #513, I will add some documentation around this asynchronous stuff, and I will update it once we land the improvements in #501.
Example: Cypress example using Playwright testing library, We expected something like this.
cy.findByTestId('menu-option-dashboard-link').click().wait(1000);
I'm not sure it's helpful to reference how the Cypress Testing Library integration works, as Cypress is very different all around. We're trying to make things as idiomatic as possible within Playwright but still adhere as closely to Testing Library's API as it makes sense.
@sebinsua, this is making me question the ergonomics of the find* queries a bit... I still think I like what we have as it should be familiar to anyone that's used to Testing Library. I think we just need to document things a bit better (probably point to the Testing Library documentation here and here). The current readme documentation is a bit of a placeholder until we consolidate on the Locator APIs in 5.0. At that point, I plan on moving more detailed documentation to the official Testing Library site.
๐ This issue has been resolved in version 4.4.1 ๐
The release is available on:
Your semantic-release bot ๐ฆ๐