Warm tip: This article is reproduced from serverfault.com, please click

How to dynamically generate test cases in Cypress?

发布于 2020-07-27 11:25:31

I have a JSON file in while I store the test data needed for my Cypress tests but I would like to generate specific it blocks dynamically based on the contents of object keys/values (not every object has the same values or needs to perform the same steps).

So for example, if I have the following testData objects:

[
    {
        "name": "Do Something",
        "type": "A",
        
    },
    {
        "name": "Do Something",
        "type": "B",
        
    },
    {
        "name": "Do Something",
        "type": "C",
        
    },
]

Not all have the same type so will need to call upon different tests for their runs.

What is the best way to achieve this in Cypress? Is there a way that doesn't involve if/else blocks?

Questioner
Keva161
Viewed
0