02. Passing Parameters

Jongsung·2022년 8월 5일
0

Cucumber BDD

목록 보기
2/3

Sometimes, I want to use different languages based on the test cases such as 'English', 'French', and 'Korean',
Lets see below step definition.

Given I go to the 'English' version of the site
Given I go to the 'French' version of the site
Given I go to the 'Korean' version of the site

How do I wirte differently?
I can define the step like this:

@Given("I go to the '{language}' version of the site)
def go_to_site(context, language):
    <code>

Lets see the example:

.feature

Feature: Passing parameters to steps

  Scenario: method 1 of passing step parameters
    Given I have a new 'DVD' in my cart
    And I have a new 'BOOK' in my cart
    When I click on 'Next'
    And I click on 'Finish'
    Then I should see 'success'

.py

from behave import given, when, then

@given("I have a new '{item}' in my cart")
def i_have_item_in_cart(context, item):
   print(f"The item is: {item}")

@when("I click on '{button}'")
def click_button(context, button):
    print(f"I am clicking the button: {button}")

@then("I should see '{txt}'")
def i_should_see_text(context, txt):
    if txt not in ['success', 'error']:
        raise Exception("Unexpected test passed in.")

    print(f"Checking if I see the {txt} text")
    print(f"PASS. I see the {txt}")

Result

profile
Software Engineer In Toronto

0개의 댓글