0

我有一个用 Cypress 编写的测试。上传一个 pdf 文件的测试之一如下所示:

it('uploads one document', () => {
        cy.get('input[type="file"]')
        .attachFile({ filePath: pdfFilePath, encoding: 'base64' , mimeType: 'application/pdf'});

        cy.get('div.table-body>.table-row')
            .find('.col-upload-name')
            .should('have.text', 'TestDocument.pdf')

        cy.get('a.button-action').contains('Upload').click()

        cy.get('div.table-body>.table-row')
            .find('.status-done')
            .should('contain.text', 'Uploaded')
    })

其中 pdfFilePath 是灯具目录中 pdf 文件的字符串路径。

当上传 pdf 文件的测试位于测试套件的开头时,它们通过:

在此处输入图像描述

当它们在测试套件的末尾时,它们会失败:

在此处输入图像描述

我得到这个错误:

在此处输入图像描述

有谁知道为什么会这样?

4

1 回答 1

0

我尝试在我这边重现这个问题。我没有得到同样的错误,但它没有添加文件。添加后fileContent它对我有用。

    cy.get('[type="file"]').attachFile({
      fileContent,
      filePath: "filepath",
      fileName: "filename",
      encoding: 'base64', 
      mimeType: 'application/pdf'

});
于 2021-11-03T13:09:30.810 回答