The Cucumber framework is the BDD frameworks. Cucumber is a testing framework that supports Behavior Driven Development(BDD). It is written by English text called Gherkin.
It consists of two parts.
Step
- Steps file is located in features file(.feature)
- Given / When / Then
1) Given
- Used for precondition
- Set up actions
- No interaction2) When
- Interaction with the application
- Act on something3) Then
- Verification
- ExpectationStep Definition
- Located in Python files(.py)
The Below ficture is file structure.
Feature: Demo of displaying output on console
Scenario: A test that will PASS (stdout demo)
Given I am at the home page
When I click on 'contact us'
Then I should see 123 Testing St.
Scenario: A test that will FAIL (stdout demo)
Given I am at the home page
When I click on my account
Then I should see 'Preferences'
from behave import given, when, then
import logging as logger
@given("I am at the home page")
def at_home_page(context):
print("I am the code that will open browser")
logger.info("I am 1 INFO")
@when("I click on 'contact us'")
def click_contact_us(context):
print('I am aclicking on the "contact us"')
logger.info("I am 2 INFO")
@then("I should see 123 Testing St.")
def verify_address(context):
print("I see the correct address")
By default Behave does not print the standart output in the console for tests that pass. Standard outputs are ‘logging’ statements or ‘print’ statements
To force printing use command line argument : —no-capture. If test fail, all the logging for the failed test will show.