Behave - First Steps



Let us create a basic Behave test.

Feature File - payment.feature

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 - stepImpPayment.py

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

(myenv) D:\behave\myenv\pythonProject>behave

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

Python Console output is given below −

USING RUNNER: behave.runner:Runner
Feature: Payment Types # features/payment.feature:1

    Then User should get Types Cheque and Cash   # features/steps/stepImpPayment.py:8 0.001s
    Then User should get Types Cheque and Cash   # features/steps/stepImpPayment.py:8
1 feature passed, 0 failed, 0 skipped
1 scenario passed, 0 failed, 0 skipped
3 steps passed, 0 failed, 0 skipped
Took 0min 0.001s
Advertisements