A custom parameter type lets a step definition accept meaningful, domain-specific text and receive a converted value or object. A regular expression identifies the text to match; a parameter method transforms it. This can make step expressions clearer and the conversions reusable. section 8.4.3
Listing 8.7 A parameter type definition
@ParameterType("(Standard|Silver|Bronze|Gold) Frequent Flyer member") #1
public FrequentFlyerMember frequentFlyer(String statusName) {
FrequentFlyerStatus status = FrequentFlyerStatus.valueOf(statusName); #2
return FrequentFlyerMember.withStatus(status); #3
}
This definition matches frequent-flyer member descriptions and converts the status into a FrequentFlyerMember object. section 8.4.3
A parameter type can also match a specific date format and convert it to a LocalDate. In Cucumber.js, custom types can resolve actor names or pronouns into Screenplay actors. section 8.4.3 section 14.3
import { defineParameterType } from '@cucumber/cucumber'
import { actorCalled, actorInTheSpotlight } from '@serenity-js/core'
defineParameterType({
name: 'actor',
regexp: /[A-Z][a-z]+/,
transformer: (name: string) => actorCalled(name)
})
defineParameterType({
name: 'pronoun',
regexp: /he|she|they|his|her|their/,
transformer: () => actorInTheSpotlight()
})
These Cucumber.js definitions convert actor names and pronouns into Serenity/JS actor objects. section 14.3
