badeball / cypress-cucumber-preprocessor

Run cucumber/gherkin-syntaxed specs with Cypress
MIT License
1.32k stars 147 forks source link

Cucumber report is missing when visit another site #944

Closed zerazeon closed 1 year ago

zerazeon commented 1 year ago

Current behavior

image image

cucumber-report.json

[
  {
    "description": "",
    "elements": [
      {
        "description": "",
        "id": "searchengine;visiting-the-frontpage;;4",
        "keyword": "Scenario Outline",
        "line": 10,
        "name": "visiting the frontpage",
        "steps": [
          {
            "keyword": "When ",
            "line": 3,
            "name": "I visit http://google.com",
            "result": {
              "duration": 1626000000,
              "status": "passed"
            },
            "match": {
              "location": "not available:0"
            }
          },
          {
            "keyword": "Then ",
            "line": 4,
            "name": "I should see a search bar",
            "result": {
              "duration": 79000000,
              "status": "passed"
            },
            "match": {
              "location": "not available:0"
            }
          }
        ],
        "type": "scenario"
      },
      {
        "description": "",
        "id": "searchengine;visiting-the-frontpage;;5",
        "keyword": "Scenario Outline",
        "line": 11,
        "name": "visiting the frontpage",
        "steps": [
          {
            "keyword": "When ",
            "line": 3,
            "name": "I visit http://google.com",
            "result": {
              "duration": 840000000,
              "status": "passed"
            },
            "match": {
              "location": "not available:0"
            }
          },
          {
            "keyword": "Then ",
            "line": 4,
            "name": "I should see a search bar",
            "result": {
              "duration": 84000000,
              "status": "passed"
            },
            "match": {
              "location": "not available:0"
            }
          }
        ],
        "type": "scenario"
      }
    ],
    "id": "searchengine",
    "keyword": "Feature",
    "line": 1,
    "name": "SearchEngine",
    "uri": "features/search.feature"
  }
]

Desired behavior

From my code, result of "http://duckduckgo.com" should be in json and ndjson.

Test code to reproduce

My code

search.feature

Feature: SearchEngine
  Scenario Outline: visiting the frontpage
    When I visit <site>
    Then I should see a search bar

  Examples:
  | site |
  | http://duckduckgo.com |
  | http://duckduckgo.com |
  | http://google.com |
  | http://google.com |

search.step.js

const { When, Then } = require("@badeball/cypress-cucumber-preprocessor");

When("I visit {}", (site) => {
    cy.visit(site);
});

Then("I should see a search bar", () => {
  cy.get("input").should("be.visible");
});

Versions

ghost commented 1 year ago

Hello,

Can you share your package.json and cypress.config.js files please?

ghost commented 1 year ago

I've this issue when I try to run your test. Is it normal ?

  1) SearchEngine
       visiting the frontpage (example #1):
     Error: 
Step implementation missing for "I visit http://duckduckgo.com".

We tried searching for files containing step definitions using the following search pattern templates:

  - cypress/e2e/[filepath]/**/*.{js,mjs,ts,tsx}
  - cypress/e2e/[filepath].{js,mjs,ts,tsx}
  - cypress/support/step_definitions/**/*.{js,mjs,ts,tsx}

These templates resolved to the following search patterns:

  - cypress/e2e/spec/**/*.{js,mjs,ts,tsx}
  - cypress/e2e/spec.{js,mjs,ts,tsx}
  - cypress/support/step_definitions/**/*.{js,mjs,ts,tsx}

These patterns matched **no files** containing step definitions. This almost certainly means that you have misconfigured `stepDefinitions`.

You can implement it using the suggestion(s) below.

  Given("I visit http:\\/\\/duckduckgo.com", function () {
    return "pending";
  });

Cypress v12.5.1

zerazeon commented 1 year ago

@Tay08

Hello,

Can you share your package.json and cypress.config.js files please?

package.json

{
  "name": "cucumber",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@badeball/cypress-cucumber-preprocessor": "^15.1.3",
    "@bahmutov/cypress-esbuild-preprocessor": "^2.1.5",
    "cypress": "^12.5.1",
    "esbuild": "0.16.5"
  }
}

cypress.config.js

const { defineConfig } = require("cypress");
const createBundler = require("@bahmutov/cypress-esbuild-preprocessor");
const preprocessor = require("@badeball/cypress-cucumber-preprocessor");
const createEsbuildPlugin = require("@badeball/cypress-cucumber-preprocessor/esbuild");

async function setupNodeEvents(on, config) {
  // This is required for the preprocessor to be able to generate JSON reports after each run, and more,
  await preprocessor.addCucumberPreprocessorPlugin(on, config);

  on(
    "file:preprocessor",
    createBundler({
      plugins: [createEsbuildPlugin.default(config)],
    })
  );

  // Make sure to return the config object as it might have been modified by the plugin.
  return config;
}

module.exports = defineConfig({
  e2e: {
    specPattern: "**/*.feature",
    setupNodeEvents,
  },
  defaultCommandTimeout: 10000,
  viewportWidth: 1366,
  viewportHeight: 768,
  screenshotOnRunFailure: false,
  video: false,
  videosFolder: "output/videos",
  screenshotsFolder: "output/screenshots",
  downloadsFolder: "output/downloads",

});
zerazeon commented 1 year ago

I apologize for accidentally closed

ghost commented 1 year ago

Sorry @zerazeon but I've the same issue. Any idea?

  1) SearchEngine
       visiting the frontpage (example #1):
     Error: 
Step implementation missing for "I visit http://duckduckgo.com".

We tried searching for files containing step definitions using the following search pattern templates:

  - cypress/e2e/[filepath]/**/*.{js,mjs,ts,tsx}
  - cypress/e2e/[filepath].{js,mjs,ts,tsx}
  - cypress/support/step_definitions/**/*.{js,mjs,ts,tsx}

These templates resolved to the following search patterns:

  - cypress/e2e/spec/**/*.{js,mjs,ts,tsx}
  - cypress/e2e/spec.{js,mjs,ts,tsx}
  - cypress/support/step_definitions/**/*.{js,mjs,ts,tsx}

These patterns matched **no files** containing step definitions. This almost certainly means that you have misconfigured `stepDefinitions`.

You can implement it using the suggestion(s) below.

  Given("I visit http:\\/\\/duckduckgo.com", function () {
    return "pending";
  });
zerazeon commented 1 year ago

@Tay08 I'm sorry. I forgot to give you ".cypress-cucumber-preprocessorrc.json" .cypress-cucumber-preprocessorrc.json

{
    "filterSpecs": true,
    "omitFiltered": true,
    "stepDefinitions": [
      "cypress/steps/**/*.{js,ts}"
    ],
    "json": {
      "enabled": true,
      "output": "output/cucumber.json",
      "formatter": "cucumber-json-formatter"
    },
    "messages": {
      "enabled": true,
      "output": "output/cucumber.ndjson"
    },
    "html": {
      "enabled": true,
      "output": "output/cucumber.html"
    }
  }
ghost commented 1 year ago

Ok @zerazeon no worries, and to make sure, can you share also your project structure please?

zerazeon commented 1 year ago

@Tay08 here my project structure image

ghost commented 1 year ago

Thank you @zerazeon Any info about my issue previously? Do you encountered already this issue?

Anything else inside commands.js and e2e.js files?

zerazeon commented 1 year ago

@Tay08 for commands.js and e2e.js

commands.js

// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })

e2e.js

// ***********************************************************
// This example support/e2e.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
Cypress.on('uncaught:exception', (err, runnable, promise) => {
    // when the exception originated from an unhandled promise
    // rejection, the promise is provided as a third argument
    // you can turn off failing the test in this case
    // if (promise) {
    return false
    // }
    // we still want to ensure there are no other unexpected
    // errors, so we let them fail the test
})
zerazeon commented 1 year ago

Here my code that I reproduce an issue.

badeball commented 1 year ago

Interfacing with Cypress in cases of domain switch during a test is unfortunately difficult and not handled properly. I'm not sure at this point if this will ever change, but I'm leaving the isuse open for now.

pat-convex commented 1 year ago

@Tay08 here my project structure image

hello, please what theme are using ?? i like the theme.

zerazeon commented 1 year ago

hello, please what theme are using ?? i like the theme.

It's Dark+ and Material Icon

norbertorok92 commented 1 year ago

any news on this? Seem to have strange behaviour too. in the reports, I get only the failed tests.

badeball commented 1 year ago

This will likely depend on whether this is answered: https://github.com/cypress-io/cypress/issues/26613.

badeball commented 1 year ago

This has been fixed in v17.0.0.