English 中文(简体)
Behave - Scenario Outlines
  • 时间:2024-12-22

Behave - Scenario Outpnes


Previous Page Next Page  

A Scenario Outpne is used if we have a group of similar criteria and the results are to be passed in a Scenario. A Scenario Outpne is accompanied with an Examples table. A Scenario Outpne can have multiple Examples tables.

The tests get executed once for every row found (after the header row) within the Examples table. The values to be tested are represented by their names enclosed in brackets<>. These names should match with the Examples table header.

It helps to reduce the pnes of code (epminates repeating steps) and orders our tests.

Feature File

The feature file for scenario outpne is as follows −


Feature − User information
Scenario Outpne: Check login functionapty
   Given user enters "<name>" and "<password>"
   Then user should be logged in
   Examples: Credentials
      | name   | password |
      | user1  | pwd1     |
      | user2  | pwd2     |

Please Note: We have kept the name and password parameters enclosed in "<>". These parameters are column headers provided below the Examples section. In the step implementation, we shall pass the parameters enclosed in "{}".

Also, these parameters need to be passed as arguments to the implementation method.

Corresponding Step Implementation File

The corresponding step implementation file is as follows −


from behave import *
@given( user enters "{name}" and "{password}" )
def step_implpy(context, name, password):
      print("Username for login: {}".format(name))
         print("Password for login: {}".format(password))
@then( user should be logged in )
def step_implpy(context):
      pass

Output

The output is obtained after running the feature file and the command used is behave --no-capture -f plain.

Scenario Outpnes

The output shows Username for login: user1, Password for login: pwd1 and Username for login: user2, Password for login: pwd2 printed. Here, the two data sets were passed from the Examples.

Advertisements