Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Conversation

jrolfs
Copy link
Member

@jrolfs jrolfs commented Sep 1, 2022

  • Add support for find* queries in locator fixture
    • Rename SupportedQuerySynchronousQuery
    • Include find* queries in Queries type as (/* ... */) => Promise<Locator>
    • Implement find queries per discussion starting here
      • Use locator.first().waitFor()
      • Throw proper error on timeout via get* query
      • Wire up waitFor's to asyncUtilTimeout
      • Incorporate waitFor's state option into our options and wire it up?
      • Convert within to a fixture in order to pass asyncUtilTimeout properly — @sebinsua is this gonna be annoying/confusing?

Refactors Merged in #489

  • Isolate 'standard' page (no timeout) in describe blocks
  • Use queries from Testing Library to enumerate queries (instead of internal hard-coded query name array, with the intention of removing all of the legacy ElementHandle implementation in a future major release)

expect(text).toEqual(['Hello h1', 'Hello h2'])
})

test('throws Testing Library error when locator times out', async ({queries}) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Is there any reason why we called this queries and not screen?
  2. @gajus seemed to expose the methods on Page itself. Would this be possible? Are we against doing this for some reason?

Copy link
Member Author

@jrolfs jrolfs Sep 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both things I have considered... I wasn't sure how much benefit we'd get from attaching stuff to page. From your experience, would this be convenient? We could attach within as well.

That said, I do like how switching to screen would resemble TL. Playwright's Page is like a real "screen," though.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I quite like screen for familiarity with Testing Library. And, to be honest, I would prefer to not add any methods to Page as I think this would be unclear (e.g. "why do these methods exist when they're not on the Playwright website?!").

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We adopted the pattern I showed quite without regrets, for what it is worth.

I find that reducing verbosity in tests is extremely important to reduce test fatigue. These things add up

Copy link
Collaborator

@sebinsua sebinsua Sep 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another idea -- could we leave page untouched but make screen itself be Queries & Page, so it is clear that you are using Testing Library but you do not need to juggle both?

That makes it independent but also reduces verbosity in tests.

Are there issues with doing this? What happens if there is a method that returns a Page? Is there anything we can do to avoid people needing to pass the Locators we produce into within(...) in order to make the Testing Library queries available again?

In practice, being able to chain .locator(...) as you can do in Playwright is quite helpful. My code got more explicit but worse when I used within(...). 😅

(Thinking aloud to see if other's have opinions.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooo, I quite like that idea re: screen + page. I think I'll probably go that route.

As for your question, we could use a similar approach to augment the Locator returned from queries with the query methods (so you could chain), but my concern there is departing from the Testing Library API.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm think gonna address this stuff in a separate PR.


expect(text).toEqual(['Hello h1', 'Hello h2'])
})

Copy link
Collaborator

@sebinsua sebinsua Sep 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to support Locator#waitFor.state we should add an extra <div> element with a style of visibility: hidden into fixtures/late-page.html which is not added by a setTimeout and is already attached to <body>. That way we could write a test of this passing in state: 'hidden' and state: 'attached' to check the behaviour.

Copy link
Member Author

@jrolfs jrolfs Sep 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make any sense to support hidden and detached just because waitFor supports them? playwright.dev/docs/api/class-locator#locator-wait-for
Right now I'm snagging the type from Playwright, but I'm thinking visible and attached really only make sense https://github.com/testing-library/playwright-testing-library/pull/488/files#diff-04543a94352d1484d0a0add940de7e7b20b0e8d7d58ca1e3aa8d705ba7de95cdR55-R58

Related: waitForElementToBeRemoved

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and removed hidden and detached from the types for now. Unfortunately our follow-up getBy query for the Testing Library error kinda breaks down when the element is attached but not visible because the getBy query doesn't throw an error in that case 😑.

@sebinsua
Copy link
Collaborator

sebinsua commented Sep 1, 2022

This all looks good to me. I wrote some comments with my understanding of things! (I also wrote further comments within the GitHub issue.)

@jrolfs jrolfs force-pushed the feature/locator-find-queries branch 3 times, most recently from ce9630e to c6a148c Compare September 2, 2022 08:04
@jrolfs jrolfs marked this pull request as ready for review September 2, 2022 08:07
@jrolfs jrolfs force-pushed the feature/locator-find-queries branch 2 times, most recently from cb567cb to 739e085 Compare September 2, 2022 08:09
)}`,
)
.first()
.waitFor({state, timeout: 100})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bleh, this hard-coded timeout is to handle the hidden element case I mentioned where getBy* doesn't throw 😑.

@jrolfs jrolfs requested a review from sebinsua September 2, 2022 08:15
@jrolfs
Copy link
Member Author

jrolfs commented Sep 2, 2022

I think this may be in a reasonable spot to release as another beta, assuming I can sort whatever's going on with Semantic Release. Worst case we switch to next 🙃 (or maybe alpha, heh)

@sebinsua
Copy link
Collaborator

sebinsua commented Sep 2, 2022

Can you expose queriesFor when you publish a new version?

(until we have an official API for \`Locator\` queries that doesn't require
a **@playwright/test** fixture)
@jrolfs jrolfs force-pushed the feature/locator-find-queries branch from 739e085 to a9cb165 Compare September 3, 2022 01:16
@jrolfs jrolfs merged commit f01deb4 into beta Sep 3, 2022
@jrolfs jrolfs deleted the feature/locator-find-queries branch September 3, 2022 01:37
@github-actions
Copy link

github-actions bot commented Sep 3, 2022

🎉 This PR is included in version 4.4.0-alpha.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants