Web*_*ity 2 unit-testing cypress
我有一个测试用例来修复X出现1次的错误。我想多次运行同一测试,但是找不到任何说明如何自动重新启动测试以及在达到阈值时停止测试的文档。任何见解表示赞赏
Get*_*ald 23
您可以在循环内添加测试块。
Cypress与一些库捆绑在一起,lodash可以使用以下方法来做到这一点:Cypress._.times方法:
Cypress._.times(10, () => {
describe('Description', () => {
it('runs 10 times', () => {
//...
});
});
});
Run Code Online (Sandbox Code Playgroud)
Sam*_*Sam 11
您可以将循环放入外部空间,而不是将循环放入测试中,如下所示
var i = 0;
for (i = 0; i < 3 ; i++) {
describe('Verify "Login" is visible. Test: '+i, function() {
it('finds the Login link in the header', function() {
//Place code inside the loop that you want to repeat
})
})
}
Run Code Online (Sandbox Code Playgroud)
结果如下:
我完全隔开了,并且忘记了这些是普通的JS文件,因此我将测试包裹在for循环中。这似乎按我的预期工作。
describe('Verify "Login" is visible', function() {
it('finds the Login link in the header', function() {
var i = 0;
for (i = 0; i < 5 ; i++) {
//Place code inside the loop that you want to repeat
cy.visit('https://www.example.com/page1')
cy.get('.navbar').contains('Login').should('be.visible')
cy.visit('https://www.example.com/page2')
cy.get('.navbar').contains('Login').should('be.visible')
}
})
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3030 次 |
| 最近记录: |