javascript - 赛普拉斯没有上传图片
问题描述
我正在自动化 cypress 中的一个用例,但我无法使用附加文件功能上传图像。以下是 HTML 标记的代码和片段
用户界面上传图片
HTML 标签
VS 代码
解决方案
我认为您想将文件附加到<input>
作为第一步。然后单击按钮,或者您甚至可能不必执行 click()。
从文档中,
// start watching the POST requests
cy.intercept({ method: 'POST', url: /upload_endpoint/ }).as('upload');
const myFilePath = 'product.jpeg'; // file is in "/cypress/fixtures/" folder
cy.fixture(myFilePath, 'binary')
.then(Cypress.Blob.binaryStringToBlob)
.then(fileContent => {
cy.get('input#productImageUpload').attachFile({
fileContent,
fileName: myFilePath,
mimeType: 'application/octet-stream',
encoding:'utf8',
lastModified: new Date().getTime(
})
})
cy.get('.label-side').click() // may not need to do this
// wait for the 'upload_endpoint' request, and leave a 2 minutes delay before throwing an error
cy.wait('@upload', { requestTimeout: 120000 });
推荐阅读
- rust - 在 Rust 的元组中传递多个引用
- node.js - 如何将只有一个元素的数组转换为猫鼬(mongodb)中的对象
- pytorch - 在 PyTorch 中为 nn.functional.conv2d 提供权重
- html - 如何在没有边距的 HTML 表格中的两个文本块之间放置一条线?
- flutter - Flutter web - ReordorableListView,在字段之间悬停时带有+按钮
- html - 媒体查询不起作用。我究竟做错了什么?
- python - pip 命令未找到,安装 django 时在 mac 上未找到 virtualenv 命令
- laravel - 如何在由 Laravel api 提供支持的移动应用程序中处理异地支付
- tomcat - javax.servlet.ServletException:类 [org.glassfish.jersey.servlet.ServletContainer] 不是 Servlet
- java - 如何在硒中并行运行多个类