Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

having issue with json report generation #759

Closed
oguzhantx opened this issue Jul 11, 2022 · 25 comments
Closed

having issue with json report generation #759

oguzhantx opened this issue Jul 11, 2022 · 25 comments

Comments

@oguzhantx
Copy link

Current behavior

Tests run fine however json reports are stopped generating. everything was working fine with cypress version <10 and also cypress-cucumber-preprocessor <10 (before repo migration).
I have completed the steps mentioned here https://github.com/badeball/cypress-cucumber-preprocessor/blob/master/docs/json-report.md installed json-fomatter but still no luck.

e2e. js (support file)

import { addCucumberPreprocessorPlugin } from '@badeball/cypress-cucumber-preprocessor';
export default async (
on: Cypress.PluginEvents,
config: Cypress.PluginConfigOptions
): Promise<Cypress.PluginConfigOptions> => {
await addCucumberPreprocessorPlugin(on, config);
return config;
};

cypress.config.json

async function setupNodeEvents(on, config) {
await preprocessor.addCucumberPreprocessorPlugin(on, config);

on(
    'file:preprocessor',
    webpack({
        webpackOptions: {
            resolve: {
                extensions: ['.ts', '.js'],
            },
            module: {
                rules: [
                    {
                        test: /\.ts$/,
                        exclude: [/node_modules/],
                        use: [
                            {
                                loader: 'ts-loader',
                            },
                        ],
                    },
                    {
                        test: /\.feature$/,
                        use: [
                            {
                                loader: '@badeball/cypress-cucumber-preprocessor/webpack',
                                options: config,
                            },
                        ],
                    },
                ],
            },
        },
    })
);

When I run tests getting

image

if I just comment out the e2e.js file or set support file=false in config then tests run fine but no json reports.

Any suggestion is appreciated.

Desired behavior

json reports are generated when test completes running.

Versions

  • Cypress version: 10.3.0
  • Preprocessor version:11.4.0
  • Node version:16.13.1

Checklist

  • [x ] I've read the FAQ.
  • [ x] I've read Instructions for logging issues.
  • [ x] I'm not using cypress-cucumber-preprocessor@4.3.1 (package name has changed and it is no longer the most recent version, see #689).
@JomyGeo
Copy link

JomyGeo commented Jul 12, 2022

Try this ,

await preprocessor.addCucumberPreprocessorPlugin(on, config);

const options = {
webpackOptions: {
module: {
rules: [
{
test: /.feature$/,
use: [
{
loader: '@badeball/cypress-cucumber-preprocessor/webpack',
options: config,
},
],
},
],
},
},

};

on('file:preprocessor', webpackPreprocessor(options));
]
return config;
}

@badeball
Copy link
Owner

@oguzhantx, you're placing TS in a JS file. Rename it or remove the type annotations.

@oguzhantx
Copy link
Author

@badeball when I remove type annotations, I am not getting any error as mentioned in original post however, json reports are still not being generated.

@oguzhantx
Copy link
Author

Try this ,

await preprocessor.addCucumberPreprocessorPlugin(on, config);

const options = { webpackOptions: { module: { rules: [ { test: /.feature$/, use: [ { loader: '@badeball/cypress-cucumber-preprocessor/webpack', options: config, }, ], }, ], }, },

};

on('file:preprocessor', webpackPreprocessor(options)); ] return config; }

@JomyGeo When I update my setupNode Events function with this code, I am getting the below error.
ReferenceError: webpackPreprocessor is not defined
at setupNodeEvents (/Users/oguzhanozturk/Documents/Projects/doberman/cypress.config.js:32:5)

@badeball
Copy link
Owner

@badeball when I remove type annotations, I am not getting any error as mentioned in original post however, json reports are still not being generated.

Well it's impossible to say why given the provided information. Have you enabled it, as per docs?

@oguzhantx
Copy link
Author

@badeball when I remove type annotations, I am not getting any error as mentioned in original post however, json reports are still not being generated.

Well it's impossible to say why given the provided information. Have you enabled it, as per docs?

yes, json is enabled in package,json file, also I have tried with and without old config in package.json but did not make any difference.
"cypress-cucumber-preprocessor": {
"cucumberJson": {
"generate": true,
"outputFolder": "cypress/reports/cucumber-json",
"filePrefix": "",
"fileSuffix": ".cucumber"
}
}

one question I have though, do we need to specify any reporter option in cypress.config file when we define cypress configs. Ex:
image

@badeball
Copy link
Owner

@oguzhantx
Copy link
Author

all the steps in this doc are already completed and implemented in the cypress framework. no luck

@badeball
Copy link
Owner

Given that you tell me your current configuration looks like

