Encountering an abrupt conclusion in JSON input while utilizing cucumber-html-reporter alongside Nightwatch-Cucumber

I have been utilizing Nightwatch-Cucumber to automate my end-to-end tests and I am encountering an issue when trying to generate a cucumber html report after test execution using cucumber-html-reporter. The error message I receive during the report generation by cucumber-html-reporter is as follows:

Unable to parse cucumberjs output into json: 'reports/cucumber.json' SyntaxError: reports/cucumber.json: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at Object.readFileSync (/Users/GRme/projects/e2e-web-tests/node_modules/jsonfile/index.js:69:17)

I am uncertain as to why my generated cucumber.json file is invalid.

The versions I am currently using are:

"cucumber-html-reporter": "^2.0.0",
"nightwatch": "^0.9.16",
"nightwatch-cucumber": "^7.1.10",

This is how my configuration looks in nightwatch.conf.js:

require('nightwatch-cucumber')({
  cucumberArgs: [
      '--tags', '@run',
      '--require', 'timeout.js',
      '--require', 'hooks.js',
      '--require', 'features/step_definitions',
      '--format', 'pretty',
      '--format', 'json:reports/cucumber.json',
      'features']
});

Furthermore, this is the content of hooks.js, where the cucumber html report generation takes place:

const {client} = require('nightwatch-cucumber');
const {defineSupportCode} = require('cucumber');
var reporter = require('cucumber-html-reporter');

var options = {
  theme: 'bootstrap',
  jsonFile: 'reports/cucumber.json',
  output: 'reports/cucumber_report.html',
  reportSuiteAsScenarios: true,
  launchReport: false,
  //ignoreBadJsonFile: true,
  name: 'NIKITA end-to-end tests',
  brandTitle: 'NIKITA end-to-end tests',
  storeScreenShots: true,
  metadata: {
//    "App Version": "0.0.1",
//    "Test Environment": "AAT",
//    "Browser": "Chrome XXX",
//    "Platform": "Mac OS X",
  }
};

defineSupportCode(({Before, After}) => {
  Before(function() {
    client.maximizeWindow();
  });

  After(function() {
    reporter.generate(options);
  });
});

The contents of my apparently invalid cucumber.json file look like this:

[
  {
    "keyword": "Feature",
    "line": 1,
    "name": "only a test feature",
    "tags": [],
    "uri": "/Users/GRme/projects/e2e-web-tests/features/testFeature.feature",
    "elements": [
      {
        "keyword": "Scenario",
        "line": 4,
        "name": "only a test Scenario",
        "tags": [
          {
            "line": 3,
            "name": "@run"
          }
        ],
        "id": "only-a-test-feature;only-a-test-scenario",
        "steps": [
          {
            "arguments": [],
            "keyword": "Before",
            "result": {
              "status": "passed",
              "duration": 1
            },
            "hidden": true,
            "match": {
              "location": "/Users/GRme/projects/e2e-web-tests/hooks.js:24"
            }
          },
          {
            "arguments": [],
            "keyword": "When ",
            "name": "\"1\" seconds waiting",
            "result": {
              "status": "passed",
              "duration": 2615
            },
            "line": 5,
            "match": {
              "location": "/Users/GRme/projects/e2e-web-tests/features/step_definitions/abstractStepDefinition.js:10"
            }
          },
          {
            "arguments": [],
            "keyword": "After",
            "result": {
              "status": "passed",
              "duration": 4
            },
            "hidden": true,
            "match": {
              "location": "/Users/GRme/projects/e2e-web-tests/hooks.js:28"
            }
          }
        ]
      }
    ],
    "id": "only-a-test-feature"
  }
]

When generating the Cucumber Html Report via Jenkins using the Cucumber Reports Plugin, it runs successfully.

My question now is, how can I address this issue and determine which framework (Nightwatch-Cucumber or cucumber-html-reporter) is causing the problem? Additionally, what part of my generated cucumber.json is considered invalid?

Answer №1

To enhance your testing process, consider creating a cucumber HTML report as a distinct step within the test execution. One approach is to utilize a separate npm script specifically for generating the report. The current issue lies in relying on the global After hook in Cucumber.js where the report may not have been generated yet, leading to errors. A more effective solution would be to run a dedicated node.js script responsible for executing cucumber-html-reporter.

Answer №2

Utilizing the power of an Action Executor, I was able to successfully tackle the issue at hand. By incorporating the Cucumber report generation within this Action Executor function triggered by the AfterFeatures event, everything fell into place seamlessly.

For further details, feel free to explore more here.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Comparison Between Object and Array

When inputting the values {2,4,45,50} in the console, 50 is displayed. However, assigning these values to a variable results in an error: var a = {2,4,45,50} Uncaught SyntaxError: Unexpected number Can you explain this concept? ...

Python : Retrieving file from the URL associated with PHP functionality

I'm attempting to download a file from a webpage. The file is linked using php:~/download.php?id=~ To download the file, you can either click the link or right-click and choose the option "save this file" in your web browser. Initially, I tried usin ...

Converting this HTML/PHP code into JavaScript: A step-by-step guide

I have been struggling to convert this code into JavaScript in order to set the document.getElementById().innerHTML and display it in HTML. Can anyone assist with writing this code in JavaScript? <form action='create_new_invoice.php?name="<?php ...

updating the background image in CSS after uploading a photo using Ajax

Whenever I click on an element, it triggers an input dialog that allows me to upload a photo. The server then responds with a JSON OBJECT containing 4 items: NAME, TYPE, HEIGHT, WIDTH. My goal is to refresh the element's background with the newly upl ...

overlay appears as I reveal the slide-out menu

Struggling with adding an overlay to an expanding navigation bar, similar to Youtube's overlay when the slide-out nav is open. Need help with the implementation. Here is the javascript code for the expanding navigation using jQuery: 'use strict ...

Create an excel spreadsheet using HTML tables with the help of jQuery

Upon clicking a button, I aim to generate an excel sheet. Essentially, I am trying to achieve what is being discussed here (Kalle H. Väravas answer). If the following links are not working within Mozilla browser, then maybe my code requires ActiveXObject ...

issue encountered when attempting to use string.replace with regex

When using a regex like this: I am attempting to replace "subdir" with a custom string using the string.replace method. However, when I use myStr.replace(/^.*\/\/.*\.net\/.*\/(.*)\/.*\z/, otherStr) The result is not as ...

Endless Loop of Http Redirects in Node.js with Express

I need assistance with the code below which is meant to redirect all http traffic to https. // Implement redirect logic to ensure usage of https in production, staging, and development environments app.use((req, res, next) => { // Do not redirect to h ...

The value of a variable remains constant even when it is assigned within a function

I developed a dynamic image slideshow using HTML and JS specifically for the Lively Wallpaper app. This app offers various customization options, which are stored in the LivelyProperties.json file along with input types such as sliders and text boxes. To ...

Is it necessary to have bidirectional relationships in Sequelize?

In my database, I have two existing tables: "user" which contains columns "id" and "depId", and "department" with columns "id" and "name". The column user.depId is a foreign key referencing department.id. Now, I want to create a sequelize model for this r ...

How can Reactjs access a configuration file?

I am struggling to find a solution for reading a properties file in reactJS. I have come across the "properties-reader" module but I can't figure out how to make the require function work. Is there an easier way? For instance, import React, { Com ...

When attempting to execute a query in Node using oracledb, an error with the code 'npm ERR! errno 3221225477' occurred

Encountered the following error message in the command line: npm ERR! code ELIFECYCLE npm ERR! errno 3221225477 npm ERR! [email protected] start: `node ./bin/www` npm ERR! Exit status 3221225477 npm ERR! npm ERR! Failed at the [email protected] start sc ...

Updating a specific property for each object within an array of objects in MongoDB, and inserting the object if it does not already exist

I am looking for a solution to update a property for each object in an array of objects. If some of the objects do not exist, I want to insert the missing objects instead. Currently, I have been using "upsert", which creates a new document when no documen ...

The Highchart feature endOnTick does not properly align with the maximum value set for the x-axis

We're implementing line charts with Highchart's API and have a requirement to end the xAxis scale with the last value provided in the data and display its tick label. Data: [[2014-08-28, .434], [2014-10-17, .234], [2014-11-5, .134], [2015-01-12, ...

Katalon ensures that the browser remains active even when running in headless mode

I have created automation code using Katalon Studio and I am trying to run it in headless mode. I've added the necessary arguments for headless in ChromeOptions. I have also tried executing it in Chrome(headless) mode. However, the browser still open ...

Transferring a variable from a scriplet to JSP with the issue of a null

Seeking assistance with passing a variable from a scriptlet in one jsp to the 'calling jsp' The scenario involves assetedit.jsp posting a binary stream to upload.jsp. However, despite the processing of the stream in upload.jsp and determination ...

Selenium Webdriver Select provides a powerful tool for manipulating

Hey there, I'm having some trouble selecting Canada using Selenium WebDriver in Java with Mozilla. Here is my code: Select select = new Select(driver.findElement(By.id("address.country"))); select.selectByValue("CA"); Unfortunately, it doesn' ...

JavaScript encounters an unexpected identifier: Syntax Error

I encountered a syntax error while executing the code below: var userAnswer = prompt("Do you want to race Bieber on stage?") if userAnswer = ("yes") { console.log("You and Bieber start racing. It's neck and neck! You win by a shoelace!") } else { ...

Exploring the Efficiency of jQuery AJAX and JSON Data Handling

I have implemented a method to store JSON data in a text file for querying using jQuery Ajax on my webpage. Currently, the text file contains approximately 10 facets of data with the potential for an additional 30 facets. This JSON data consists of questio ...

Issue with $watch in Angular Modal not triggering

Having trouble using $watch with a radio button located inside an AngularJS Modal. The $watch doesn't seem to work when the value changes within the modal. If I move the radio buttons outside the modal, the $watch functions as expected. You can see ...