0

我有一个接受文件并使用的表单cypress-file-upload,我让它正常工作。但是我也有一个场景,当没有文件上传时我需要验证错误。包本身正在验证文件是否存在。在这种情况下我们如何测试?

cy.get('input[type="file"]').attachFile();// Cannot read property 'filePath' of undefined
cy.get('input[type="file"]').attachFile(""); //missing "filePath" or "fileName".
Please make sure you are passing either "filePath" or "fileName"
cy.get('input[type="file"]').attachFile("expense1.json")//Works for the positive case
cy.get(".alert").should('be.visible').and('contain', "You poor guy did not upload a file...")
4

1 回答 1

0

从问题中不清楚用户将如何做错事并导致警报,这是您想要在测试中复制的内容。

如果只是为了检查发生了一些内部错误,可能没有这样的用户路径。

您应该准确找出触发警报的原因并进行相应的测试。

在这种情况下,这里有一些想法

  • 选项allowEmpty: truecy.get('input[type="file"]').attachFile("")

  • 制作expense1.json二进制文件,或空文件,或格式错误的 json(删除括号)

  • 在选项中给出无效编码,encoding: 'binary' and use valid 费用 1.json`

  • 在选项中给出无效的 mimeType

于 2021-10-17T19:36:39.900 回答