{
  "cypress-cucumber-preprocessor": {
    "cucumberJson": {
      "generate": true,
      "outputFolder": "cypress/reports/cucumber-json",
      "filePrefix": "",
      "fileSuffix": ".cucumber"
    }
  }
}

.. then you have absolutely not configured JSON reporting according to the docs. Read them again.

@oguzhantx
Copy link
Author

it is not, you should read my previous message again where you got the idea that I still have it. I have mentioned there I just put it back for testing purpose to see if it will change anything. anyways, I was able to get the json report generated by using esbuild but only one json report is being generated for all test files. Is there a way to have individual json files for each feature file?

@oguzhantx
Copy link
Author

I do not see a solution to this issue. by closing this are you saying that you can generate a json report as used to for every individual test files?

@MDG-JHowley
Copy link

I have been debugging issues with JSON report output in my repo. You may be coming across this issue which is a regression in cypress v10: cypress-io/cypress#22428

@bartonhammond
Copy link

@oguzhantx Did you ever get this working? I can run my tests but no JSON is emitted.
Here's what I have done
0) running on windows 10 w/in bash

  1. I installed the Standalone JSON Formatter (https://github.com/cucumber/json-formatter/releases/download/v19.0.0/cucumber-json-formatter-windows-amd64)
  2. I moved it to my path and renamed it and confirmed it was installed
~/git/smc-cypress (hotfix/upgrade10)
$ cucumber-json-formatter.exe --help
Usage of C:\Users\hammonbu\bin\cucumber-json-formatter.exe:
  1. created cypress/support/e2e.ts with the following and confirmed it is invoked by adding console.log
import { addCucumberPreprocessorPlugin } from "@badeball/cypress-cucumber-preprocessor";

export default async (
  on: Cypress.PluginEvents,
  config: Cypress.PluginConfigOptions
): Promise<Cypress.PluginConfigOptions> => {
  await addCucumberPreprocessorPlugin(on, config);

  // Make sure to return the config object as it might have been modified by the plugin.
 console.log('config',config);
  return config;
}

console.log

config {
  animationDistanceThreshold: 5,
  arch: 'x64',
  autoOpen: false,
  baseUrl: null,
  blockHosts: null,
  browsers: [
    {
      name: 'chrome',
      family: 'chromium',
      channel: 'stable',
      displayName: 'Chrome',
      version: '103.0.5060.66',
      path: 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
      minSupportedVersion: 64,
      majorVersion: 103
    },
    {
      name: 'edge',
      family: 'chromium',
      channel: 'stable',
      displayName: 'Edge',
      version: '103.0.1264.49',
      path: 'C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe',
      minSupportedVersion: 79,
      majorVersion: 103
    },
    {
      name: 'electron',
      channel: 'stable',
      family: 'chromium',
      displayName: 'Electron',
      version: '100.0.4896.160',
      path: '',
      majorVersion: 100,
      info: 'Electron is the default browser that comes with Cypress. This is the default browser that runs in headless mode. Selecting this browser is useful when debugging. The version number indicates the underlying Chromium version that Electron uses.'
    }
  ],
  chromeWebSecurity: true,
  clientCertificates: [],
  clientRoute: '/__/',
  configFile: 'C:\\Users\\hammonbu\\git\\smc-cypress\\cypress.config.js',
  cypressBinaryRoot: 'C:\\Users\\hammonbu\\AppData\\Local\\Cypress\\Cache\\10.3.0\\Cypress\\resources\\app',
  cypressEnv: 'production',
  defaultCommandTimeout: 4000,
  devServerPublicPathRoute: '/__cypress/src',
  downloadsFolder: 'C:\\Users\\hammonbu\\git\\smc-cypress\\cypress\\downloads',
  env: {
    host: 'http://127.0.0.1:9081/smc-web/',
    ENV: 'dev'
  },
  excludeSpecPattern: '*.hot-update.js',
  execTimeout: 60000,
  experimentalFetchPolyfill: false,
  experimentalInteractiveRunEvents: false,
  experimentalSessionAndOrigin: false,
  experimentalSourceRewriting: false,
  fileServerFolder: 'C:\\Users\\hammonbu\\git\\smc-cypress',
  fixturesFolder: 'C:\\Users\\hammonbu\\git\\smc-cypress\\cypress\\fixtures',
  hosts: null,
  includeShadowDom: false,
  isInteractive: true,
  isTextTerminal: false,
  keystrokeDelay: 0,
  modifyObstructiveCode: true,
  morgan: true,
  namespace: '__cypress',
  numTestsKeptInMemory: 50,
  pageLoadTimeout: 60000,
  platform: 'win32',
  port: null,
  projectId: null,
  projectName: 'smc-cypress',
  projectRoot: 'C:\\Users\\hammonbu\\git\\smc-cypress',
  rawJson: {
    e2e: {
      specPattern: '**/*.feature',
      supportFile: 'cypress/support/index.js',
      setupNodeEvents: '[Function setupNodeEvents]'
    },
    specPattern: '**/*.feature',
    supportFile: 'cypress/support/index.js',
    setupNodeEvents: '[Function setupNodeEvents]',
    projectRoot: 'C:\\Users\\hammonbu\\git\\smc-cypress',
    projectName: 'smc-cypress'
  },
  redirectionLimit: 20,
  reporter: 'spec',
  reporterOptions: null,
  reporterRoute: '/__cypress/reporter',
  requestTimeout: 5000,
  resolved: {
    animationDistanceThreshold: { value: 5, from: 'default' },
    arch: { value: 'x64', from: 'default' },
    baseUrl: { value: null, from: 'default' },
    blockHosts: { value: null, from: 'default' },
    chromeWebSecurity: { value: true, from: 'default' },
    clientCertificates: { value: [], from: 'default' },
    defaultCommandTimeout: { value: 4000, from: 'default' },
    downloadsFolder: { value: 'cypress/downloads', from: 'default' },
    env: {
      host: [Object],
      username: [Object],
      password: [Object],
      ENV: [Object]
    },
    execTimeout: { value: 60000, from: 'default' },
    experimentalFetchPolyfill: { value: false, from: 'default' },
    experimentalInteractiveRunEvents: { value: false, from: 'default' },
    experimentalSessionAndOrigin: { value: false, from: 'default' },
    experimentalSourceRewriting: { value: false, from: 'default' },
    fileServerFolder: { value: '', from: 'default' },
    fixturesFolder: { value: 'cypress/fixtures', from: 'default' },
    excludeSpecPattern: { value: '*.hot-update.js', from: 'default' },
    includeShadowDom: { value: false, from: 'default' },
    keystrokeDelay: { value: 0, from: 'default' },
    modifyObstructiveCode: { value: true, from: 'default' },
    numTestsKeptInMemory: { value: 50, from: 'default' },
    platform: { value: 'win32', from: 'default' },
    pageLoadTimeout: { value: 60000, from: 'default' },
    port: { value: null, from: 'default' },
    projectId: { value: null, from: 'default' },
    redirectionLimit: { value: 20, from: 'default' },
    reporter: { value: 'spec', from: 'default' },
    reporterOptions: { value: null, from: 'default' },
    requestTimeout: { value: 5000, from: 'default' },
    resolvedNodePath: { value: null, from: 'default' },
    resolvedNodeVersion: { value: null, from: 'default' },
    responseTimeout: { value: 30000, from: 'default' },
    retries: { value: [Object], from: 'default' },
    screenshotOnRunFailure: { value: true, from: 'default' },
    screenshotsFolder: { value: 'cypress/screenshots', from: 'default' },
    slowTestThreshold: { value: 10000, from: 'default' },
    scrollBehavior: { value: 'top', from: 'default' },
    supportFile: { value: 'cypress/support/index.js', from: 'config' },
    supportFolder: { value: false, from: 'default' },
    taskTimeout: { value: 60000, from: 'default' },
    trashAssetsBeforeRuns: { value: true, from: 'default' },
    userAgent: { value: null, from: 'default' },
    video: { value: true, from: 'default' },
    videoCompression: { value: 32, from: 'default' },
    videosFolder: { value: 'cypress/videos', from: 'default' },
    videoUploadOnPasses: { value: true, from: 'default' },
    viewportHeight: { value: 660, from: 'default' },
    viewportWidth: { value: 1000, from: 'default' },
    waitForAnimations: { value: true, from: 'default' },
    watchForFileChanges: { value: true, from: 'default' },
    specPattern: { value: '**/*.feature', from: 'config' },
    browsers: { value: [Array], from: 'runtime' },
    hosts: { value: null, from: 'default' },
    isInteractive: { value: true, from: 'default' }
  },
  resolvedNodePath: 'C:\\Users\\hammonbu\\.nvm\\versions\\node\\v14.16.0\\bin\\node.exe',
  resolvedNodeVersion: '14.16.0',
  responseTimeout: 30000,
  retries: { runMode: 0, openMode: 0 },
  screenshotOnRunFailure: true,
  screenshotsFolder: 'C:\\Users\\hammonbu\\git\\smc-cypress\\cypress\\screenshots',
  scrollBehavior: 'top',
  setupNodeEvents: '[Function setupNodeEvents]',
  slowTestThreshold: 10000,
  socketId: null,
  socketIoCookie: '__socket',
  socketIoRoute: '/__socket',
  specPattern: '**/*.feature',
  supportFile: 'C:\\Users\\hammonbu\\git\\smc-cypress\\cypress\\support\\index.js',
  supportFolder: 'C:\\Users\\hammonbu\\git\\smc-cypress\\cypress\\support',
  taskTimeout: 60000,
  trashAssetsBeforeRuns: true,
  userAgent: null,
  version: '10.3.0',
  video: true,
  videoCompression: 32,
  videoUploadOnPasses: true,
  videosFolder: 'C:\\Users\\hammonbu\\git\\smc-cypress\\cypress\\videos',
  viewportHeight: 660,
  viewportWidth: 1000,
  waitForAnimations: true,
  watchForFileChanges: true,
  xhrRoute: '/xhrs/',
  testingType: 'e2e'
}
  1. updated cypress\support\index.js with this:
import "./commands";
import "./e2e";
  1. created .cypress-cucumber-preprocessorrc.json in root (above cypress - at level of ``package.json)` and it contains
{
  "json": {
    "enabled": true
  }
}
  1. I start cypress and run tests and kill all
  2. no errors are reported anywhere and no JSON file is emitted.

@oguzhantx
Copy link
Author

@oguzhantx Did you ever get this working? I can run my tests but no JSON is emitted. Here's what I have done 0) running on windows 10 w/in bash

  1. I installed the Standalone JSON Formatter (https://github.com/cucumber/json-formatter/releases/download/v19.0.0/cucumber-json-formatter-windows-amd64)
  2. I moved it to my path and renamed it and confirmed it was installed
~/git/smc-cypress (hotfix/upgrade10)
$ cucumber-json-formatter.exe --help
Usage of C:\Users\hammonbu\bin\cucumber-json-formatter.exe:
  1. created cypress/support/e2e.ts with the following and confirmed it is invoked by adding console.log
import { addCucumberPreprocessorPlugin } from "@badeball/cypress-cucumber-preprocessor";

export default async (
  on: Cypress.PluginEvents,
  config: Cypress.PluginConfigOptions
): Promise<Cypress.PluginConfigOptions> => {
  await addCucumberPreprocessorPlugin(on, config);

  // Make sure to return the config object as it might have been modified by the plugin.
 console.log('config',config);
  return config;
}

console.log

config {
  animationDistanceThreshold: 5,
  arch: 'x64',
  autoOpen: false,
  baseUrl: null,
  blockHosts: null,
  browsers: [
    {
      name: 'chrome',
      family: 'chromium',
      channel: 'stable',
      displayName: 'Chrome',
      version: '103.0.5060.66',
      path: 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
      minSupportedVersion: 64,
      majorVersion: 103
    },
    {
      name: 'edge',
      family: 'chromium',
      channel: 'stable',
      displayName: 'Edge',
      version: '103.0.1264.49',
      path: 'C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe',
      minSupportedVersion: 79,
      majorVersion: 103
    },
    {
      name: 'electron',
      channel: 'stable',
      family: 'chromium',
      displayName: 'Electron',
      version: '100.0.4896.160',
      path: '',
      majorVersion: 100,
      info: 'Electron is the default browser that comes with Cypress. This is the default browser that runs in headless mode. Selecting this browser is useful when debugging. The version number indicates the underlying Chromium version that Electron uses.'
    }
  ],
  chromeWebSecurity: true,
  clientCertificates: [],
  clientRoute: '/__/',
  configFile: 'C:\\Users\\hammonbu\\git\\smc-cypress\\cypress.config.js',
  cypressBinaryRoot: 'C:\\Users\\hammonbu\\AppData\\Local\\Cypress\\Cache\\10.3.0\\Cypress\\resources\\app',
  cypressEnv: 'production',
  defaultCommandTimeout: 4000,
  devServerPublicPathRoute: '/__cypress/src',
  downloadsFolder: 'C:\\Users\\hammonbu\\git\\smc-cypress\\cypress\\downloads',
  env: {
    host: 'http://127.0.0.1:9081/smc-web/',
    ENV: 'dev'
  },
  excludeSpecPattern: '*.hot-update.js',
  execTimeout: 60000,
  experimentalFetchPolyfill: false,
  experimentalInteractiveRunEvents: false,
  experimentalSessionAndOrigin: false,
  experimentalSourceRewriting: false,
  fileServerFolder: 'C:\\Users\\hammonbu\\git\\smc-cypress',
  fixturesFolder: 'C:\\Users\\hammonbu\\git\\smc-cypress\\cypress\\fixtures',
  hosts: null,
  includeShadowDom: false,
  isInteractive: true,
  isTextTerminal: false,
  keystrokeDelay: 0,
  modifyObstructiveCode: true,
  morgan: true,
  namespace: '__cypress',
  numTestsKeptInMemory: 50,
  pageLoadTimeout: 60000,
  platform: 'win32',
  port: null,
  projectId: null,
  projectName: 'smc-cypress',
  projectRoot: 'C:\\Users\\hammonbu\\git\\smc-cypress',
  rawJson: {
    e2e: {
      specPattern: '**/*.feature',
      supportFile: 'cypress/support/index.js',
      setupNodeEvents: '[Function setupNodeEvents]'
    },
    specPattern: '**/*.feature',
    supportFile: 'cypress/support/index.js',
    setupNodeEvents: '[Function setupNodeEvents]',
    projectRoot: 'C:\\Users\\hammonbu\\git\\smc-cypress',
    projectName: 'smc-cypress'
  },
  redirectionLimit: 20,
  reporter: 'spec',
  reporterOptions: null,
  reporterRoute: '/__cypress/reporter',
  requestTimeout: 5000,
  resolved: {
    animationDistanceThreshold: { value: 5, from: 'default' },
    arch: { value: 'x64', from: 'default' },
    baseUrl: { value: null, from: 'default' },
    blockHosts: { value: null, from: 'default' },
    chromeWebSecurity: { value: true, from: 'default' },
    clientCertificates: { value: [], from: 'default' },
    defaultCommandTimeout: { value: 4000, from: 'default' },
    downloadsFolder: { value: 'cypress/downloads', from: 'default' },
    env: {
      host: [Object],
      username: [Object],
      password: [Object],
      ENV: [Object]
    },
    execTimeout: { value: 60000, from: 'default' },
    experimentalFetchPolyfill: { value: false, from: 'default' },
    experimentalInteractiveRunEvents: { value: false, from: 'default' },
    experimentalSessionAndOrigin: { value: false, from: 'default' },
    experimentalSourceRewriting: { value: false, from: 'default' },
    fileServerFolder: { value: '', from: 'default' },
    fixturesFolder: { value: 'cypress/fixtures', from: 'default' },
    excludeSpecPattern: { value: '*.hot-update.js', from: 'default' },
    includeShadowDom: { value: false, from: 'default' },
    keystrokeDelay: { value: 0, from: 'default' },
    modifyObstructiveCode: { value: true, from: 'default' },
    numTestsKeptInMemory: { value: 50, from: 'default' },
    platform: { value: 'win32', from: 'default' },
    pageLoadTimeout: { value: 60000, from: 'default' },
    port: { value: null, from: 'default' },
    projectId: { value: null, from: 'default' },
    redirectionLimit: { value: 20, from: 'default' },
    reporter: { value: 'spec', from: 'default' },
    reporterOptions: { value: null, from: 'default' },
    requestTimeout: { value: 5000, from: 'default' },
    resolvedNodePath: { value: null, from: 'default' },
    resolvedNodeVersion: { value: null, from: 'default' },
    responseTimeout: { value: 30000, from: 'default' },
    retries: { value: [Object], from: 'default' },
    screenshotOnRunFailure: { value: true, from: 'default' },
    screenshotsFolder: { value: 'cypress/screenshots', from: 'default' },
    slowTestThreshold: { value: 10000, from: 'default' },
    scrollBehavior: { value: 'top', from: 'default' },
    supportFile: { value: 'cypress/support/index.js', from: 'config' },
    supportFolder: { value: false, from: 'default' },
    taskTimeout: { value: 60000, from: 'default' },
    trashAssetsBeforeRuns: { value: true, from: 'default' },
    userAgent: { value: null, from: 'default' },
    video: { value: true, from: 'default' },
    videoCompression: { value: 32, from: 'default' },
    videosFolder: { value: 'cypress/videos', from: 'default' },
    videoUploadOnPasses: { value: true, from: 'default' },
    viewportHeight: { value: 660, from: 'default' },
    viewportWidth: { value: 1000, from: 'default' },
    waitForAnimations: { value: true, from: 'default' },
    watchForFileChanges: { value: true, from: 'default' },
    specPattern: { value: '**/*.feature', from: 'config' },
    browsers: { value: [Array], from: 'runtime' },
    hosts: { value: null, from: 'default' },
    isInteractive: { value: true, from: 'default' }
  },
  resolvedNodePath: 'C:\\Users\\hammonbu\\.nvm\\versions\\node\\v14.16.0\\bin\\node.exe',
  resolvedNodeVersion: '14.16.0',
  responseTimeout: 30000,
  retries: { runMode: 0, openMode: 0 },
  screenshotOnRunFailure: true,
  screenshotsFolder: 'C:\\Users\\hammonbu\\git\\smc-cypress\\cypress\\screenshots',
  scrollBehavior: 'top',
  setupNodeEvents: '[Function setupNodeEvents]',
  slowTestThreshold: 10000,
  socketId: null,
  socketIoCookie: '__socket',
  socketIoRoute: '/__socket',
  specPattern: '**/*.feature',
  supportFile: 'C:\\Users\\hammonbu\\git\\smc-cypress\\cypress\\support\\index.js',
  supportFolder: 'C:\\Users\\hammonbu\\git\\smc-cypress\\cypress\\support',
  taskTimeout: 60000,
  trashAssetsBeforeRuns: true,
  userAgent: null,
  version: '10.3.0',
  video: true,
  videoCompression: 32,
  videoUploadOnPasses: true,
  videosFolder: 'C:\\Users\\hammonbu\\git\\smc-cypress\\cypress\\videos',
  viewportHeight: 660,
  viewportWidth: 1000,
  waitForAnimations: true,
  watchForFileChanges: true,
  xhrRoute: '/xhrs/',
  testingType: 'e2e'
}
  1. updated cypress\support\index.js with this:
import "./commands";
import "./e2e";
  1. created .cypress-cucumber-preprocessorrc.json in root (above cypress - at level of ``package.json)` and it contains
{
  "json": {
    "enabled": true
  }
}
  1. I start cypress and run tests and kill all
  2. no errors are reported anywhere and no JSON file is emitted.

check this out. https://www.youtube.com/watch?v=FlQ9Carxeds&t=10s

@bartonhammond
Copy link

bartonhammond commented Jul 20, 2022

@oguzhantx Thanks! Your video and project were very helpful - thank you. My reports are all running again.

@RoopaShivakumar
Copy link

@badeball @bartonhammond @oguzhantx Hey was it solved, were you able to generate json reports, I am not able .
So have switched to mocha reporter, which i am using which is good but only thing is since combined with cucumber ,when displaying the code in the report, it shows irrelevant code rathe than the step definitions code..

I am using Cypress 10, and cucumber preprocessor, Have updated this in cypress.config.json
(Ignore mocha reporter commands, I have used as cucumber jsons were not generating from where we can get html reports)
const { defineConfig } = require("cypress");
const createEsbuildPlugin = require('@badeball/cypress-cucumber-preprocessor/esbuild').createEsbuildPlugin
const createBundler = require('@bahmutov/cypress-esbuild-preprocessor')
const nodePolyfills = require('@esbuild-plugins/node-modules-polyfill').NodeModulesPolyfillPlugin
const addCucumberPreprocessorPlugin = require('@badeball/cypress-cucumber-preprocessor').addCucumberPreprocessorPlugin
const addReportPlugin = require('cypress-mochawesome-reporter/plugin')

async function setupNodeEvents(on, config) {
require('cypress-mochawesome-reporter/plugin')(on);
await addCucumberPreprocessorPlugin(on, config);
on(
"file:preprocessor",
createBundler({
plugins: [nodePolyfills(), createEsbuildPlugin(config)],
})
);
await addReportPlugin(on);
// Make sure to return the config object as it might have been modified by the plugin.
return config;
}

module.exports = defineConfig({
defaultCommandTimeout: 6000,
viewportWidth: 1024,
viewportHeight: 768,
//pageLoadTimeout: 60000,
chromeWebSecurity: false,
video: false,
reporter: 'cypress-mochawesome-reporter',
//reporter: 'multiple-cucumber-html-reporter',

reporterOptions: {
charts: true,
reportPageTitle: 'Cypress Automation execution Report',
embeddedScreenshots: true,
inlineAssets: true,
saveAllAttempts: false,
overwrite: false,
timestamp: true,
json: true,
saveJson: true,
code: true
},
e2e: {
supportFile: false,
specPattern: ["/*.feature", "cypress/e2e//*.cy.{js,jsx,ts,tsx}"],
setupNodeEvents,
},
});

and my package.json
{
"name": "cypress-adapt",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "cypress open"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@badeball/cypress-cucumber-preprocessor": "^11.4.0",
"@bahmutov/cypress-esbuild-preprocessor": "^2.1.3",
"@esbuild-plugins/node-modules-polyfill": "^0.1.4",
"cypress": "^10.3.0",
"cypress-cucumber-preprocessor": "^4.3.1",
"cypress-iframe": "^1.0.1",
"cypress-mochawesome-reporter": "^3.2.0",
"cypress-wait-until": "^1.7.2",
"cypress-xpath": "^2.0.0",
"esbuild": "^0.14.48",
"multiple-cucumber-html-reporter": "^1.21.4"
},
"cypress-cucumber-preprocessor": {
"nonGlobalStepDefinitions": true,
"stepDefinitions": "cypress/e2e/AdaptDemandTest/*.{js,ts}",
"cucumberJson": {
"generate": true,
"outputFolder": "cypress/cucumber-json",
"filePrefix": "",
"fileSuffix": ".cucumber"
}
},
"json": {
"enabled": true
},

"dependencies": {}
}

