Closed jakoivis closed 5 years ago
Hi @jakoivis,
The current implementation is different. If you want to get the value of the variables, you will have to but them into the step that you are targeting:
Feature: Awesome feature
Scenario Outline: Flying to an airport
Given <airpoirt> is at (<lat>,<lon>)
When I fly to the airport <airport>
Then I'm at (<lat>, <log>)
Examples:
| airport | lat | lon |
| KMSY | 29.993333 | -90.258056 |
| KSFO | 37.618889 | -122.375000 |
| KSEA | 47.448889 | -122.309444 |
| KJFK | 40.639722 | -73.778889 |
The package will internally create 4 tests (one for each example) as if you created them manually. The above example will interally be represented as something like this:
Feature: Awesome feature
Scenario: Flying to an airport
Given KMSY is at (29.993333,-90.258056)
When I fly to the airport KMSY
Then I'm at (29.993333,-90.258056)
Scenario: Flying to an airport
Given KSFO is at (37.618889,-122.375000)
When I fly to the airport KSFO
Then I'm at (37.618889,-122.375000)
# ...
Note that all the tests have the same name. If you do not want to have this, you can use the variables in the scenario's name aswell.
Then you can access it like you would if you created them manually:
const { Given, When, Then } = require('cucumber');
Given(/^([A-Z]+) is at \((-?\d*.\d+),(-?\d*.\d+)\)$/, async (t, airportCode, latitude, longitude) => {
// stuff
});
When(/^I fly to the airport ([A-Z]+)$/, async (t, airportCode) => {
// more stuff
});
Then(/^I'm at \((-?\d*.\d+),(-?\d*.\d+)\)$/, async (t, latitude, longitude) => {
// even more stuff
});
I think we should definitely add an example for this.
That's good the hear that the scenario outline is working and it could be documented as well. But that isn't quite what I needed. I tested to create only a data table since I understood that the use cases for scenario outline and data table are different. I checked from the source code that the gherkin Compiler creates pretty much this information already but it only needs to be passed for the test case.
Oh, I wasn't even aware that something like this existed.
Then you are right. This is a feature that might get added in the future.
Just for the record, the cucumber documentation for data tables.
I would love to see this implemented :)
How you getting on @jvdieten?
Fixed in version 2.2.0
e.g. Given what ever: | | lat | lon | | KMSY | 29.993333 | -90.258056 | | KSFO | 37.618889 | -122.375000 | | KSEA | 47.448889 | -122.309444 | | KJFK | 40.639722 | -73.778889 |
The data table should be passed to the step definition as the last argument. Currently it is undefined.