Cypress with BDD Cucumber how to create my own data type

871 views Asked by At

I am using cypress with cucumber-js and i need to define my own data type. I did exactly same things like is described in https://github.com/TheBrainFamily/cypress-cucumber-preprocessor#custom-parameter-type-resolves.

That means: cypress > support > step_definitions > customParameterTypes.js I wrote:

const blogType = ["sport", "gaming"]

defineParameterType({
    name: "blogType",
    regexp: new RegExp(blogType.join("|"))
})

and in my BDD .feature file i have:

Given I have empty blog
And  Blog has default structure for sport

and in my cypress file:

Given(' Blog has default structure for {blogType}', blogType => {...})

When i start my test i get:

The following error originated from your test code, not from Cypress.

  > Undefined parameter type {blogType}

When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.

Cypress could not associate this error to any specific test.
1

There are 1 answers

1
PeaceAndQuiet On

For some reasons, I've had problems using defineParameterType() in the past, and am now using regexp in all my BDD projects.

In your .js file:

Given(/^Blog has default structure for (sport|gaming)$/, blogType => {...});

Using the above, you won't need customParameterTypes.js and your .feature file stays the same.