File 使用Cypress文件上载使用Cypress上载xlsx文件
我使用cypress file upload将xlsx文件上传到表单中 我尝试了两种解决方案File 使用Cypress文件上载使用Cypress上载xlsx文件,file,encoding,cypress,File,Encoding,Cypress,我使用cypress file upload将xlsx文件上传到表单中 我尝试了两种解决方案 // First one cy.fixture(fileName).then((fileContent) => { cy.get("input[type='file']").attachFile({ fileContent, fileName, encoding : 'UTF-8', mimeType :
// First one
cy.fixture(fileName).then((fileContent) => {
cy.get("input[type='file']").attachFile({
fileContent,
fileName,
encoding : 'UTF-8',
mimeType : 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
})
})
// Second one
cy.get("input[type='file']").attachFile({
filePath : "file/path",
encoding : 'utf-8',
mimeType : 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
})
对于这两种解决方案,上载文件时不会出现Cypress错误,但表单会拒绝该文件,并显示一般错误消息
有什么想法吗?我打赌编码是有道理的,但我找不到什么。。。谢谢请尝试使用下面的代码
编辑:
const fileName = 'upload_1.xlsx';
cy.fixture(fileName, 'binary')
.then(Cypress.Blob.binaryStringToBlob)
.then(fileContent => {
cy.get("input[type='file']").attachFile({ fileContent, fileName, mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', encoding:'utf8' })
})
嗯。。。尝试后出现以下错误:
TypeError:cy.get(…)。当我将upload
替换为attachFile
;)时,upload不是一个功能谢谢,我接受你的回答!!