automate asserting network payload data #21051
-
Hi Im new to cypress , I need to assert/validate the payload data , is it possible ? if yes can you please provide an example |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
Yes, you can assert the request object before it is sent. You'll use a callback function and make request body. // match requests method and url
cy.intercept('POST', '/users', (req) => {
// make assertions on keys or contents
expect(req.body).to.include.key('qryEmployeeForm')
// make an assertion on the payload contents
expect(req.body.qryEmployeeForm.orderBy).to.eq('NAME')
}) |
Beta Was this translation helpful? Give feedback.
-
wow this is awesome thank you for this much appreciated quick question how do you assert on something like this : { expect(req.body).to.include.key('["code 12332"]') expected ["code 12332"] to contain key code 12332 |
Beta Was this translation helpful? Give feedback.
-
for some reason instance of (Array) didn't work, but this work form me , |
Beta Was this translation helpful? Give feedback.
Yes, you can assert the request object before it is sent. You'll use a callback function and make request body.