question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cy.focused() inconsistent behavior

See original GitHub issue
  • Operating System: Mac OS X Sierra
  • Cypress Version: 1.0.2
  • Browser Version: All

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:9
  • Comments:17 (12 by maintainers)

github_iconTop GitHub Comments

3reactions
henrykuzmickcommented, Oct 26, 2018

Hey, while this works in headless mode, focused() still fails when using the ui and not having the cypress window focused. It would be great if it worked even when I’m on another tab or in my IDE, etc.

2reactions
dwellecommented, Oct 25, 2017

We don’t use chai-jquery anymore

@brian-mann meaning these docs are out of date, and you implement the chai-jquery natively (via the string args in .should())?

I also second the OP – currently cy.focused() yields window object (in some(?) cases) ).

IMO cy.focused() should correctly yield focused element.

Meanwhile, it can be done like this:

// get focused element
cy.get(":focus")

// assert if yielded element has focus
cy.get( selector ).should( $elem => {
    expect( $elem.is(":focus") ).to.be.true;
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

focused - Cypress Documentation
cy.focused() yields the DOM element it found. cy.focused() is a query, and it is safe to chain further commands.
Read more >
Cypress does not always executes click on element
click() on it 2 or more times, I ensured it was first set in focus prior to being clicked. This fixed it for...
Read more >
cypress fix this problem, or use {force: true} to disable error ...
Current behavior: CypressError: Timed out retrying: cy.type() failed because this element: <input id="visiblenumber" focus-if="" type="number" maxlength="4" ...
Read more >
Autism Spectrum Disorder - National Institute of Mental Health
Social communication / interaction behaviors may include: Making little or inconsistent eye contact; Appearing not to look at or listen to people who...
Read more >
Contextualizing the Impostor “Syndrome” - Frontiers
This focus on the individual level of analysis is most likely the result of ... This may also help explain inconsistencies in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found