我有一个接受文件的表单,使用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...")发布于 2021-10-17 19:36:40
从问题中不清楚用户会如何做错误的事情并导致警报,这是你想要在测试中复制的。
也许没有这样的用户路径,如果只是为了检查发生的一些内部错误。
您应该找出触发警报的确切原因,并进行相应的测试。
在这种情况下,这里有一些想法
cy.get('input[type="file"]').attachFile("")和
allowEmpty: trueexpense1.json成为二进制文件、空文件或格式错误的json (删除括号)在options,expense1.json` expense1.json`中,
中给出无效的mimeType
https://stackoverflow.com/questions/69602661
复制相似问题