admin管理员组

文章数量:1391766

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!

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!

Share Improve this question edited Aug 5, 2020 at 18:32 antpngl92 asked Aug 5, 2020 at 17:58 antpngl92antpngl92 5344 silver badges14 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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!

本文标签: javascriptcypresscucumberpreprocessor DatatablesStack Overflow