【发布时间】:2019-04-24 10:09:49
【问题描述】:
我有以下测试需要验证单击链接是否会下载 PDF。这一点尤其重要,因为我们使用的是 Gatsby,而 Gatsby 又使用 Reach Router 的链接组件,并且相对容易错误配置,以便路由器接管链接并导航到 404 页面而不是启动下载。
describe.skip(`Downloads`, () => {
it(`Downloads the expected file`, () => {
cy.visit(pagePath)
cy.getByHref(downloadPath)
.should(`have.attr`, `target`, `_blank`)
.click()
cy.location(`pathname`).should(`eq`, pagePath)
})
})
虽然这并不完美,但它至少会检查单击链接后是否没有导航。
问题在于,当使用在 Chrome 中运行测试的 cy run 运行此测试时,由于 Chrome 的下载对话框,测试会挂起。
如何防止测试挂起?
请注意,downloadPath 解析为静态目录中的 pdf,例如 /static/example.pdf。没有服务器组件。
另请注意,这是一个不同的问题:How can I use Cypress.io to assert that a file download has been initiated without actually downloading?
【问题讨论】:
-
你检查过这个问题吗?我认为这正是您所描述的github.com/cypress-io/cypress/issues/433
-
另外,这正在处理中:github.com/cypress-io/cypress/issues/311
-
这可能对dev.to/viveknayyar/…有帮助
-
@VivekN 谢谢。我没有考虑检查文件,但这依赖于使用具有固定时间的等待,根据我的经验,这是易碎测试的秘诀。
标签: javascript google-chrome testing download cypress