赛普拉斯不允许进行可配置的测试

时间:2020-10-04 11:01:34

标签: cypress e2e-testing

我希望赛普拉斯为以下哈希中的每个项目自动生成一个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);
            });
        });
    });

控制台日志似乎没有出现,因此对所发生的事情没有太多了解。

1 个答案:

答案 0 :(得分:0)

Cypress Real World Appa payment application to demonstrate real-world usage of Cypress testing methods, patterns, and workflows中有一个示例。该示例位于transaction feeds spec中,并使用lodash each遍历feedViews对象并为每个供稿动态生成测试。

相关问题