Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to visit the login page in Cypress.
Cypress
cy.[1]('/login')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
click instead of visit to open a page.✗ Incorrect
The visit command loads a page URL in Cypress, which is needed to start login.
2fill in blank
mediumComplete the code to fill the username input field.
Cypress
cy.get('input[name="username"]').[1]('myUser')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
click or select instead of type.✗ Incorrect
The type command enters text into input fields in Cypress.
3fill in blank
hardFix the error in the code to submit the login form.
Cypress
cy.get('form').[1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
click on the form instead of submit.✗ Incorrect
The submit() command triggers form submission in Cypress.
4fill in blank
hardFill both blanks to create a custom command for login that speeds up tests.
Cypress
Cypress.Commands.[1]('login', (username, password) => { cy.request('POST', '/api/login', { username: username, [2]: password }) })
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
send or post instead of add for command creation.✗ Incorrect
Cypress.Commands.add defines a new command. The password key must be correct to send credentials.
5fill in blank
hardFill all three blanks to use the custom login command and speed up the test suite.
Cypress
describe('Dashboard tests', () => { beforeEach(() => { cy.[1]('login', 'user1', [2]) cy.[3]('/dashboard') }) it('shows welcome message', () => { cy.contains('Welcome').should('be.visible') }) })
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
click instead of visit to load the page.✗ Incorrect
Use the custom login command with username and password, then visit the dashboard page.