Hi, I need a test for checking focus too and I think this could be a nice workaround?
Instead of checking if the element you select is focussed, you get the focussed element and check if the properties/attributes or whatever are conform expectations. In my case, I needed a focus on the field with a name
cy.focused().should('have.attr', 'name', fieldName);
Hi, after this PR #3219 , you will be able to do the following assertions:
cy.get('div').should('have.focus')
cy.get('div').should('not.have.focus')
cy.get('div').should('be.focused')
cy.get('div').should('not.be.focused')
expect(div).to.have.focus
expect(div).to.not.have.focus
expect(div).to.be.focused
expect(div).to.not.be.focused
The code for this is done in https://github.com/cypress-io/cypress/pull/3219, but this has yet to be released. We'll update this issue and reference the changelog when it's released.
Released in 3.3.0
.
I'm getting "CypressError: The chainer: 'focus' was not found. Could not build assertion." with Cypress 3.3.0 when I do cy.get('search_input').should('have.focus')
. Am I using it wrong or should I create a new issue?
I'm getting "CypressError: The chainer: 'focus' was not found. Could not build assertion." with Cypress 3.3.0 when I do
cy.get('search_input').should('have.focus')
. Am I using it wrong or should I create a new issue?
I second that. Whether I use have.focus
or be.focused
I always get the error. It looks as if it wasn't even present in this version.
I'm getting "CypressError: The chainer: 'focus' was not found. Could not build assertion." with Cypress 3.3.0 when I do
cy.get('search_input').should('have.focus')
. Am I using it wrong or should I create a new issue?
Currently looking into this
Edit: looks like it never made it into the develop branch https://github.com/cypress-io/cypress/compare/v3.3.0
We'll have this fixed soon
The code for this is done in cypress-io/cypress#4274, but has yet to be released.
We'll update this issue and reference the changelog when it's released.
Released in 3.3.1
.
Most helpful comment
Hi, after this PR #3219 , you will be able to do the following assertions: