Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

using click() in Cypress

I am testing my app using Cypress, in my app there is a one minute timer. When the timer expires, no button should work. To put it more precisely, even though the user clicks on buttons, nothing should happen (functions connected to those buttons should not be triggered). How can I test such a thing?

cy.get('#timer-btn').click().wait(60000)
cy.get('#timer').should('have.text', 'TIME IS UP, your score is: 0')
cy.get('.btn').click() 
//???

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  1. Instead of using wait use timeout because wait waits for a total of 60 seconds, but with a timeout, it is terminated whenever the expected condition is met.
cy.get('#timer-btn').click()
cy.get('#timer', {timeout: 60000}).should(
  'have.text',
  'TIME IS UP, your score is: 0'
)
cy.get('.btn').click()
  1. Now if the button is disabled after 60 seconds you can use:
cy.get('#timer-btn').click()
cy.get('#timer', {timeout: 60000}).should(
  'have.text',
  'TIME IS UP, your score is: 0'
)
cy.get('.btn').should('be.disabled')
  1. Now, if you see on comparing the HTML of the button during and after the timer, if any attribute-value pair is added to the button after the timer is completed, you can assert that using:
cy.get('#timer-btn').click()
cy.get('#timer', {timeout: 60000}).should(
  'have.text',
  'TIME IS UP, your score is: 0'
)
cy.get('.btn').should('have.attr', 'attr-name', 'attr-value')
  1. If you see just an attribute is added you can just use
cy.get('.btn').should('have.attr', 'attr-name')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading