TheBrainFamily / cypress-cucumber-example

Example of using Cypress with Cucumber
MIT License
195 stars 120 forks source link

Writing Cucumber scenario including datable #1

Closed wawagit closed 6 years ago

wawagit commented 6 years ago

Before everything, thank you Łukasz for your work! It's amazing 🥇

I was just wondering if I could use scenario including a Datatable, like this for example:

The scenario

Scenario: Writing scenario with datatable
    Given a table step
      | Cucumber     | Cucumis sativus |
      | Burr Gherkin | Cucumis anguria |

The step definition

given(`a table step`, function(table) {
    const expected = [
        ['Cucumber', 'Cucumis sativus'],
        ['Burr Gherkin', 'Cucumis anguria']
    ]
    assert.deepEqual(table, expected)
})

But when I do that Cypress displays an AssertionError :

expected undefined to deeply equal [ Array(2) ]

table seems to be undefined. Did I do something wrong?

lgandecki commented 6 years ago

Thank you :-)

This is fixed in the newest version of https://github.com/TheBrainFamily/cypress-cucumber-preprocessor by @fcurella , you can see an example here:

https://github.com/TheBrainFamily/cypress-cucumber-preprocessor/blob/master/cypress/integration/Plugin.feature

https://github.com/TheBrainFamily/cypress-cucumber-preprocessor/blob/master/cypress/support/step_definitions/dataTable.js

lgandecki commented 6 years ago

( if you have more questions/issues related to the plugin please open an issue in the other repo :-) let's keep this one for the example purpose - which I think at this point is not even necessary, with CI and tests in the plugin repo itself )

JimLynchCodes commented 4 years ago

@lgandecki I don't see any data table in the links you've provided. 🤔

Did you mean to link to this? https://github.com/TheBrainFamily/cypress-cucumber-preprocessor/blob/master/cypress/integration/DataTable.feature

When I try to use this though it doesn't work.

My feature file:

Feature: Being a plugin handling Scenario Outline

    As a cucumber cypress plugin which handles Scenario Outline
    I want to allow people to write Scenario Outline tests and run it in cypress

    Scenario Outline: Using Scenario Outlines
        When I add <provided number> and <another provided number>
        Then I verify that the result is equal the <provided>

        Examples:
            | provided number | another provided number | provided |
            | 1               | 2                       | 3        |
            | 100             | 200                     | 300      |

Steps:

import { When } from "cypress-cucumber-preprocessor/steps";

export let data = ''

When(`I add {int} and {int}`, async (int1, int2) => {

    console.log('ok when ', int1, ' ', int2)

})
import { Then } from "cypress-cucumber-preprocessor/steps";

Then(`I verify that the result is equal the {int}`, async (int3) => {

    console.log('then ', int3)

})

Results in Error: "Timed out retrying: Expected to find element: table, but never found it."

JimLynchCodes commented 4 years ago

It would be nice if there was any mention of this at all in the README...

lgandecki commented 4 years ago

That error seems unrelated. The feature file you found is run on CI on every commit and merge to make sure that functionality works. You can find step definitons of that .feature file as well in the same repo

justfathi commented 4 years ago

@lgandecki I don't see any data table in the links you've provided. 🤔

Did you mean to link to this? https://github.com/TheBrainFamily/cypress-cucumber-preprocessor/blob/master/cypress/integration/DataTable.feature

When I try to use this though it doesn't work.

My feature file:

Feature: Being a plugin handling Scenario Outline

    As a cucumber cypress plugin which handles Scenario Outline
    I want to allow people to write Scenario Outline tests and run it in cypress

    Scenario Outline: Using Scenario Outlines
        When I add <provided number> and <another provided number>
        Then I verify that the result is equal the <provided>

        Examples:
            | provided number | another provided number | provided |
            | 1               | 2                       | 3        |
            | 100             | 200                     | 300      |

Steps:

import { When } from "cypress-cucumber-preprocessor/steps";

export let data = ''

When(`I add {int} and {int}`, async (int1, int2) => {

    console.log('ok when ', int1, ' ', int2)

})
import { Then } from "cypress-cucumber-preprocessor/steps";

Then(`I verify that the result is equal the {int}`, async (int3) => {

    console.log('then ', int3)

})

Results in Error: "Timed out retrying: Expected to find element: table, but never found it."

you should remove "Examples:"

Manuel-Suarez-Abascal commented 2 years ago

Can we add the functionality to include the Examples:? Currently, I need to comment the word Examples: as workaround:

Feature: Being a plugin handling Scenario Outline

    As a cucumber cypress plugin which handles Scenario Outline
    I want to allow people to write Scenario Outline tests and run it in cypress

    Scenario Outline: Using Scenario Outlines
        When I add <provided number> and <another provided number>
        Then I verify that the result is equal the <provided>

        #Examples:
            | provided number | another provided number | provided |
            | 1               | 2                       | 3        |
            | 100             | 200                     | 300      |

If we cannot do this now, at least can we a useful debugging error message if we use the word Examples:?