【发布时间】:2019-09-19 18:37:34
【问题描述】:
我正在尝试对显示在两个单独页面上的组件运行完全相同的赛普拉斯测试。为了实现这一点,我想我会使用forEach 声明
以便为每个“状态”运行相同的代码(参见下面的代码)。
问题在于before 语句中的代码块开始为状态#2 运行,在状态#1 的测试完成之前。这会导致状态 #1 的测试失败(因为它有状态 #2 固定装置)。
如何使状态#2 的before 部分等待状态#1 中的所有测试完成?
const states = [
{
"startPath": "/path1",
"fixture": "fixture1"
},
{
"startPath": "/path2",
"fixture": "fixture2"
}
]
describe('Start test', function() {
// Loop through both test
states.forEach((state) => {
// In this before statement the fixtures are setup
before(function () {
cy.flushDB()
cy.fixture(state.fixture)
.then(fixtureData => {
new Cypress.Promise((resolve, reject) =>
cy.createCollections(fixtureData, resolve, reject)
)
})
.then(() => cy.visit(state.startPath))
})
context('Within this context', function() {
it(`Can run some test for fixture ${state.fixture}`, function() {
})
})
})
})
【问题讨论】:
标签: javascript cypress