首先从下拉菜单中选择如何在Cypress中上传文件。

huangapple go评论64阅读模式
英文:

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'
          });
     });

首先从下拉菜单中选择如何在Cypress中上传文件。
首先从下拉菜单中选择如何在Cypress中上传文件。

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.

huangapple
  • 本文由 发表于 2023年8月9日 14:08:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76864997-2.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定