[自动测试,工具:赛普拉斯]
大家好,
我想添加图像,但是出现一些错误。
我使用了代码:
cy.fixture("logo.jpg").as("logo")
cy.get('input[type=file]').eq(0).then(subject => {
return Cypress.Blob.base64StringToBlob(this.logo, "image/jpeg").then((blob) => {
const el = subject[0]
const testFile = new File([blob], 'logo.jpg', { type: 'image/jpeg' })
const dataTransfer = new DataTransfer()
dataTransfer.items.add(testFile)
el.files = dataTransfer.files
})
})
然后我收到一个错误:
TypeError: Cannot read property 'logo' of undefined
当我将 cy.fixture(“ logo.jpg”)赋予const变量时,我收到了错误消息:
InvalidCharacterError: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
即使我想使用文档中的代码,我也会遇到相同的情况,同样的问题:
cy.fixture("logo.jpg").as("logo")
cy.get("input[type=file]").eq(0).then(($input) => {
// convert the logo base64 string to a blob
return Cypress.Blob.base64StringToBlob(this.logo, "image/jpeg").then((blob) => {
// pass the blob to the fileupload jQuery plugin
// used in your application's code
// which initiates a programmatic upload
$input.fileupload("add", { files: blob })
})
})
有人有类似的问题还是有人有任何想法?