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

(feature request): Adding .toHaveFocus() to the library #61

Closed
mfrachet opened this issue Feb 25, 2021 · 1 comment · Fixed by #64
Closed

(feature request): Adding .toHaveFocus() to the library #61

mfrachet opened this issue Feb 25, 2021 · 1 comment · Fixed by #64
Labels
enhancement New feature or request

Comments

@mfrachet
Copy link

Hello folks and thank you for the great work you're doing with the tool! That's amazing 😊

I'm opening this issue to request for a .toHaveFocus() function that will allow to verify what is the actually focused element. This may become very helpful when testing for accessibility.

Actually, to determine if an element has focused on it, I have two options that are quite verbose:

  const axTreeSnapshot = await page.accessibility.snapshot({ root });
  // does not look very consistent on firefox from my experimentation, but I may be wrong
  axTreeSnapshot.focused

or as described in microsoft/playwright#2159 (comment) with the following:

const foo1Isfocused = await page.$eval("#foo1", (el) => el === document.activeElement)

What do you think?

@mmarkelov
Copy link
Member

@mfrachet thanks for your suggestion. I think we can move the second option in separate helper.toHaveFocus()
That make sense for me.

@mmarkelov mmarkelov added the enhancement New feature or request label Feb 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants