question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to use fixture with cucumber plugin

See original GitHub issue

Hi @lgandecki and all,

I am unable to use fixtures inside When,And etc. It is showing me an error : TypeError: Cannot read property 'data' of undefined

Below is the code snippet:

image

image

Below is the test runner execution error:

image

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
varunpradhancommented, Jan 24, 2020

Hi @lgandecki It worked thank you for the help but after removing mocha import it was still not working

Then I changed my below style of code

Given(‘I import fixture’, () => { cy.log(this.data.AnimalGroupNo) })

To your given style of code :

Given(‘I import fixture’, function () { cy.log(this.data.AnimalGroupNo) })

then it worked.

Thank you for the help 😃

1reaction
lgandeckicommented, Jan 24, 2020

this worked for me:

/// <reference types="Cypress" />

import { Given } from "cypress-cucumber-preprocessor/steps";
import "cypress-ntlm-auth/dist/commands";


beforeEach(function () {
     cy.fixture('createTestData').then((data) =>
     {
         this.data= "elo"
     })
 })

Given('I import fixture', function () {
  expect(this.data).to.equal("elo")
})

When('Test When log', () => {
    cy.log('Test When log')
})

Then("Test Then log", () => {
    cy.log('Test Then log')
})

don’t import anything from mocha, and make sure you use function callbacks, you have it explained here:

https://docs.cypress.io/api/commands/fixture.html#Encoding

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to use fixture with cucumber plugin · Issue #317 - GitHub
Hi @lgandecki and all, I am unable to use fixtures inside When,And etc. It is showing me an error : TypeError: Cannot read...
Read more >
Cypress cucumber with custom directory structure
I need to support a custom directory structure on my project that uses Cypress for testing. As I am using cucumber preprocessor plugin...
Read more >
Plugins - Cypress Documentation
Plugins provide a way to support and extend the behavior of Cypress. Follow these instructions to ... Run cucumber/gherkin-syntaxed specs with cypress.io.
Read more >
Using Cypress with Cucumber to test your app as if you were ...
Cucumber is a test framework for BDD. By using the Gherkin language, it allows you to write tests that look like natural language....
Read more >
How to set up Cucumber BDD Automation Framework in ...
The first file (shown by marker 1) is the "index. js" file under the plugins folder. We need to make the following changes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found