【问题标题】:Cypress file upload for negative testCypress 文件上传进行否定测试
【发布时间】:2021-10-17 08:45:54
【问题描述】:

我有一个接受文件并使用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...")

【问题讨论】:

  • 您只需单击上传按钮,无需选择任何内容。那么它会给你提示信息吗?
  • 不,我只有一个按钮,我没有上传按钮

标签: cypress cypress-file-upload


【解决方案1】:

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

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

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

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

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

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

  • 在选项中给出一个无效的编码,encoding: 'binary' and use valid expense1.json`

  • 在选项中给出一个无效的 mimeType

【讨论】:

    猜你喜欢
    • 2021-07-13
    • 1970-01-01
    • 1970-01-01
    • 2022-12-16
    • 1970-01-01
    • 1970-01-01
    • 2021-11-26
    • 2019-12-01
    • 1970-01-01
    相关资源
    最近更新 更多