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)
我究竟做错了什么 ?
您需要首先安装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)
| 归档时间: |
|
| 查看次数: |
9911 次 |
| 最近记录: |