如何编写场景大纲来捕获单个参数中的对象列表?

时间:2016-03-20 06:56:20

标签: cucumber cucumber-jvm gherkin

在编写黄瓜场景大纲测试用例时,有时我要求我需要一个占位符来保存数据列表而不是一个。见下面的伪示例:

Scenario Outline: example
Given I have <input_1> 
When I choose <input_2>
Then I should receive <result_list>  //instead of a single result

Examples:
| input_1        | input_2        | result                 |
| input_1_case_1 | input_2_case_1 | result_1_case_1_part_1 |
|                |                | result_1_case_1_part_2 |
|                |                | result_1_case_1_part_3 |

在上面的示例中,我的“结果”需要捕获每个input_1和input_2参数的对象列表。但是通过上面的写作,黄瓜不会将最后一个语句编译成类似的东西:

@Then("....")
public void i_should_receive(Datatable or list of object) throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

如何写我的黄瓜脚本来达到我想要的效果?

感谢。

2 个答案:

答案 0 :(得分:2)

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Const DESIRED_ADDRESS As String = "A:A, C:C, E:E"
    Dim desired As Range

    IntelliSense.Hide

    'Check if just one cell has been selected
    If Target.Cells.Count = 1 Then
        'Check if target cell is one that we want
        Set desired = Me.Range(DESIRED_ADDRESS)
        If Not Intersect(Target, desired) Is Nothing Then
            'Check that target cell is blank
            If Len(Target.Value) = 0 Then
                'All criteria met so show 'IntelliSense'
                IntelliSense.Show False
            End If
        End If
    End If

End Sub

然后在您的步骤定义中

Scenario Outline: example
Given I have <input_1> 
When I choose <input_2>
Then I should receive <result_list>  //instead of a single result

Examples:
| input_1        | input_2        | result                                                                
| input_1_case_1 | input_2_case_1 | result_1_case_1_part_1,result_1_case_1_part_2,result_1_case_1_part_3 |

答案 1 :(得分:0)

我已经能够在黄瓜示例中设置值列表,这样:

Scenario Outline: The role already exists in the system, with the specified permissions
    Given the user admin is logged in
    And the role ADMIN with permissions <permissions> to be created
    When a call to SecurityService is performed to create system roles
    Then http status code 200 is returned
    Examples:
      |permissions                                       |
      |REGISTER_ACCOUNT,REVOKE_TOKENS,GET_ROLES,SET_ROLES|

具体方法:

 @And("^the role ([^\"]*) with permissions ([^\"]*) to be created$")
 public void theRoleWithPermissionsToBeCreated(String roleCode, List<String> permissions) {

对我来说,这就像一个魅力,我直接收到一个字符串列表,而不需要解析一个字符串值