如何向赛普拉斯故障添加其他数据?



我想在测试用例失败时记录其他数据。在哪里可以最好地插入自定义错误处理程序?

例如:

cy.get('something')
.should('have.property', 'blah')

当这在赛普拉斯仪表板中失败时,我得到:

CypressError: Timed out retrying: expected 'something' to have a property 'blah'
at Object.cypressErr (https://my.website.com/__cypress/runner/cypress_runner.js:65727:11)
at Object.throwErr (https://my.website.com/__cypress/runner/cypress_runner.js:65692:18)
at Object.throwErrByPath (https://my.website.com/__cypress/runner/cypress_runner.js:65719:17)
at retry (https://my.website.com/__cypress/runner/cypress_runner.js:59237:16)
at https://my.website.com/__cypress/runner/cypress_runner.js:51312:18
at tryCatcher (https://my.website.com/__cypress/runner/cypress_runner.js:131273:23)
at Promise._settlePromiseFromHandler (https://my.website.com/__cypress/runner/cypress_runner.js:129291:31)
at Promise._settlePromise (https://my.website.com/__cypress/runner/cypress_runner.js:129348:18)
at Promise._settlePromise0 (https://my.website.com/__cypress/runner/cypress_runner.js:129393:10)
at Promise._settlePromises (https://my.website.com/__cypress/runner/cypress_runner.js:129468:18)
at Async._drainQueue (https://my.website.com/__cypress/runner/cypress_runner.js:126197:16)
at Async._drainQueues (https://my.website.com/__cypress/runner/cypress_runner.js:126207:10)
at Async.drainQueues (https://my.website.com/__cypress/runner/cypress_runner.js:126081:14)
at <anonymous>

我可以做些什么来自定义此错误,如下所示:

CypressError: ...
My additional logging: {foo: 'bar', etc, etc}

最终,我想记录一些额外的上下文数据,以便我可以调查 + 调试测试可能失败/剥落的原因。

我希望这个库能帮助你的需求 - https://github.com/cypress-io/error-message

这是它的要点,

//Load the function from the module
const {formErrorText} = require('@cypress/error-message')
//Handle the error with custome messages
const fileSaveError = {
description: 'We could not save an important file',
solution: `Please check folder permissions and try again
more details on our FAQ page: https://faq.company.name
`
}
fs.writeFile(name)
.catch(
formErrorText(info).then(console.error)
)
/*
shows nice error message
------
We could not save an important file
Please check folder permissions and try again
more details on our FAQ page: https://faq.company.name
Exception message
------
Platform: darwin
Version: 15.6.2
*/

有关更多信息,您可以查看此博客 - https://www.cypress.io/blog/2017/07/26/good-error-messages/#Useful-E2E-assertion-failures

编辑 1:

如评论中所述,如果您正在寻找处理神秘故障,建议您查看赛普拉斯事件处理机制。这是它的摘录,

// likely want to do this in a support file
// so it's applied to all spec files
// cypress/support/index.js
Cypress.on('uncaught:exception', (err, runnable) => {
// Handle your logging logic here
})

最新更新