Package: behave-cucumber-matcher
Behave Cucumber MatcherBehave step matcher forCucumber Expressions.Installationbehave-cucumber-matcheris available viaPyPI:pip install behave-cucumber-matcherUsageImport and patch the matcher into Behave insideenvironment.pyin yourfeaturesdirectory.frombehave.matchersimportuse_step_matcher,matcher_mappingfrombehave_cucumber_matcherimportbuild_step_matcherfromcucumber_expressions.parameter_type_registryimportParameterTypeRegistry# Initialise a Cucumber Expressions parameter registryparameter_registry=ParameterTypeRegistry()# Create the step matcher to pass to behavestep_matcher=build_step_matcher(parameter_registry)# Patch the step matcher into behavematcher_mapping["cucumber_expressions"]=step_matcher# Specify to use the Cucumber Expressions step matcheruse_step_matcher("cucumber_expressions")Create a scenario insidecolor.featurein yourfeaturesdirectory:Feature:Color selectionRule: User can select a profile colorScenario:User selects a valid colorGivenI am on the profile settings pageWhenI select the theme colour "red"Thenthe profile colour should be "red"Create step definitions insidecolor.pyin yourfeatures/stepsdirectory:frombehaveimportgiven,then,whenfromcucumber_expressions.parameter_typeimportParameterTypefromenvironmentimportparameter_registry# Define the parameter typecolor=ParameterType(name="color",regexp="red|blue|yellow",type=str,transformer=lambdas:s,use_for_snippets=True,prefer_for_regexp_match=False,)# Pass the parameter type to the registry instanceparameter_registry.define_parameter_type(color)@given("I am on the profile customisation/settings page")defstep_given(context):assertTrue# Reference the parameter type in the step definition pattern@when('I select the theme colo(u)r "{color}"')defstep_when(context,selected_color):assertselected_colorcontext.selected_color=selected_color@then('the profile colo(u)r should be "{color}"')defstep_then(context,displayed_color):assertdisplayed_colorassertcontext.selected_color==displayed_colorThe necessary files are now in place to execute your gherkin scenario.repository/└── features/├── steps/│   └── color.py├── environment.py└── color.featureFinally, execute Behave. The scenario will run with the step definitions using the Cucumber Expressions parameter type.$behavefeaturesFeature: Color selection # features/Gherkin.feature:1Rule: User can select a profile colorScenario: User selects a valid color      # features/Gherkin.feature:5Given I am on the profile settings page # features/steps/color.py:20 0.000sWhen I select the theme colour "red"    # features/steps/color.py:26 0.000sThen the profile colour should be "red" # features/steps/color.py:32 0.000s1 feature passed, 0 failed, 0 skipped1 scenario passed, 0 failed, 0 skipped3 steps passed, 0 failed, 0 skipped, 0 undefinedTook 0m0.001sFor detailed usage ofbehave, see theofficial documentation.AcknowledgementsBased on the Behave step matcher base class and built on the architecture ofcuke4behavebyDev Kumar Gupta, with extended type hints, a fix for detecting patterns without arguments, a default parameter type registry, additional documentation for arguments and return types and direct import of the matcher at package level rather than via its module.Licensebehave-cucumber-matcheris licensed under theMIT License