我希望赛普拉斯为以下哈希中的每个项目自动生成一个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);
});
});
});
控制台日志似乎没有出现,因此对所发生的事情没有太多了解。
答案 0 :(得分:0)
Cypress Real World App,a payment application to demonstrate real-world usage of Cypress testing methods, patterns, and workflows中有一个示例。该示例位于transaction feeds spec中,并使用lodash
each
遍历feedViews
对象并为每个供稿动态生成测试。