-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
cy.focused() inconsistent behavior #752
Comments
I'm curious if chai-jQuery's newer |
Code for |
We don't use |
Can you think of any workarounds? |
@brian-mann meaning these docs are out of date, and you implement the chai-jquery natively (via the string args in I also second the OP -- currently IMO Meanwhile, it can be done like this:
|
We technically do not use Here's the code: The problem with focus in general is that it behaves differently whether or not the:
Because of this we normalized the focus behavior (or at least attempted to) with What we do is basically a polyfill for when the browser doesn't do the "right thing" just because its out of focus. I believe there was a specific technical reason we chose not to implement The problem is that because we are normalizing focus it means Cypress is the only source of truth to understand what should be in focus even when its not. Because of that - the We could override jquery's |
I ran into this issue when testing moving between text boxes in a form. |
@verheyenkoen Did you find any workaround for this? I'm also running into this using cypress@v1.4.1. Tests with Sample test case: cy
.get('input[name="digit-1"]')
.type('1')
.should('have.value', '1')
.focused()
.should('have.attr', 'name', 'digit-2')
.focused()
.type('2')
.should('have.value', '2')
.focused()
.type('3')
.should('have.value', '3')
// ... |
I think I now tested for the existence of the autofocus attribute, which is not a consistent workaround obviously. |
Running into this issue as well. I'm testing a listbox component. Tests are passing when I run Cypress through the GUI, but fails in headless mode. Cypress test: it('when listbox does not have option selected and receives focus, focus is delegated to the first option', function() {
cy.get('#listbox--static .listbox__options').focus();
cy.focused().then($el => {
expect($el[0].className).to.equal('listbox__option');
expect($el[0].innerText).to.contain('Option 1');
})
}); The feature is working and test is passing in GUI mode. But fails in headless Electron mode. |
This issue was probably fixed in |
I'm closing this for now, but leave a comment if something still seems broken |
I cannot confirm this fix. I upgraded my test repo to Cypress 3.0.2 and my test still fails. Please reopen. |
@verheyenkoen I looked at your test repo. Can you explain what behavior you expect? Looking at the event handler you added: document.getElementById('field').onkeyup = function() {
window.setTimeout(function() {
document.getElementById('field').blur();
}, 100)
}
I don't see why the element would be focused after typing into '#field' |
Damn, what was I thinking?? Nevermind all that. Sorry for bothering... |
Hey, while this works in headless mode, |
@henrykuzmick what version of cypress are you on? cy.focused() should yield the same as document.activeElement or null if the body is focused, which will be unaffected by window focus |
Is this a Feature or Bug?
Bug
Current behavior:
cy.focused()
does the right thing when you keep the Cypress UI window focused. It does the wrong thing if you blur the Cypress UI window or if you run headlessly.Desired behavior:
cy.focused()
should produce consistent results, regardless of being run headed/headless or focused/blurred.How to reproduce:
https://github.com/verheyenkoen/cypress-focused-issue
The text was updated successfully, but these errors were encountered: