Issue encountered when attempting to run specific Nightwatch.js tests individually

I'm encountering an issue where I can only run individual nightwatchjs tests when using the absolute path of the test script.

For instance, if I execute my test from the following directory;

/Users/darrenharley/Documents/Git/uk-content-parkers/Tests/Functional/tests

using the command;

npm run test:live /Users/darrenharley/Documents/Git/uk-content-parkers/Tests/Functional/tests/current_functionality/gamAds/PAR-5139.js

It runs successfully.

However, I require running this test without relying on my local file structure (as it will eventually be triggered via a Jenkins build so the absolute path cannot be used).

If I try to run the test with the following command;

npm run test:live ./current_functionality/gamAds/PAR-5139.js

It fails and returns the error message;

Error: ENOENT: no such file or directory, stat './current_functionality/gamAds/PAR-5139.js'

Am I making an obvious mistake here?

As a reference, in my nightwatch.conf.js file, I have specified this;

 src_folders: [
    'tests/',
  ],

and in my package.json file, the relevant script is defined as;

"test:live": "nightwatch --config config/nightwatch.conf.js --env live --suiteRetries 3",

Any assistance would be welcome, as I find it frustrating that something so basic is causing such trouble.

Thank you in advance.

Answer №1

Initially, the lack of information about your Jenkins job makes it difficult to provide an accurate solution (Where is the NPM command initiated from? What is the project root directory?). It would be advisable to insert a pwd command before executing the NPM call to identify the project root location and adjust the command accordingly.


NOW ...

For your current task, the simplest (and most organized) method involves utilizing NightwatchJS test groups & test tags.

❒ Employing test tags:

module.exports = {
  '@tags': ['PAR-5139', 'live', 'smoke'],
  'This is the PAR-5139 test': function (browser) {
     // > your code here <
  }
};

To implement this logic, update your command to:

npm run test:live -- --tag PAR-5139
(Please ensure to add -- before additional NightwatchJS switches for proper parameter separation between npm command and script parameters.)

❒ Using test groups:

Consider the following tests structure:

tests/
  ├── current_functionality
  |   └── PAR-5139.js
  ├── critical_functionality
  |   └── PAR-5140.js
  |   └── PAR-5141.js
  └── dated_functionality
      ├── OLD-90210.js
      └── OLD-NO7-BRAND-SOUR-MASH.js

To apply the concept, modify your command to:

npm run test:live -- --group current_functionality
.

The group switch accepts multiple folders in one command:

npm run test:live -- --group current_functionality,critical_functionality

!Note: Remember, you can utilize the --skipgroup switch (to exclude certain test folders) or disable specific tests with the 'disabled' attribute set to true:

module.exports = {
  '@disabled': true, // Prevents this test module execution.
  'Skipping this PAR': function (browser) {
    // > your code here <
  }
};

Answer №2

The issue lies in the path provided. It is essential for the path to be relative to the root directory. Relative paths are referenced based on the root directory (where the package.json file is located at the top level).

Consider the following directory structure:

root
--tests
----PAR-5139.js
----
--src
--config
----nightwatch.config.json
--package.json

To run the command, use

npm run test:live ./tests/PAR-5139.js
, regardless of whether you execute it from within the tests folder or the root directory.

In your scenario, although the command is executed from the tests folder and the path is specified relative to that folder, the command is searching for the file relative to the root directory rather than the tests folder.

I hope this explanation clarifies things for you. Feel free to reach out if you have any questions.

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

How can I retrieve information from an object using Mongoose queries?

Looking to retrieve data for all users with cardNumber: 3243 using the provided mongoose model. cred: { nameValue: 'anonymous', emailValue: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1879767776617 ...

Guide: Passing and reading command line arguments in React JavaScript using npm

When launching the react application, I utilize npm start which is defined in package.json as "start": "react-scripts start -o". Within the JavaScript code, I currently have: const backendUrl = 'hardCodedUrl'; My intention ...

Having trouble converting Buffered Byte Array into Image in Browser

Hello there! I am currently facing an issue while attempting to generate an image from a buffered byte array. The reason behind this is that I need to transfer the image from the server to the client using JSON. Below is the code snippet in question: The ...

Is there a way to handle two separate ajax requests located within different script tags?

I am facing an issue with my page that has 3 dropdowns and 1 submit button. Upon selecting a value from the top dropdown, the rest auto-populate using ajax. However, when I try to submit the information using the submit button, the second ajax call does no ...

Tips for querying orchestrate.io

Recently, I found myself in need of a user-friendly database for a small highscore system in my game development projects using JavaScript. Through the Github student developer pack, I came across Orchestrate.io. After discovering a suitable driver module ...

Oops! We encountered an issue trying to find the "list" view in the views directory

Here are the images I have: This is the code for my app.js file And this is the code for list.ejs located in the views directory Unfortunately, my index.html file is empty. Below is the full error log: Error: Failed to lookup view "list" in the views di ...

Exploring Nashorn's capabilities in parsing TypeScript

Recently, I came across a discussion suggesting that Nashorn in JDK 9 should have the capability to parse TypeScript. Excited to try it out, I attempted to use it like this: Parser parser = Parser.create(); CompilationUnitTree ...

Issue with Node Webpack identifying the "Import" statement

I'm diving into the world of Node and Webpack, but I'm struggling with getting my project to compile properly. Every time I try to load it in the browser, I encounter the error message: Uncaught SyntaxError: Unexpected token import. Let me share ...

Deleting a child in Three.js: A step-by-step guide

I connected a child to three different meshes using the following function: .add() Is there a specific method I can use to remove the child from one of the meshes? ...

Error: Module not located or Image unable to load in React JS

Here is the structure of my project : src -assets fut.png -components -admin_dashboard Sidebar.js -App.js -pages Dashboard.js I encountered an issue trying to load the image fut.png from the file Sidebar.js. Even after attempting ...

Solution for handling pointer events in Safari iOS when they are not supported

https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/pointerdown_event Hello! I have successfully implemented code for a long click, however, the pointer event api is not fully supported in Safari as it is still under development. Is there a simp ...

My Node/Express service seems to be generating a span in the logs, but I am unable to locate my service in the Ja

Currently, I am in the process of setting up Jaeger tracing for my Node.js microservice using Express.js. After adding a basic GET request handler in my Express app and hitting the endpoint via curl, I notice that a span is created in the logs. However, w ...

Retrieving values of objects based on array keys

Hey everyone, I have a question that might seem silly, but I'm feeling stuck and could use some assistance. So, I have two sets of data - one is an object structured like this: var userData = { "2_6": { "name":"John Doe", "location":"New ...

Building Your Own Array Object in JavaScript

Yes, it may seem crazy at first glance, but let me clarify things a bit. When using Jquery, for instance $('div'), it returns an Array Collection similar to this: [div#container, div#header, div#logo]. The interesting part is that primitive Arra ...

Expand the width of the div by a specified amount with each click

Greetings Everyone! I've scoured the internet high and low in search of a solution, but I have yet to come across exactly what I need. The Issue at Hand My goal is to expand the width of my Div every time I click on my Button. All I have is my DIV ...

Correctly managing variables in HTML

Within my HTML code, I am retrieving a value from a file and using it as a link. The code snippet looks like this: <a href="{{ var('page').value }}">page</a> Now, when the link is clicked, I want to display a popup window with the c ...

JavaScript: Update missing values in an array by assigning the average of its neighboring values

Consider the following array: [5,2,null,5,9,4] To replace the null value with the average of the previous and next values (2 and 5), you can do the following: [5,2,3.5,5,9,4] If there are consecutive null values in an array: [5,2,null,null,9,4] You c ...

Error code E401 is being encountered with npm, indicating either an incorrect password has been provided or the

My Node version is 10.15.0 and my NPM version is currently at 6.8.4. After updating npm to 14.16.0 and node to 7.6.2, I encountered the following error - npm ERR! code E401 npm ERR! Incorrect or missing password. npm ERR! If you were trying to log in, ...

Generating hidden form fields dynamically with AngularJS

In the midst of developing an AngularJS application, I'm faced with a requirement to pass hidden variables to a third-party application. These variables need to be fetched from a database. To accomplish this, I've implemented the following code ...

JSON has encountered an unconventional string at position 41 that was not anticipated

Attempting to learn Javascript as a beginner, I am facing an error that is puzzling me: SyntaxError: /home/runner/myrepl/config.json: Unexpected string in JSON at position 41 Upon checking my index.js file, it seems correct at position 41 (at least I beli ...