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

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

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中上传文件。
首先从下拉菜单中选择如何在Cypress中上传文件。

如何使用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

看起来你忽略了上一个问题中的回答建议。

你没有使用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.

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

发表评论

匿名网友

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

确定