如何在Chrome中运行时使用赛普拉斯测试文件下载

问题描述 投票:2回答:1

我有以下测试需要验证单击链接下载PDF。这一点尤其重要,因为我们使用的是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)
  })
})

虽然这并不完美,但它至少会检查单击链接后是否没有导航。

问题是,当使用cy run运行此测试时,由于Chrome的下载对话,测试会在Chrome中运行测试。

如何防止测试挂起?

请注意,downloadPath解析为静态目录中的pdf,例如/static/example.pdf。没有服务器组件。

另请注意,这是一个不同的问题:How can I use Cypress.io to assert that a file download has been initiated without actually downloading?

javascript google-chrome testing download cypress
1个回答
-1
投票

实际上我搜索了很多,发现在安装了浏览器扩展的无头模式下运行测试是不可能的,因为无头模式下唯一支持的浏览器是Electron,Electron不支持文档中所述的扩展。

目前还不支持运行无头Chrome。看到这个问题:#488 https://github.com/cypress-io/cypress/issues/488

这是一个不太老的问题,它在2019年2月被标记

https://github.com/cypress-io/cypress/issues/832 https://github.com/cypress-io/cypress/issues/1235

© www.soinside.com 2019 - 2024. All rights reserved.