Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load a fixture file named 'user.json' before the test.
Cypress
cy.fixture([1]).then((user) => { cy.log(user.name) }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the fixture file name
Omitting the .json extension
✗ Incorrect
The fixture file name must be a string with quotes, including the extension, so 'user.json' is correct.
2fill in blank
mediumComplete the code to intercept a GET request to '/api/user' and respond with fixture data.
Cypress
cy.intercept('GET', '/api/user', { fixture: [1] }).as('getUser')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Including the .json extension in the fixture name
Not using quotes around the fixture name
✗ Incorrect
When using fixture in intercept, the fixture name is given without the .json extension and as a string, so 'user' is correct.
3fill in blank
hardFix the error in the code to wait for the intercepted request alias 'getUser'.
Cypress
cy.wait([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the '@' symbol before the alias
Not using quotes around the alias
✗ Incorrect
To wait for an intercepted request, you must use the alias with '@' and quotes, like '@getUser'.
4fill in blank
hardFill both blanks to intercept a POST request to '/api/login' and respond with fixture 'loginResponse'.
Cypress
cy.intercept([1], [2], { fixture: 'loginResponse' }).as('postLogin')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'GET' instead of 'POST' for the method
Using wrong URL path in the intercept
✗ Incorrect
The first argument is the HTTP method 'POST', the second is the URL '/api/login' to intercept the correct request.
5fill in blank
hardFill all three blanks to load fixture 'profile', intercept GET '/api/profile', and wait for the alias.
Cypress
cy.fixture([1]).then((profile) => { cy.intercept([2], { fixture: profile }).as('getProfile') cy.wait([3]) })
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting .json in fixture file name
Using URL instead of method in intercept
Not using '@' in wait alias
✗ Incorrect
Load fixture with 'profile.json', intercept with method 'GET', and wait for alias '@getProfile'.