vendredi 13 décembre 2019

Cypress - log response data from an request after a click()

Although I know this may not be considered as a best practice, but what I want to achieve is to silently delete a record from a database after the same was created throughout UI. In htat way I want to keep our test environment clear as much as possible and reduce the noise of test data.

After my tests create a new record by clicking over the UI, I wait for POST request to finish and then I would like to extract the id from the response (so I can reuse it to silently delete that record by calling the cy.request('DELETE', '/id')).

Here's a sample test I have put on as a showcase. I'm wondering why nothing is logged in this example.

it('GET cypress and log', () => {
  cy.server()
    .route('**/repos/cypress-io/cypress*')
    .as('getSiteInfo');

  cy.visit('https://www.cypress.io/dashboard');

  cy.get('img[alt="Cypress.io"]')
    .click()
    .wait('@getSiteInfo')
    .then((response) => {
      cy.log(response.body)
    })
})

As far as I can see from here https://docs.cypress.io/api/commands/wait.html#Alias this should be fine.

Aucun commentaire:

Enregistrer un commentaire