microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.68k stars 3.65k forks source link

[Docs] Improve documentation for addLocatorHandler #30003

Closed Rafiot closed 7 months ago

Rafiot commented 7 months ago

Page(s)

https://playwright.dev/docs/api/class-page#page-add-locator-handler

Description

So I hope I'll not be hurting your soul too much with that one, but I really need to trigger the locator handler at an arbitrary time without doing anything else (I need to be able to bypass the cookies authorization on arbitrary websites).

My workaround is to run do that:

await page.locator("body").click(button="right")

Which does nothing, but triggers the locator handlers whenever I want them triggered.

The full commit looks like that:

https://github.com/Lookyloo/PlaywrightCapture/commit/26348f7bf5f28f7d6c6a6d48cb41fe77ed99f6f5

Maybe two things:

  1. Add in the documentation that the locator handlers are only checked when there is an action, it wasn't clear to me before I found this bug https://github.com/microsoft/playwright/issues/29701
  2. Add a way to forcefully trigger the locator handlers?
yury-s commented 7 months ago

Add a way to forcefully trigger the locator handlers?

You can extract the handler in a function and call it whenever you want in the tests, would that work for you?

Rafiot commented 7 months ago

I could, but I have a bunch of them (currently 6, most probably many more later) and using the locator handler seemed like a cleaner way to do it (?).

But, now you say that, internally, they are all triggered sequentially, right?

yury-s commented 7 months ago

I could, but I have a bunch of them (currently 6, most probably many more later)

You have flexibility to chose which one you need or you can wrap all of them in a function too.

and using the locator handler seemed like a cleaner way to do it (?).

Locator handlers are only triggered during an action/assertion, I'm updating the docs to make it more clear.

But, now you say that, internally, they are all triggered sequentially, right?

Yes.