英文:
First select from dropdown how to upload file in cypress
问题
首先,点击并从下拉菜单中选择如何上传文件,比如选择"计算机"或"驱动器",选择"计算机"后,我需要从我的计算机中上传文件到Cypress。我尝试了这种方式,但是点击后没有任何动作。
cy.get(this.business_registration).click()
cy.fixture('images.png').then(fileContent => {
cy.get(this.select_browse).attachFile({
fileContent,
fileName: 'images.png',
mimeType: 'image/png'
});
});
如何使用Cypress完成这个任务?
英文:
First click and select from dropdown how to upload file like computer or drive, after selecting computer i have to upload from my computer in cypress. I'm trying this way it's not working, No action after clicking
cy.get(this.business_registration).click()
cy.fixture('images.png').then(fileContent => {
cy.get(this.select_browse).attachFile({
fileContent,
fileName: 'images.png',
mimeType: 'image/png'
});
});
What is the way to do it with Cypress?
答案1
得分: 4
看起来你忽略了上一个问题中的回答建议。
你没有使用Cypress.Blob.base64StringToBlob
进行Blob转换,这是由@ryry提供的,Cypress也在这里提供了Image Fixture。
// 程序化上传logo
cy.fixture('images/logo.png').as('logo')
cy.get('input[type=file]').then(function ($input) {
// 将logo的base64字符串转换为blob
const blob = Cypress.Blob.base64StringToBlob(this.logo, 'image/png')
// 将blob传递给fileupload jQuery插件
// https://github.com/blueimp/jQuery-File-Upload
// 在你的应用程序代码中使用
// 用于启动程序化上传
$input.fileupload('add', { files: blob })
})
另外,你提到的.click()
似乎并没有改变问题的基础。
英文:
It appears you have neglected the advice from the answer to your previous question.
You have not used Blob conversions .then(Cypress.Blob.base64StringToBlob)
as given by @ryry and also given by Cypress themselves here Image Fixture
// programmatically upload the logo
cy.fixture('images/logo.png').as('logo')
cy.get('input[type=file]').then(function ($input) {
// convert the logo base64 string to a blob
const blob = Cypress.Blob.base64StringToBlob(this.logo, 'image/png')
// pass the blob to the fileupload jQuery plugin
// https://github.com/blueimp/jQuery-File-Upload
// used in your application's code
// which initiates a programmatic upload
$input.fileupload('add', { files: blob })
})
Also, it seems that the .click()
you refer to is not changing the basis of the question.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论