简体   繁体   English

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

[英]Cypress Not Allowing Configurable Tests

I would like Cypress to auto-generate an it block for each item in the below hash.我希望赛普拉斯为以下哈希中的每个项目自动生成一个 it 块。 When I currently run cypress, it picks up on the second test just fine, but ignores the one with the while loop.当我目前运行 cypress 时,它在第二个测试中表现得很好,但忽略了带有 while 循环的那个。 How can I resolve this?我该如何解决这个问题? I'd prefer not to have to write out an explicit it block for each item in the map.我宁愿不必为地图中的每个项目写出一个明确的 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);
            });
        });
    });

Console logs don't seem to show up, so don't have much insight into what is happening.控制台日志似乎没有出现,所以对发生的事情没有太多了解。

There is an example in the Cypress Real World App , a payment application to demonstrate real-world usage of Cypress testing methods, patterns, and workflows . Cypress Real World App 中有一个示例,这是一个支付应用程序,用于演示 Cypress 测试方法、模式和工作流的实际使用情况 The example is in the transaction feeds spec and uses lodash each to iterate over a feedViews object and dynamically generate the tests for each feed.该示例在事务提要规范中,并使用lodash each来迭代feedViews对象并为每个提要动态生成测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM