假設我有一個簡單的測驗:
/// <reference types="cypress" />
describe('Something important', () => {
it('First test', () => {
...
})
})
我需要做的是處理如果發生了什么事情First test,我正在嘗試類似的事情,但它不是這樣作業的:
it('First test', () => {
try {
...
} catch (e) {
... // send email, for example
}
})
所以,在某種程度上,我需要處理測驗中發生的任何事情。是否可以?像這樣的東西,但對于整個測驗:
cy.get('button').contains('hello')
.catch((err) => {
// oh no the button wasn't found
// (or something else failed)
cy.get('somethingElse').click()
})
uj5u.com熱心網友回復:
這是您需要捕獲測驗失敗的原因嗎?
Cypress.on('fail', (error, runnable) => {
debugger
// we now have access to the err instance
// and the mocha runnable this failed on
throw error // throw error to have test still fail
})
這將在測驗失敗時觸發,因此您可以執行電子郵件或其他操作。
但通常賽普拉斯希望您知道按鈕會在那里。你不應該在頁面上有太多不可預測的東西(或者不在頁面上,視情況而定)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/424106.html
標籤:javascript 单元测试 测试 柏
