cypress-file-upload AttachFile 不是一个函数

J.e*_*ome 5 javascript cypress

我想使用 Cypress-file-upload 测试我的文件上传功能,但我伤害了自己.attachFile is not a function

在此输入图像描述

我尝试了两种解决方案,但仍然无法使其工作:

// 1st one, "find file input" works

  it('find file input', () => {
    cy.get('input[type="file"')
  })
  
  const fileName = 'french_tweets_split.csv';
  it('Testing csv uploading', () => {
    cy.fixture(fileName, 'binary')
      .then(Cypress.Blob.binaryStringToBlob)
      .then(fileContent => {
        cy.get("input[type='file']").attachFile({ fileContent, fileName, mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', encoding:'utf8' })
    })
  })
Run Code Online (Sandbox Code Playgroud)
// 2nd one, "find file input" works
  it('find file input', () => {
    cy.get('input[type="file"')
  })
  
  it('Testing csv uploading', () => {
    cy.fixture('french_tweets_split.csv').then(fileContent => {
        cy.get('input[type="file"]').attachFile({
            fileContent: fileContent.toString(),
            fileName: 'french_tweets_split.csv',
            mimeType: 'text/csv'
        })
    })
  })

Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么 ?

Ous*_*led 8

您需要首先安装cypress-file-upload开发依赖项:

npm i cypress-file-upload --save-dev
Run Code Online (Sandbox Code Playgroud)

然后在cypress/support/index.js中导入

import 'cypress-file-upload'
Run Code Online (Sandbox Code Playgroud)


pav*_*man 7

您必须导入该包:

支持/index.js

import 'cypress-file-upload';
Run Code Online (Sandbox Code Playgroud)