03. Sharing Data

Jongsung·2022년 8월 5일
0

Cucumber BDD

목록 보기
3/3

I want to share information between step frequently. For this, I need to data available globally.

Lets see the scenario.

Feature: Display email

Scenario: Email should display when I logged in

   Given I create a random email
   When I login with the random email
   Then I should see the email in the page

I want to use random email variable created Given step on the When and Then steps. A random email is generated on the first step.
How can I use that on the next step to login?
I can store the value using "context".

context.<variable name> = <value>

Lets see the example.
.py

from behave import given, when, then

@given("I find recent order from database")
def find_order_from_db(context):
    print("Finding an order from the database...")
    context.order_num = '112233'

    print(f"Found an order. Order number: {context.order_num}")

@when("I issue a refund for the order")
def issue_refund(context):
    print(f"Trying to issue a refund for order number: {context.order_num}")

@then("Payment should get processed for the user")
def payment_should_process(context):
    print("Payment successfully processed")
    print(f"Payment is for refund of order number: {context.order_num}")

@when("I issue a refund on the same order")
def issue_repeat_refund(context):
    print(f"Trying to issue refund on same order: {context.order_num}")

@then("The refund should fail to process")
def refund_fails(context):
    print(f"The refund for order {context.order_num} should fail")

Result

profile
Software Engineer In Toronto

0개의 댓글