Skip to main content

Behave Cucumber Matcher

Release version License Python versions Supported platforms Cucumber Ruff Code style: black Imports: isort Pipeline status

Behave step matcher for Cucumber Expressions.

Installation

behave-cucumber-matcher is available via PyPI:

pip install behave-cucumber-matcher

Usage

Import and specify the matcher inside environment.py of your features directory.

from behave.matchers import use_step_matcher
from behave_cucumber_matcher import CUCUMBER_EXPRESSIONS_MATCHER

# Specify to use the Cucumber Expressions step matcher
use_step_matcher(CUCUMBER_EXPRESSIONS_MATCHER)

Create a scenario inside color.feature of your features directory:

Feature: Color selection

  Rule: User can select a profile color

    Scenario: User selects a valid color
      Given I am on the profile settings page
      When I select the theme colour "red"
      Then the profile colour should be "red"

Create step definitions inside color.py of your features/steps directory:

from behave import given, then, when
from behave_cucumber_matcher import parameter_registry
from cucumber_expressions.parameter_type import ParameterType

# Define the parameter type
color = ParameterType(
    name="color",
    regexp="red|blue|yellow",
    type=str,
)

# Pass the parameter type to the registry instance
parameter_registry.define_parameter_type(color)

@given("I am on the profile customisation/settings page")
def step_given(context):
    assert True

# Reference the parameter type in the step definition pattern
@when('I select the theme colo(u)r "{color}"')
def step_when(context, selected_color):
    assert selected_color
    context.selected_color = selected_color

@then('the profile colo(u)r should be "{color}"')
def step_then(context, displayed_color):
    assert displayed_color
    assert context.selected_color == displayed_color

The necessary files are now in place to execute your gherkin scenario.

repository/
  └── features/
      ├── steps/
      │   └── color.py
      ├── environment.py
      └── color.feature

Finally, execute Behave. The scenario will run with the step definitions using the Cucumber Expressions parameter type.

$ behave
Feature: Color selection # features/color.feature:1
  Rule: User can select a profile color
  Scenario: User selects a valid color      # features/color.feature:5
    Given I am on the profile settings page # features/steps/color.py:20 0.000s
    When I select the theme colour "red"    # features/steps/color.py:26 0.000s
    Then the profile colour should be "red" # features/steps/color.py:32 0.000s

1 feature passed, 0 failed, 0 skipped
1 scenario passed, 0 failed, 0 skipped
3 steps passed, 0 failed, 0 skipped, 0 undefined
Took 0m0.001s

For detailed usage of behave, see the official documentation.

Acknowledgements

Based on the Behave step matcher base class and built on the architecture of cuke4behave by Dev 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, direct import of the matcher at package level rather than via its module, backwards compatibility with Cucumber Expressions missing parameter type defaults, and a global parameter type registry.

License

behave-cucumber-matcher is licensed under the MIT License

Metadata

Release files for behave-cucumber-matcher 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for behave-cucumber-matcher 0.4.0
File Size Uploaded
behave_cucumber_matcher-0.4.0.tar.gz 5.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for behave-cucumber-matcher 0.4.0
File Interpreter ABI Platform
behave_cucumber_matcher-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.1 kB

Release files / behave_cucumber_matcher-0.4.0.tar.gz

Download URL behave_cucumber_matcher-0.4.0.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b5e144974a059a57b1afb2b33649b4cc4c5364cd4a104d1f8098e7a36370c7a3
BLAKE2b-256 checksum
How to use checksums
dd78e3c733da718faf37bb242473f2597dd98e74fe21cdc267fce83c010658a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release files / behave_cucumber_matcher-0.4.0-py3-none-any.whl

Download URL behave_cucumber_matcher-0.4.0-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f478175ba9a23ceef15cbf522cc98684540595bbbf60312579ac6f38a1060166
BLAKE2b-256 checksum
How to use checksums
b42124f8b8ef1d02336a827653d12350251e04f656c81312832096b321dd8501
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page