Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a test block using Cypress.
Cypress
describe('My First Test', () => { it('[1]', () => { cy.visit('https://example.com') }) })
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a vague or unrelated string inside the it block
Leaving the it block description empty
✗ Incorrect
The it block describes what the test does. Here, it should say what is being checked, like 'checks the homepage loads'.
2fill in blank
mediumComplete the code to visit a URL inside an it block.
Cypress
it('visits the page', () => { cy.[1]('https://example.com') })
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
cy.click() instead of cy.visit()Using
cy.get() which selects elements, not pages✗ Incorrect
The cy.visit() command loads a webpage in Cypress tests.
3fill in blank
hardFix the error in the it block to correctly check the page title.
Cypress
it('checks the title', () => { cy.title().[1]('eq', 'Example Domain') })
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
get which selects elements, not assertionsUsing
visit or click which are unrelated here✗ Incorrect
The should command is used to make assertions in Cypress.
4fill in blank
hardFill both blanks to select an element and check its text.
Cypress
it('checks header text', () => { cy.[1]('h1').[2]('contain', 'Welcome') })
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
click instead of getUsing
visit instead of should✗ Incorrect
cy.get() selects the element, and should('contain', ...) asserts its text.
5fill in blank
hardFill all three blanks to write a test that types into an input and checks its value.
Cypress
it('types in input and checks value', () => { cy.[1]('input[name="username"]').[2]('user123') cy.[3]('input[name="username"]').should('have.value', 'user123') })
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
invoke instead of typeNot selecting the element before typing
✗ Incorrect
Use get to select the input, type to enter text, and get again to select for assertion.