Please any help much appreciated, Cucumber html reports with test content and screenshots for failed cases is required...

@badeball
Copy link
Owner

#775 (comment)

@RoopaShivakumar
Copy link

@badeball @surajwaitz I went through the above issue., I am not maintaining different file cypress-cucumber-preprocessor.config.js,

All config related i have put in package.json as i have pasted earlier,
Still not getting json report, What i am missing here??

@badeball
Copy link
Owner

I can clearly see from the above-mentioned package.json, that not all configuration values are placed within the "cypress-cucumber-preprocessor": { .. } block.

@RoopaShivakumar
Copy link

Thank you @badeball ,ndJson file got generated after moving this json enabled under "cypress-cucumber-preprocessor": { .. }

"cypress-cucumber-preprocessor": {
"nonGlobalStepDefinitions": true,
"stepDefinitions": "cypress/e2e/AdaptDemandTest/*.{js,ts}",
"cucumberJson": {
"generate": true,
"outputFolder": "cypress/cucumber-json",
"filePrefix": "",
"fileSuffix": ".cucumber"
} ,
"json": {
"enabled": true
}

},

Have downloaded the json formatter as per the instructions given and ran to convert cucmber-messages.ndjson to .json file.

was converted it to json, But not able to generate the html reports,

Using "multiple-cucumber-html-reporter": "^1.21.4", and created to generate html file
const report = require('multiple-cucumber-html-reporter');

