我想测试上传文件和下载文件的内容是否相同。所以,以下是我通过柏树尝试过的:
it.only(cfg.testname, () => {
// 1. Login to website, navigate to desired webapge
// 2. Upload the file
// 3. Download the file
// cy.wait(5000)
// 4. Read the uploaded file:
const fileContent = cy.fixture(_filePath)
console.log('fixture file path', '======>', _filePath)
console.log('fixture file content', '=====>', fileContent)
// 5. Read the downloaded file:
const downloadsFolder = Cypress.config("downloadsFolder")
const downloadedFileContent = cy.readFile(path.join(downloadsFolder, _fileName))
console.log('downloaded file path', '======>', path.join(downloadsFolder, fileName))
console.log('downloaded file content','====>', downloadedFileContent)
// 6. Check if they are equal:
expect(downloadedFileContent).equals(fileContent)
})
但是,当我运行此测试时,它甚至没有完成登录步骤并立即给出断言错误第 6 步,即 on expect()...:
AssertionError: expected { Object (userInvocationStack, specWindow, ...) } to equal {
Object (userInvocationStack, specWindow, ...) }
at Context.eval (VM753 tests:224)
当我评论第 6 步时expect()...,它会正确登录、上传文件和下载文件。所以,我觉得我应该让这个过程等到下载完成之前expect()...。所以我尝试取消注释cy.wait(5000),但没有帮助。它仍然给我以上错误(当然没有expect()...注释)。
Q1。为什么会有这种行为?
Q2。我应该如何解决这个问题?
PS:我在控制台中遇到了一堆我无法理解的错误。这是控制台的屏幕截图:
