01. BDD Component

Jongsung·2022년 8월 2일
0

Cucumber BDD

목록 보기
1/3

1. What is Cucumber BDD Framework?

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.

2. Cucumber Consists

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 interaction

    2) When
    - Interaction with the application
    - Act on something

    3) Then
    - Verification
    - Expectation

Step Definition

  • Located in Python files(.py)

The Below ficture is file structure.

3. feature file contains

The feature name

  • One line starting with keyword ‘Feature:’

The scenario name(test case name)

  • One line starting with keyword ‘Scenario:’
  • You Can have multiple scenario in single feature file

The steps

  • One or multiple lines starting with keywords:
    Given, When, Then, And, But
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'

4. Step definition file Contains

  • Step definitions go under ‘steps’ directory
  • Python functions which are definition for the steps
  • Must start with @given, @when, @then
  • This file also contains all the imports
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")

5. Displaying Output

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.

profile
Software Engineer In Toronto

0개의 댓글