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

document.hasFocus() returns false even if top is focused #1940

Closed
brian-mann opened this issue Jun 13, 2018 · 1 comment · Fixed by #1962
Closed

document.hasFocus() returns false even if top is focused #1940

brian-mann opened this issue Jun 13, 2018 · 1 comment · Fixed by #1962
Assignees
Labels
type: unexpected behavior User expected result, but got another
Milestone

Comments

@brian-mann
Copy link
Member

This code fails even when top (Cypress) is in focus.

cy.document().invoke('hasFocus').should('be.true')

We need to monkey patch document.hasFocus() so that it always returns the value of top.document.hasFocus() since a parent frame will always have the same focus as a child frame, which replicates a focused document outside of Cypress.

@brian-mann brian-mann added the type: unexpected behavior User expected result, but got another label Jun 13, 2018
@brian-mann brian-mann added this to the 3.0.2 milestone Jun 13, 2018
@brian-mann brian-mann self-assigned this Jun 13, 2018
brian-mann added a commit that referenced this issue Jun 16, 2018
this prevents situations where there are differences between running
within Cypress vs out of Cypress. normally the AUT is top and hasFocus
will return true, but in Cypress the AUT iframe has to literally be in
direct focus else it will return false.

hasFocus effectively “bubbles” when in iframes so children iframes in
focus cause their parents to receive the same value
brian-mann added a commit that referenced this issue Jun 18, 2018
@brian-mann
Copy link
Member Author

Released in 3.0.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: unexpected behavior User expected result, but got another
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants