如何测试赛普拉斯的文件上传功能?

问题描述 投票:0回答:2

我目前正深入研究赛普拉斯并为应用程序编写e2e测试。在测试文件上传功能方面,我似乎遇到了障碍。由于我作为QA工程师的初学者身份以及在这个特定问题上缺乏互联网流量,我已达到并陷入僵局。我在Docs中遇到了Cypres.Blob。不幸的是,没有很多记录,我无法将这些例子应用到我需要学习的内容中。

describe('文件上传测试',()=> {

it('should upload a file', () => {
    let testfile = cy.fixture('../fixtures/cypresstest.txt')
    cy.get('input[type=file]').then(($input) => {
    return Cypress.Blob.base64StringToBlob(testfile, 'file/txt')
        .then((blob) => {
        $input.fileupload('add', { files: blob })
        })
    })
})

});

javascript file-upload e2e-testing qa cypress
2个回答
1
投票

我正在测试我们的文件上传服务,如下所示:

Cypress.Commands.add('uploadFile', (fileNamePath, fileName, fileType = ' ', selector) => {
cy.get(selector).then(subject => {
    cy.fixture(fileNamePath, 'base64')
        .then(Cypress.Blob.base64StringToBlob)
        .then(blob => {
            const el = subject[0]
            const testFile = new File([blob], fileName, {
                type: fileType
            })
            const dataTransfer = new DataTransfer()
            dataTransfer.items.add(testFile)
            el.files = dataTransfer.files
        })
})

})

然后在spec文件中。单击上载按钮并等待文件加载:

cy.server().route('POST', api-upload-url).as('loadUp')
        cy.uploadFile('./pathToFile/' + fileName, fileName, fileType, fileInput);
        cy.get('.btn-upload.mat-raised-button.mat-primary').click()
        cy.wait('@loadUp').then((response) => {
            expect(response.method).to.eq('POST')
            expect(response.status).to.eq(200)
            expect(response.response.body.status).to.eq('OK')
        })

还有一个检查所需的答案。

它不是超级花哨和优化。但它适用于3.1.5和3.2.0。它使用电子59头部和无头


0
投票

我注意到Cypress 3.1.5尚不支持测试文件上传功能。

© www.soinside.com 2019 - 2024. All rights reserved.