Search code examples
cucumbercucumberjs

Is there any way to specify eg (car|cars) in a cucumber step definition?


So I have 2 scenarios....one starts out

Given I have 1 car

The other starts out

Given I have 2 cars

I'd like them to use the same step definition - ie something like this

 Given('I have {int} (car|cars)',

I know it's possible to do specify 2 possible values (ie car or cars), but I can't for the life of me remember how. Does anyone know? I'm using typescript, protractor, angular, selenium.

Have also tried

Given(/^I have {int} (car|cars)$

Solution

  • Within cukeExp, the () become optional characters. That is what you want.

    So your expression would be

    Given('I have {int} car(s)')
    

    Happy to help - More information can be found here: https://cucumber.io/docs/cucumber/cucumber-expressions/ - Switch to JS code at the top.

    Luke - Cucumber contributor.