Converters with Pytest-BDD


Index

  1. Converters
    1.1 Implementation
  1. Running Tests
    2.1 Running tests by Tag
  1. Repository
  1. Thanks
  1. Bibliography


1. Converters

Converters are used by the step_definition functions so that the functions can accept other argument types than strings.

The converters can turn the arguments into “float”, “int” and “str” types, for example:

  • Float Type.
@when(parsers.parse('the user searches for "{text}"'), converters={"text": float})
def search_phrase(browser, text):
  • Int Type.
@when(parsers.parse('the user searches for "{text}"'), converters={"text": int})
def search_phrase(browser, text):


1.1 Implementation

web.feature”:

    @basic-search
    Scenario: Basic DuckDuckGo Result Title
        When the user searches for "123"
        Then results title contains "123"

test_web_steps.py”:

@when(parsers.parse('the user searches for "{text}"'), converters={"text": str})
def search_phrase(browser, text):
    DuckDuckGoSearchPage(browser).search(text)


2. Running Tests


2.1 Running tests by Tag

Run the command below to test only the scenario where the converter was implemented.

pipenv run python -m pytest -k "basic-search and not independence-search"


3. Repository

If you want to run the test above, clone the project from the link below and run the commands in the project root.
https://github.com/LuizGustavoR/intro-selenium-py/tree/tutorial/converters

The end.


4. Thanks


5. Bibliography

Leave a Comment

Your email address will not be published. Required fields are marked *