英文:
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
看起来你忽略了先前问题的答案中的建议。
你没有使用Blob转换.then(Cypress.Blob.base64StringToBlob),这是由@ryry提供的,并且Cypress也在这里图像Fixture中提供了相同的方法。
此外,你提到的.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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。




评论