vendredi 2 février 2018

Run tests on dynamic file in cypress.io

I am trying to use cypress to test a large angular app that I have built. My requirement is that I load an expecation file into my test and then drive the test off this expecation file. I have so far been unable to get this to work using various combinations of cy.readFile(), cy.fixture(), and even axios to load the file via http. The issue seems to be that I can't use these methods outside of it() and if I can't do that it means I can loop through the data to create the its. I am trying to do something like the below... is this even possible in cypress?

describe(`Test the app `, function() {
    cy.readFile("path/to/expectation.js").then(function(expectation) {
        Object.keys(expectation).forEach(function(pageName) {
            it(`for page ${pageName}`, function() {
                gotoPage(pageName);
                var pageData = getDataFrompage();
                expect(pageData).to.equal(expectation[pageName]);
            })
        })
    })
})

Aucun commentaire:

Enregistrer un commentaire