1

I have the following step: User creats something using the following input:

|Key|value|
|Key|value|

Meaning duplicate values are being passed to step. So I thought I should use list<Map<String,String>> in the step definition but it is being passed as (key=key, value=value)

Could you please help me on how should I reserve this issue?

yassadi
  • 524
  • 1
  • 9
  • 20
user35253
  • 143
  • 1
  • 8
  • Do you want the user to be able to do something like this? , , – yassadi Apr 11 '18 at 03:15
  • Yes, but key-value pair may be duplicate and I want cucumber to pass every entry to step definition. When i make the data table as List> then the data table is being stored as (key=key, value=value) not as (key=value, key=value), could you please help me here how should I store it? – user35253 Apr 11 '18 at 03:38
  • Is this your question? https://stackoverflow.com/questions/1062960/map-implementation-with-duplicate-keys – yassadi Apr 11 '18 at 03:59
  • I can do whatever written in the link above, but the problem is cucumber only converts the data table to Map, list where k and v should be Integer, String , Boolean or Float. – user35253 Apr 11 '18 at 04:12
  • you can try [gerkin using qaf](https://qmetry.github.io/qaf/latest/gherkin_client.html). Refer different [examples](https://github.com/qmetry/qaf/blob/master/test/src/com/qmetry/qaf/automation/impl/step/qaf/QAFTestStepImpl.java#L82) of step implementation and [exampe usage](https://github.com/qmetry/qaf/blob/master/test/resources/features/gherkin_datatable.feature) – user861594 Apr 14 '18 at 19:17

1 Answers1

0

Assuming following feature file

Feature: demo for a key,value data table
  Scenario: duplicate data for a scenario
    When some condition is true
    Then enter a valid data pair
        |Key    |value|
        |Key    |value|
        |SomeKey|SomeValue|

and you want to execute the scenario for all listed rows, regardless the duplicated row Key,value.

The step can be implemented using a DataTable parameter

public void enterAValidDataPair(DataTable dataTable) throws Exception {
    System.out.println("dataTable.raw().size() = " + dataTable.raw().size());
    for (List<String> row : dataTable.raw()) {
        System.out.printf("key: %-10s value: %-10s%n", row.get(0), row.get(1));
    }
}

if you run the scenario the method produces following output

dataTable.raw().size() = 3
key: Key        value: value     
key: Key        value: value     
key: SomeKey    value: SomeValue 
SubOptimal
  • 22,518
  • 3
  • 53
  • 69