Search code examples
javascripttestingcucumbercypress

Cypress Cucumber Step running multiple steps


Lets say I have

Step1

Step2

Step3

Is it possible to have Step4 which runs all 3 of them?


Updated what I mean is

I already wrote 3 steps

Given('do step1', function () {})

Given('do step2', function () {})

Given('do step3', function () {})

Is it possible to have

Given('do step4', function () {
    do step1
    do step2
    do step3
})

Solution

  • If you write those 3 steps as individual functions you'll be able to achieve the same effect as what you're looking for:

    login(user, pass){
       cy.visit(loginUrl)
       cy.get('#username').type(user)
       cy.get('#password').type(pass)
       return cy.contains('Submit').click()
    }
    
    stepTwo(){
       ... // Other stuff
    }
    
    stepThree(){
       ... // More stuff
    }
    
    Given('I log in as {string} with password {string}', function (username, password) {
       return login(username, password)
    })
    
    Given('some set up step', function () {
       login('[email protected]', 'bodacious')
       return stepTwo()
    })
    
    Given('another set up step', function () {
       login('[email protected]', 'triumphant')
       stepTwo()
       return stepThree()
    })