Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the element is visible using should().
Cypress
cy.get('button').should([1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'exist' instead of 'be.visible' only checks presence, not visibility.
Using 'contain.text' requires additional arguments.
✗ Incorrect
The 'should' command with 'be.visible' checks if the element is visible on the page.
2fill in blank
mediumComplete the code to assert the button has the class 'active' using should() with a chainer.
Cypress
cy.get('button').should([1], 'active')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'have.text' checks text content, not classes.
Using 'be.enabled' checks if element is enabled, not class.
✗ Incorrect
The 'have.class' chainer checks if the element has the specified CSS class.
3fill in blank
hardFix the error in the code to check if the input contains the value 'test' using should() with chainers.
Cypress
cy.get('input').should([1], 'test')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'contain.text' does not check input value.
Using 'have.attr' requires specifying attribute name.
✗ Incorrect
The correct chainer to check input value is 'have.value'.
4fill in blank
hardFill both blanks to check if a checkbox is checked and has the attribute 'type' equal to 'checkbox'.
Cypress
cy.get('input[type="checkbox"]').should([1]).and([2], 'type', 'checkbox')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'have.value' instead of 'have.attr' for attribute check.
Using 'be.visible' does not check checked state.
✗ Incorrect
First, 'be.checked' asserts the checkbox is checked. Then, 'have.attr' checks the attribute 'type' equals 'checkbox'.
5fill in blank
hardFill all three blanks to assert that a link contains the text 'Home' and has the attribute 'href' equal to '/'.
Cypress
cy.get('a').should([1], 'Home').and([2], 'href', [3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'be.visible' as first chainer instead of 'contain.text'.
Using incorrect attribute value for href.
✗ Incorrect
The first assertion checks the link text with 'contain.text'. The second checks the 'href' attribute with 'have.attr' and the expected value '/'.