Index
- Converters
1.1 Implementation
- Running Tests
2.1 Running tests by Tag
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"
@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
- This guide was created based on the course “Behavior Driven Python with pytest-bdd” by Andrew Knight.
- Course available at “Testing Automation University”.