report.generate({
jsonDir: 'cypress/cucumber-json',
reportPath: './reports/cucumber-htmlreport.html',
metadata: {
browser: {
name: 'chrome',
version: '103'
},
device: 'M2B-L-18KWT93',
platform: {
name: 'Microsoft Windows 10',
version: '20H2'
}
},
customData: {
title: 'Run info',
data: [
{ label: 'Project', value: 'Custom project' },
{ label: 'Release', value: '1.2.3' },
{ label: 'Cycle', value: 'B11221.34321' },
{ label: 'Execution Start Time', value: 'Nov 19th 2017, 02:31 PM EST' },
{ label: 'Execution End Time', value: 'Nov 19th 2017, 02:56 PM EST' }
]
}
});

and when i ran the file, it throws error to generate html report
PS C:\REPL-Adapt\cypress-Adapt> node .\cucumber-html-report.js
undefined:1
��[
^

SyntaxError: Unexpected token � in JSON at position 0
at JSON.parse ()
at C:\REPL-Adapt\cypress-Adapt\node_modules\multiple-cucumber-html-reporter\lib\collect-jsons.js:37:18
at Array.map ()
at collectJSONS (C:\REPL-Adapt\cypress-Adapt\node_modules\multiple-cucumber-html-reporter\lib\collect-jsons.js:31:15)
at Object.generateReport [as generate] (C:\REPL-Adapt\cypress-Adapt\node_modules\multiple-cucumber-html-reporter\lib\generate-report.js:72:22)
at Object. (C:\REPL-Adapt\cypress-Adapt\cucumber-html-report.js:3:8)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
PS C:\REPL-Adapt\cypress-Adapt>

the json file converted luks good but not able to generate html report

So will the json report not work with multiple-cucumber-html-reporter??
Can you please help on this?

@surajwaitz
Copy link

surajwaitz commented Jul 29, 2022

@RoopaShivakumar : It seems your json is generating as empty, could you please check it?
Also, could you please try below configurations in package.json?

"cypress-cucumber-preprocessor": {
"nonGlobalStepDefinitions": true,
"json": {
"enabled": true,
"output": "cypress/cucumber-json/log.json",
"formater": "cucumber-json-formatter.exe"
},
"messages": {
"enabled": true,
"output": "cypress/cucumber-json/messages.ndjson",
},
"filterSpecs": true,
"omitFiltered": true
},
"stepDefinitions": [
"[filepart]/step_definitions/.{js,ts}",
"cypress/e2e/AdaptDemandTest/
.{js,ts}"
]

@RoopaShivakumar
Copy link

RoopaShivakumar commented Jul 29, 2022

@RoopaShivakumar : It seems your json is generating as empty, could you please check it? Also, could you please try below configurations in package.json?

"cypress-cucumber-preprocessor": { "nonGlobalStepDefinitions": true, "json": { "enabled": true, "output": "cypress/cucumber-json/log.json", "formater": "cucumber-json-formatter.exe" }, "messages": { "enabled": true, "output": "cypress/cucumber-json/messages.ndjson", }, "filterSpecs": true, "omitFiltered": true }, "stepDefinitions": [ "[filepart]/step_definitions/.{js,ts}", "cypress/e2e/AdaptDemandTest/.{js,ts}" ]

Nope.....json was not empty it was fine...it had all the Scenarios...let me attach that.(the ndJson file which got generated and then i ran cucumber-formatter and got the json report)attaching it..
REPORTDEBUG.zip

...

But cudnt get html reports from that json report file, Will try updating in json file which you have mentioned

@RoopaShivakumar
Copy link

the json file created by cat .\cypress\cucumber-json\messages.ndjson | .\cucumber-json-formatter.exe >.\cypress\cucumber-json\adptOrig.json

might have some character...
So when opened the file in notepad++ and select all,copy and paste in new notepad++ file and save as JSON file then the report gt generated, its weird just did a copy paste of that file and saved as JSON file in notepad++.

Tried cat .\cypress\cucumber-json\messages.ndjson | .\cucumber-json-formatter.exe --format=json >.\cypress\cucumber-json\adptOrig.json
or
cat .\cypress\cucumber-json\messages.ndjson | .\cucumber-json-formatter.exe --format json >.\cypress\cucumber-json\adptOrig.json

but gives this error
flag provided but not defined: -format

PLease suggest how to specify format option in cucumber-json-formatter.exe which gives a clean json file

@RoopaShivakumar
Copy link

RoopaShivakumar commented Aug 18, 2022

@badeball @surajwaitz Please Any updates on this...can't we have a json file generated instead of generating messages.ndJson and then converting using json formatter to generate json file??
Because we need to add a manual step there...

Also will the json files gets generated??in my case its not...in package.json...
"cypress-cucumber-preprocessor": {
"nonGlobalStepDefinitions": true,
"stepDefinitions": "cypress/e2e/AdaptDemandTest/*.{js,ts}",
"cucumberJson": {
"generate": true,
"outputFolder": "cypress/cucumber-json",
"filePrefix": "",
"fileSuffix": ".cucumber"
},
"json": {
"enabled": true,
"output": "cypress/cucumber-json/log.json",
"formater": "cucumber-json-formatter.exe"
},
"messages": {
"enabled": true,
"output": "cypress/cucumber-json/messages.ndjson"
},
"filterSpecs": true,
"omitFiltered": true
},
only the messagesNdjson getting generated but not json files....Is it becasue i have mocha report as well in cypress.config.json
const addReportPlugin = require('cypress-mochawesome-reporter/plugin')
await addReportPlugin(on);
module.exports = defineConfig({
defaultCommandTimeout: 6000,
viewportWidth: 1024,
viewportHeight: 768,
//pageLoadTimeout: 60000,
chromeWebSecurity: false,
video: false,
reporter: 'cypress-mochawesome-reporter',
//reporter: 'multiple-cucumber-html-reporter',

reporterOptions: {
charts: true,
reportPageTitle: 'Cypress Automation execution Report',
embeddedScreenshots: true,
inlineAssets: true,
saveAllAttempts: false,
overwrite: false,
timestamp: true,
json: true,
//saveJson: true,
code: false
},
e2e: {
baseUrl: "<>",
supportFile: false,
specPattern: ["/*.feature", "cypress/e2e//*.cy.{js,jsx,ts,tsx}"],
setupNodeEvents,
},
});

PLease let me know....or what config is missing

@RoopaShivakumar
Copy link

@RoopaShivakumar : It seems your json is generating as empty, could you please check it? Also, could you please try below configurations in package.json?

"cypress-cucumber-preprocessor": { "nonGlobalStepDefinitions": true, "json": { "enabled": true, "output": "cypress/cucumber-json/log.json", "formater": "cucumber-json-formatter.exe" }, "messages": { "enabled": true, "output": "cypress/cucumber-json/messages.ndjson", }, "filterSpecs": true, "omitFiltered": true }, "stepDefinitions": [ "[filepart]/step_definitions/.{js,ts}", "cypress/e2e/AdaptDemandTest/.{js,ts}" ]

@surajwaitz @badeball ....Able to generate the html report....Had put the cucumber-json-formatter in the PATH and I had cypress mocha report as well so commented mocha report part and JSON reports were generated without manual step...
in the HTML report not able to add Execution start and End time...
Tried this
{ label: 'Execution Start Time', value: new Date(runInfos.startedTestsAt).toLocaleString() },

but it shows Invalid date in the Report.....
tried { label: 'Execution Start Time', value: new Date(runInfos.startedTestsAt).toISOString() }, but this gives error when tried running the node .\cucumber-html-report.js itself...

In Mocha report by default the total time taken for the execution is displayed in the report but not in Cucumber report....
Have set the below options
displayDuration: true,
durationInMS: true,
displayReportTime: true,

but doesnt look like these options show the proper duration

Please let know to include...and also the
-report shows the Scenario but doesn't show the Step definition file steps. It would be good to have this
PLease guide on

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants