简体   繁体   中英

Cypress - How to restrict a constant value?

I am loading a fixture via constant (there are some reasons why I am not using cy.fixture) . I loop through a group of users - Cypress._.range(3, 19).

        import users from '../../../fixtures/users.json';
        describe('Emergency Code', () => {

        Cypress._.range(3, 19).forEach((k) => {
        const user = users[k]


            it('Should generate Emergency Code for ' + user.Product_Code, function () {

                cy.userAssginDongle(user);
                cy.get('.col-md-12 > .row > .col-md-12 > #sideButtonGroup > .btn:nth-child(2)').click();
                cy.get('.modal-content > .modal-body > .row > .col-md-12 > #copyInput').click();
                cy.get('.modal-content > .modal-body > .row > .col-md-12 >     #copyInput').invoke('val').should('not.be.empty')

            })


        })
        })

In users.json there is a field that defines Emergency Code as Yes or No. "Emergency_Code": "Yes", "Emergency_Code": "No",

How do I start this test restricting the Fixture JSON data based on this field? Something like if Emergency is yes: load the user into the test, if it's no, do not load if it's something else do not load.

If the user doesn't meet the condition skip that iteration:

Cypress._.range(3, 19).forEach((k) => {
        const user = users[k]
        if (user['Emergency_Code'] === 'No') {
          return
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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