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

Add support for "focus" assertion (to work effectively as Chai jQuery assertion does) #97

Closed
jennifer-shehane opened this issue Feb 5, 2016 · 10 comments

Comments

6 participants
@jennifer-shehane
Copy link
Member

commented Feb 5, 2016

Chai jQuery added a focus assertion recently.

Cypress needs support for focus assertions so I can assert whether a DOM element has or does not have focus.

Example

cy
  .get('input')
    .type('Foo').should('have.focus')
    .blur().should('not.have.focus')
@anniekvandijk

This comment has been minimized.

Copy link

commented Aug 17, 2018

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);

@Bkucera Bkucera referenced this issue Jan 24, 2019

Merged

add "be.focused" and "have.focus" to assertions #3219

6 of 6 tasks complete
@Bkucera

This comment has been minimized.

Copy link
Member

commented Jan 24, 2019

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
@brian-mann

This comment has been minimized.

Copy link
Member

commented May 1, 2019

Fixed by #3219

@jennifer-shehane

This comment has been minimized.

Copy link
Member Author

commented May 1, 2019

The code for this is done in #3219, but this has yet to be released. We'll update this issue and reference the changelog when it's released.

@cypress-bot

This comment has been minimized.

Copy link

commented May 17, 2019

Released in 3.3.0.

@denkristoffer

This comment has been minimized.

Copy link

commented May 21, 2019

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?

@ThisIsJesus

This comment has been minimized.

Copy link

commented May 21, 2019

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.

@Bkucera

This comment has been minimized.

Copy link
Member

commented May 21, 2019

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

@cypress-bot

This comment has been minimized.

Copy link

commented May 21, 2019

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.

@cypress-bot

This comment has been minimized.

Copy link

commented May 23, 2019

Released in 3.3.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.