【发布时间】:2019-05-09 21:54:12
【问题描述】:
所以,我有一个 beforeEach 来加载我的网站。我主要在一个describe 函数和一个it 函数中编写我的测试。
我的 beforeEach 在 index.js>Support>Cypress 文件夹中
beforeEach(() => {
cy.visit('http://localhost:3000/');
});
当前代码示例:
describe('this is a test',function(){
it('will be a test example',function(){
cy.contains('test').click
cy.contains('another test').click()
})
})
一位同事指出,只要每个部分都可以独立运行,我应该尝试将它们分解,以便更清楚地了解每个测试在做什么。我有几个可以独立运行的测试,但是,对于我写的每个it('test_name',function(),beforeEach 都会启动。
例如:我写了一个测试来打开一张卡片,点击一个状态,添加关于该状态的数据,然后关闭。如果我将每个部分分成它自己的it,那么它将在我的网站的“主页”页面上重新开始 beforeEach。
所需代码示例:
describe('this is a test',function(){
it('will be a test example',function(){
cy.contains('test').click
})
it('will test another test',function(){
cy.contains('another test').click()
})
})
有没有办法让这几个 it 函数继续上一个测试而不是让 beforeEach 生效?
提前谢谢你。
【问题讨论】:
标签: cypress