0
0
Cypresstesting~10 mins

Why intercepting network validates API integration in Cypress - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to intercept a GET API call using Cypress.

Cypress
cy.intercept('GET', [1]).as('getData')
Drag options to blanks, or click blank then click option'
A'/api/data'
B'POST'
C'/home'
D'PUT'
Attempts:
3 left
💡 Hint
Common Mistakes
Using HTTP methods like 'POST' or 'PUT' instead of the correct URL.
Not specifying the correct URL pattern.
2fill in blank
medium

Complete the code to wait for the intercepted API call to finish.

Cypress
cy.wait([1])
Drag options to blanks, or click blank then click option'
A'@postData'
B'postData'
C'getData'
D'@getData'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the '@' symbol before the alias.
Using the wrong alias name.
3fill in blank
hard

Fix the error in the assertion to check the API response status code.

Cypress
cy.wait('@getData').its('response.statusCode').should([1], 200)
Drag options to blanks, or click blank then click option'
A'eq'
B'equal'
C'equals'
D'is'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'eq' which is not a Cypress assertion method.
Using 'equals' or 'is' which are invalid.
4fill in blank
hard

Fill both blanks to assert the API response body contains the expected user name.

Cypress
cy.wait('@getData').its('response.body').should([1], [2])
Drag options to blanks, or click blank then click option'
A'have.property'
B'include'
C'user123'
D'name'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'include' instead of 'have.property' for object keys.
Checking for the value instead of the property name.
5fill in blank
hard

Fill all three blanks to intercept a POST request, wait for it, and assert the response status is 201.

Cypress
cy.intercept([1], [2]).as('postUser')
cy.wait([3]).its('response.statusCode').should('equal', 201)
Drag options to blanks, or click blank then click option'
A'POST'
B'/api/users'
C'@postUser'
D'GET'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'GET' instead of 'POST' for the intercept.
Omitting the '@' in the wait alias.
Using wrong URL or alias names.