Tyler-Keith-Thompson / CucumberSwift

A lightweight swift Cucumber implementation
https://tyler-keith-thompson.github.io/CucumberSwift/documentation/cucumberswift/
MIT License
74 stars 19 forks source link

Data Table does not substitute parameter from Example in Scenario Outline #53

Closed fwpascual closed 1 year ago

fwpascual commented 1 year ago

Describe the bug When using a Scenario Outline and a step that uses a Data Table, the parameter in the Example is not substituted for the row entry in the data table.

To Reproduce Steps to reproduce the behavior:

  1. Add a step definition:

    Then("^I have a sample step with a=(\\d+),b=(\\d+)$") { matches, step in
    print("Match A = \(matches[1])")
    print("Match B = \(matches[2])")
    
    let dataTable = step.dataTable!
    for (rowIndex, row) in dataTable.rows.enumerated() {
        for (columnIndex, column) in row.enumerated() {
            print("Row[\(rowIndex)][\(columnIndex)] = \(column)")
        }
    }
    }
  2. Add a scenario outline such as:

    Scenario Outline: Sample scenario
    Then I have a sample step with a=<paramA>,b=<paramB>
        | a        | b        |
        | <paramA> | <paramB> |
    
    Examples:
        | paramA | paramB |
        | 0      | 1      |
        | 5      | 10     |

Expected behavior For the second example, I expected an output like:

Match A = 5
Match B = 10
Row[0][0] = a
Row[0][1] = b
Row[1][0] = 5
Row[1][1] = 10

but instead received an output like:

Match A = 5
Match B = 10
Row[0][0] = a
Row[0][1] = b
Row[1][0] = <paramA>
Row[1][1] = <paramB>

Screenshots N/A

Additional context Add any other context about the problem here.

Feature: Sample

Scenario Outline: Sample scenario
    Then I have a sample step with a=<paramA>,b=<paramB>
        | a        | b        |
        | <paramA> | <paramB> |

    Examples:
        | paramA | paramB |
        | 0      | 1      |
        | 5      | 10     |
Tyler-Keith-Thompson commented 1 year ago

Thanks for calling this out! I need to take a closer look at the cucumber spec for expected behavior and try to wrap my head around your example. It's been a while since I touched the datatable code.

Can you explain why you expected the output to be:

Row[0][0] = a
Row[0][1] = b
Row[1][0] = 5
Row[1][1] = 10

Instead of:

Row[0][0] = a
Row[0][1] = b
Row[1][0] = 0
Row[1][1] = 1

Is it that you expect the datatable attached to the then step to line up with the row in examples? So given that you have <paramA> | <paramB> on row 2, it'll read from row 2 in examples?

fwpascual commented 1 year ago

For what it's worth, in my experience using the cucumber-jvm library, I've been able to use Example parameters in Data Table entries. However, I can't speak towards what the spec says.

Sorry for the confusion, I probably should have included the full output. The one I provided was only for the second example index. It's probably more accurate if Row was DataTable in the output too, but I'll leave it for now.

// First Example (where paramA=0, paramB=1 in the Examples table)
Match A = 0
Match B = 1
Row[0][0] = a
Row[0][1] = b
Row[1][0] = 0
Row[1][1] = 1

// Second Example (where paramA=5, paramB=10 in the Examples table)
Match A = 5
Match B = 10
Row[0][0] = a
Row[0][1] = b
Row[1][0] = 5
Row[1][1] = 10

My expectation is that for every scenario run, for steps with a DataTable, if there are cells in the DataTable that reference a param, they get string replaced with the matching entry from the currently executing Examples table row.

Tyler-Keith-Thompson commented 1 year ago

Ahha! I'm totally tracking now. The params were being replaced in the step, but not in the datatable. Seems like the library is only partially meeting expectations. Okay great! I'll get a test case in place and work on this as I have time (with a little luck, I can work on it this weekend)

Tyler-Keith-Thompson commented 1 year ago

This is fixed but for some reason I'm having deployment issues. If you need an immediate workaround point your package manager to the main branch, rather than a specific version.

I'll try and get the deployment issues fixed up ASAP

Tyler-Keith-Thompson commented 1 year ago

Alright, this is good to go in CucumberSwift v3.3.22

fwpascual commented 1 year ago

Awesome, thanks so much for addressing this so quickly!