Is there a way to use Then steps for When definitions with pytest-bdd?
Example,
I have the step in my scenario
Then User downloads the file "test_file.txt"
But my definitions is
@when(parsers.parse('User downloads the file "{file_name}"'))
def step_user_downloads_file(bdd_context, file_name):
pass
There is the error about step is not found. I have scenarios where same step is used with "When" keyword. I would like to use with both. But more globally, i would like to use any step definitions with any of keywords When/Then/Given/And . is it possible?
Is there a way to use Then steps for When definitions with pytest-bdd?
Example,
I have the step in my scenario
Then User downloads the file "test_file.txt"
But my definitions is
@when(parsers.parse('User downloads the file "{file_name}"'))
def step_user_downloads_file(bdd_context, file_name):
pass
There is the error about step is not found. I have scenarios where same step is used with "When" keyword. I would like to use with both. But more globally, i would like to use any step definitions with any of keywords When/Then/Given/And . is it possible?
Unfortunately, there are no pytest annotations that allow you to bind a step definition to any keyword. It would be pretty neat if there was an annotation like @step(parsers.parse(...)) that would allow you to use that step with Given, When, or Then. However, there are still several workarounds that can get the job done for your example:
* User downloads the file "test_file.txt"
@given(parsers.parse('User downloads the file "{file_name}"'))
@when(parsers.parse('User downloads the file "{file_name}"'))
@then(parsers.parse('User downloads the file "{file_name}"'))
def step_user_downloads_file(bdd_context, file_name):
pass