【发布时间】:2020-11-06 07:20:39
【问题描述】:
我正在 Cypress 中编写一个简单的测试,单击一个按钮并开始下载。 API 的响应包含 csv 文件的未格式化内容,因此我可以使用它来断言我想要的内容 - 但问题是当您使用 Chrome 或 Firefox 进行测试时,下载仍然会发生。没有对话提示 - 下载发生在点击 - 但我想知道是否有办法阻止它发生,也许是 cy.window() 或 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')
})
})
谢谢
【问题讨论】:
标签: javascript testing automation download cypress