Reputation: 534
I saw some similar post to mine but I didn't find it helpful at all since none of them are using the cypress preprocessor.
I have a Scenario:
Scenario: Some scenario
Given ...
When ...
Then I should see "<task_field>" field as "<field_value>"
Examples:
| task_field | field_value |
| some_field1 | some_value1 |
| some_field2 | some_value2 |
| some_field3 | some_value3 |
The .js file has:
Then('I should see {string} field as {string}', (field, value ) => {
switch (field) {
case 'some_field1':
cy.get('.someClass1').contains(value)
break
case 'some_field2':
cy.get('.someClass2').contains(value)
break
case 'some_field3':
cy.get('.someClass3').contains(value)
break
default:
throw new Error(`Invalid field: ${field}`)
}
})
My goal is to check each some_field if it equals to some_value, but currently cypress throws me an error and it's not even giving me the option to execute the test:
Any help would be appreciated Cheers!
Upvotes: 2
Views: 4282
Reputation: 534
After 2 hours of debugging I find out that I have forgotten to include Outline
world in the Scenario definition in order the test to be able to iterate through the data table.
So for future reference the fix from:
Scenario: Some scenario
Given ...
When ...
Then I should see "<task_field>" field as "<field_value>"
Examples:
| task_field | field_value |
| some_field1 | some_value1 |
| some_field2 | some_value2 |
| some_field3 | some_value3 |
Is to include in the first line Outline
:
Scenario Outline: Some scenario
Given ...
When ...
Then I should see "<task_field>" field as "<field_value>"
Examples:
| task_field | field_value |
| some_field1 | some_value1 |
| some_field2 | some_value2 |
| some_field3 | some_value3 |
I think is been a long day for me. Hope this helps to someone with a similar issue!
Upvotes: 7