jeudi 16 juillet 2020

Is there a way I can prevent downloads when testing with Cypress

I'm writing a simple test in Cypress which clicks a button and starts a download. The API's response contains the unformatted contents of the csv file, so I can use that to assert what I want - but the problem is that when you're using Chrome or Firefox to test with, the download still occurs. There is no dialogue prompt - the download happens on click - but I was wondering if maybe there was a way I could prevent it from happening, maybe with cy.window() or cy.stub()?

it('Export list to CSV', () => {
    //Click button and assert on the API
    cy.findByTestId('btnExport_SystemUsers')
      .should('be.visible')
      .click()
      .wait('@exportToCsv')
      .then((xhr) => {
        //Assert on some keywords from the response such as Role names, user names, and site group name (that won't change)
        expect(xhr.status).to.eq(200)
        expect(xhr.response.body.csvFileData).to.contain('CY.User')
        expect(xhr.response.body.csvFileData).to.contain('CY.Admin')
        expect(xhr.response.body.csvFileData).to.contain('unlockUserAccount')
        expect(xhr.response.body.csvFileData).to.contain('CY Administrator')
        expect(xhr.response.body.csvFileData).to.contain('Site Group 1')
      })
  })

Thanks

Aucun commentaire:

Enregistrer un commentaire