79435559

Date: 2025-02-13 08:56:02
Score: 0.5
Natty:
Report link

To save data like request responses for later use, apply an alias, described here Variables and aliases

Rather that individual properties, take the whole body and destructure parts as required, for example

it('saves the response as an alias', () => {
  let id = 2
  cy.request({
    method: 'GET',
    url: `https://jsonplaceholder.typicode.com/posts/${id}`,
  })
  .then(response => {
    expect(response.status).to.eq(200)  // check status inline
  })
  .its('body')                   // take the response body
  .as('response')                // assign it to an alias


  /// later

  cy.get('@response')
    .its('title')
    .should('eq', 'qui est esse')
})

enter image description here

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Klompus