如何将示例表添加到黄瓜功能文件中的背景?

时间:2015-02-27 14:19:59

标签: cucumber

我想在黄瓜功能文件的后台步骤中添加一个示例表。我该怎么做呢?

我想做这样的事情:

Background:
Given <username> has logged in

Examples:
|username|
|User 1  |
|User 2  |

Scenario: .....

3 个答案:

答案 0 :(得分:3)

这对你有帮助..

Feature: Passing background with multiline args 

Background: 
Given table |a|b| 
|c|d|
And multiline string """ I'm a cucumber
and I'm okay. I sleep all night and I test all day """

Scenario: passing background

Then the table should be 
|a|b| 
|c|d| 

Then the multiline string should be """ I'm a cucumber and I'm okay. I sleep all night and I test all day 

""" Scenario: another passing background 

Then the table should be |a|b| |c|d| 

Then the multiline string should be """ I'm a cucumber and I'm okay. I sleep all night and I test all day

有关更多方案,请参阅此链接..

https://www.relishapp.com/cucumber/cucumber/docs/gherkin/background

答案 1 :(得分:2)

不幸的是,这是不可能的。

黄瓜docs

答案 2 :(得分:0)

也许这可以帮助您:

Background:
    Given Login with email myemail@mail.com and pass myPass

Scenario Outline:Scenario 1

Examples:
  | thing1| thing2 | thing3 |
  | fdlsk | fadsff | faskld |

在您的stepdef中使用它:

@Then("^Login Login with email ([^\"]*) and pass ([^\"]*)$")
    public void login_general(String email, String pass) {
            login.fillEmail(email);
            login.fillPass(pass);
            login.clickLogin();
    }