Behave - First Steps


Advertisements

Let us create a basic Behave test.

Feature File

The feature file for the Feature titled Payment Types is as follows −

Feature − Payment Types
   
   Scenario − Verify user has two payment options
      Given User is on Payment screen
      When User clicks on Payment types
      Then User should get Types Cheque and Cash

Corresponding Step Implementation File

The corresponding step implementation file for the above mentioned feature is as follows −

from behave import *
@given('User is on Payment screen')
def impl_bkpy(context):
      print('User is on Payment screen')
@when('User clicks on Payment types')
def impl_bkpy(context):
      print('User clicks on Payment types')
@then('User should get Types Cheque and Cash')
def impl_bkpy(context):
      print('User should get Types Cheque and Cash')

Project Structure

The project structure for the feature “Payment Types” is as follows −

Payment Types

Output

The output obtained after running the feature file is as mentioned below and the command used here is behave

Running the Feature File

The output shows the Feature and Scenario names, along with test results, and duration of test execution.

Python Console output is given below −

Python Console
Advertisements