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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: option to remove a locator handler #30471

Closed
DetachHead opened this issue Apr 23, 2024 · 1 comment 路 Fixed by #30494
Closed

[Feature]: option to remove a locator handler #30471

DetachHead opened this issue Apr 23, 2024 · 1 comment 路 Fixed by #30494
Assignees
Labels

Comments

@DetachHead
Copy link
Contributor

馃殌 Feature Request

it would be nice if handlers added by addLocatorHandler could be removed

Example

remove a handler at a certain point in the test:

const handler = await page.addLocatorHandler(page.getByText('Sign up to the newsletter'), async () => {
  await page.getByRole('button', { name: 'No thanks' }).click();
});

await page.goto('https://example.com');
await page.getByRole('button', { name: 'Start here' }).click();

// at this point we can be confident that the popup has either already appeared, or won't appear at all,
// so it's safe to remove the handler.
handler.remove() 

remove a handler after it's called once:

await page.addLocatorHandler(page.getByText('Sign up to the newsletter'), async (handler) => {
  await page.getByRole('button', { name: 'No thanks' }).click();
  handler.remove()
});

### Motivation

- in some cases, a locator handler is only needed once
- at a certain point in the test, you can often be confident that a handler is no longer needed
@dgozman dgozman added the v1.44 label Apr 23, 2024
@dgozman dgozman self-assigned this Apr 23, 2024
@dgozman
Copy link
Contributor

dgozman commented Apr 23, 2024

Two options we think of:

  • { once: true } for a single-use;
  • page.removeLocatorHandler(locator, handler) with the same arguments to remove it.

dgozman added a commit that referenced this issue Apr 24, 2024
- Automatically waiting for the overlay locator to be hidden, with
`allowStayingVisible` opt-out.
- `times: 1` option.
- `removeLocatorHandler(locator, handler)` method.
- Passing `locator` as first argument to `handler`.

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

Successfully merging a pull request may close this issue.

2 participants