2 回答
TA贡献1936条经验 获得超6个赞
您也可以使用这个 Cypress 插件,同时 Cypress 本身不支持此功能:https : //www.npmjs.com/package/cypress-fail-fast
将插件添加到 devDependencies:
npm i --save-dev cypress-fail-fast
在 cypress/plugins/index.js 里面:
module.exports = (on, config) => {
require("cypress-fail-fast/plugin")(on, config);
return config;
};
在 cypress/support/index.js 的顶部:
import "cypress-fail-fast";
TA贡献1856条经验 获得超5个赞
正如您所提到的,它还没有得到官方支持(从 3.6.0 开始)。
这是我对 hack 的看法(不使用 cookie 等来保持状态):
// cypress/plugins/index.js
let shouldSkip = false;
module.exports = ( on ) => {
on('task', {
resetShouldSkipFlag () {
shouldSkip = false;
return null;
},
shouldSkip ( value ) {
if ( value != null ) shouldSkip = value;
return shouldSkip;
}
});
}
// cypress/support/index.js
function abortEarly () {
if ( this.currentTest.state === 'failed' ) {
return cy.task('shouldSkip', true);
}
cy.task('shouldSkip').then( value => {
if ( value ) this.skip();
});
}
beforeEach(abortEarly);
afterEach(abortEarly);
before(() => {
if ( Cypress.browser.isHeaded ) {
// Reset the shouldSkip flag at the start of a run, so that it
// doesn't carry over into subsequent runs.
// Do this only for headed runs because in headless runs,
// the `before` hook is executed for each spec file.
cy.task('resetShouldSkipFlag');
}
});
一旦遇到故障,将跳过所有进一步的测试。输出将如下所示:
添加回答
举报