Skip to main content

Behave step matcher for Cucumber Expressions.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

behave_cucumber_matcher-0.4.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

behave_cucumber_matcher-0.4.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file behave_cucumber_matcher-0.4.0.tar.gz.

File metadata

File hashes

Hashes for behave_cucumber_matcher-0.4.0.tar.gz
Algorithm Hash digest
SHA256 b5e144974a059a57b1afb2b33649b4cc4c5364cd4a104d1f8098e7a36370c7a3
MD5 edd3af5a1112917436dd7c0e526a349c
BLAKE2b-256 dd78e3c733da718faf37bb242473f2597dd98e74fe21cdc267fce83c010658a0

See more details on using hashes here.

File details

Details for the file behave_cucumber_matcher-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for behave_cucumber_matcher-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f478175ba9a23ceef15cbf522cc98684540595bbbf60312579ac6f38a1060166
MD5 a14e2b305e6ea238c5d631a661d29248
BLAKE2b-256 b42124f8b8ef1d02336a827653d12350251e04f656c81312832096b321dd8501

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page