0

Here is my feature file

Scenario Outline: Test different value for same parameter
 Examples:
 | app     | app1     |
 | instagram| facebook |

Given <app> is installed on my device
And <app1> is installed on my device
@given("<app> is installed on my device")
def app_installation(app):
    install_app(app)

As of now, i cannot use app2 value with same step and i have to duplicate app_installation with app1 parameter

Is there a way that i can use any parameter in Example which value can be mapped to app

Raj
  • 165
  • 1
  • 2
  • 11
  • Going by your sample, do you want to have 1 scenario where instagram AND facebook (AND whatsapp AND etc. for example) are all installed before continuing to the next step? – 0buz Sep 14 '20 at 11:47
  • Yes, i want to test something which requires both to be installed – Raj Sep 15 '20 at 02:11

1 Answers1

1

Since pytest-bdd is reading your examples table and creates a fixture for every table entry you can load the table data dynamically. This can be done by passing the header name of the examples table column instead of the value and then using the pytest request fixture to retrieve the actual table value.

Scenario Outline: Test different value for same parameter
 Examples:
 | app     | app1     |
 | instagram| facebook |

Given app is installed on my device
And app1 is installed on my device
# IMPORTANT:
#    The step is parsed by `parsers.parse` and not by using
#    `<>`, therefore in the `app` variable will be the column
#    name (app, app1, app2, ...) of the examples table instead
#    of the actual value (instagram, facebook, ...).
@given(parsers.parse("Given {app} is installed on my device"))
def app_installed(request, app):
    app_to_install = request.getfixturevalue(app)
    # Install app ...

Note: You can use <app> in your feature file as well, but then you have to remove the angle brackets in the @given step before calling request.getfixturevalue(app)

mattefrank
  • 231
  • 1
  • 9