2017-10-10 45 views
0

步驟之間傳遞參數我有多個示例場景輪廓看起來像這樣:中的行爲

Examples: 
| country  |  type  | number | 
| Poland   | An individual |  -  | 
| Poland   | Company  | 8971660890 | 
| Germany   | An individual |  -  | 
| France   | Company  | 92511490856 | 

我想用這個例子,並把它傳遞給步驟定義之一,以創建條件表達式,例如:

@step(check_sth) 
def step_imp(country, type, number): 
if county == Poland: 
    do sth 
elif type == individual: 
    do other thing 

是否有可能在bahave?

回答

1

請參閱如何做到這一點的行爲教程:https://pythonhosted.org/behave/tutorial.html

特別是,看看如何建立場景輪廓,如:

Given I enter the following data <country> <type> and <number>, 
    Then check that <country> is correct 

會給你下面的步驟定義:

@given('I enter the following data "{country}" "{type}" and "{number}",') 
    def step_impl(context, country, type, number): 

    @then('check that "{country}" is correct') 
    def step_impl(context, country): 
+0

但是我可以在不同的步驟中使用國家,類型和編號嗎?我有步驟:'「{type}」被選中「並且」{country}「被選中',我想在另一個步驟中使用country和type。 – Ewa

+0

是的,您可以在相同的場景中重複使用它們。只需使用相同的參數定義另一個步驟。 –