【发布时间】:2020-10-04 11:01:34
【问题描述】:
我希望赛普拉斯为以下哈希中的每个项目自动生成一个 it 块。当我目前运行 cypress 时,它可以很好地进行第二次测试,但会忽略带有 while 循环的测试。我该如何解决这个问题?我宁愿不必为地图中的每个项目写出明确的 it 块。
const testDataMappings = {
1: {e2eTestName: 'test-one'},
2: {e2eTestName: 'test-two'},
3: {e2eTestName: 'test-three'},
}
// Does not work
describe('My Tests', function () {
let i = 1;
while (i < testDataMappings.length + 1) {
let entry = testDataMappings[i];
it("Should Do The Thing Correctly For" + entry.e2eTestName, () => {
const standardCaseUrl = Cypress.config().baseUrl + "?profile_id=" + String(i);
cy.visit(standardCaseUrl);
cy.wait(5000);
cy.get('.some-div-class-name').compareSnapshot(entry.e2eTestName, 0.0);
});
i +=1;
}
// works
describe('Another Describe block', function () {
it('Should do the thing', () => {
const standardCaseUrl = Cypress.config().baseUrl + "?profile_id=1";
cy.visit(standardCaseUrl);
cy.wait(5000);
cy.get('.some-div-class-name').compareSnapshot('some-snapshot-name', 0.0);
});
});
});
控制台日志似乎没有显示,因此对正在发生的事情没有太多了解。
【问题讨论】:
标签: cypress e2e-testing