Write An API Test Using Cypress

preview_player
Показать описание

// reset the backend data using POST /request call
// add an item using POST /todos call
// passing the title and the completed: false properties
{ title: 'write more tests', completed: false })
// from the response get the body and confirm
// it has the expected properties, including the "id"
.its('body')
// get the "id" property and confirm it is a number
.its('id')
// TIP: add a short wait for our simple server to
// really save the added item
.wait(100, { log: false })
.then(function (id) {
.should('eq', 'write more tests')
// and then use the DELETE /todos/:id call to delete it
// the status of the response should be 200
.its('status').should('equal', 200)
})

Рекомендации по теме
Комментарии
Автор

Hi, i utilize the API a lot in my tests and found that a better approach is to make the API request as command, so you dont have to copy paste the same 'cy.request' over and over if you have a step repeating in many tests

TBVnBIX
Автор

how do you add authorization header to each of the requests?

LekhnathRijal
Автор

Hi gleb, is there a way that we import the postman collection and it converts them into cypress tests?

rojalbati