Is there a way to sequentially execute Nightwatch tests in a specific order?

Doing various tests to check the user interface and generate data concurrently.

Another set of tests use this generated data, necessitating them to run only after the initial ones.

I understand about running them as a group or using tags, but how do I ensure they run in a sequential order?

Answer №1

In order to ensure that Nightwatch runs each test within a specific file in the desired sequence, one approach would be to consolidate all tests into a single file while arranging them in the preferred execution order.

However, managing a large number of tests within a single file can become cumbersome. To address this issue, you can leverage Nightwatch's feature of executing test files in alphabetical order. One strategy is to prefix each test file with a numerical value representing the intended run sequence. For instance, if you have two test files named before.js and after.js, and wish for before.js to execute first, you can rename the files as 01before.js and 02after.js. This adjustment will prompt Nightwatch to read the files in accordance with your specified order.

Answer №2

While not perfect, a solution that can be effective is to organize your test files in numerical sequence.

0001_first_test_to_run.js
0002_second_test_to_run.js
...
9999_last_test_to_run.js

Answer №3

To maintain the order of tests and streamline authentication, I devised a method using a "main" test module where I imported the tests in a specific sequence:

Within main.test.js

// importing test modules
const first = require('./first.test.js');
const second = require('./second.test.js');
module.exports = {
    before(){
         // perform login actions, etc.
    },
    'first': (browser) => {
         first.run(browser);
    },
    'second': (browser) => {
         second.run(browser);
    },
}

and in first.test.js

var tests = {
    'google': (browser) => {
        browser.url('https://google.com';
    },
    'cnn': (browser) => {
        browser.url('https://cnn.com';
    }
};

module.exports = {
    // prevent nightwatch from running this test module outside _main
    '@disabled': true,
    'run': (browser) => {
        // execute all functions within tests
        Object.values(tests)
            .filter(f => typeof f === 'function')
            .forEach(f => f(browser));
    }
};

Answer №4

If you possess the files first.js and second.js, then construct a new file named main.js and incorporate all functions existing in these files into main.js.

first.js:

module.exports = {
 'function1' function(browser){
    //testing code
 },
 'function11' function(browser){
    //testing code
  }
}

second.js:

module.exports = {
 'function2' function(browser){
    //testing code
}
}

main.js:

const { function1,function11 } = require('./path/to/first.js')
const { function2 } = require('./path/to/second.js')
module.exports = {
    //execute the functions mentioned in any order you desire
    run: function (browser) {
     funtion1(browser)
     function11(browser)
     function2(browser)
    }
 }

Proceed to launch the main.js file.

Answer №5

A solution to the issue can be found at this link: https://github.com/nightwatchjs/nightwatch/issues/649. This solution allows nightwatch to execute tests sequentially rather than in parallel. To implement this, simply disable test_workers in the configuration file by changing "true" to "false" as shown below:

{
  "test_workers": {
    enabled: false,
    workers: 'auto'
  }
},

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 Selenium and Celerity: Which is the better choice?

Why opt for Selenium over Celerity when testing web sites? Real browsers like Firefox, Safari, Chrome, and Internet Explorer can be used with Selenium to ensure website compatibility with each of them. If I utilize Celerity (a Java browser), even if all t ...

What is the best method for removing a class with JavaScript?

I have a situation where I need to remove the "inactive" class from a div when it is clicked. I have tried various solutions, but none seem to work. Below is an example of my HTML code with multiple divs: <ul class="job-tile"> <li><div ...

Using Scalable Vector Graphics (SVG) in HTML

I am attempting to insert an SVG vector graphic into my HTML document. The SVG file I want to use can be found here: I was able to load it like this: <embed src="images/grafica-2.svg" type="image/svg+xml"/> However, the issue is that it only load ...

Javascript inheritance through prototypes results in the addition of supplementary attributes within the descendant classes

When dealing with inheritance in JavaScript, I often encounter a issue where derived classes contain duplicate properties of the base class. And yet, I struggle to understand how to ensure that the derived class leverages the properties of the base class p ...

Error: The function `push` cannot be used on the variable `result` (TypeError)

Here is a snippet from my react component const mockFetch = () => Promise.resolve({ json: () => new Promise((resolve) => setTimeout(() => resolve({ student1: { studentName: 'student1' }, student2: { studen ...

Stream audio smoothly with icecast audio.js without any delays

I have set up an icecast server on my system, and the clients connecting to it will be embedded in web pages using either HTML5 or Flash. Currently, I am utilizing audio.js with a flash fallback for this purpose. The issue at hand is that the audio and a ...

Guide to obtaining scope within a nested directive

My problem lies in a nested directive within my code. I am attempting to pass a function from the nested directive to my controller, but for some reason, the function is not being triggered. Here is an excerpt of my main directive HTML: <div class="pa ...

What is the best way to retrieve the most recent CMS posts information within a Gatsby-constructed project?

I created a static website using Gatsby and everything was working well. However, I encountered an issue when updating the titles and content of posts in Contentful CMS - the changes were not reflected when I refreshed the website. How can I ensure that ...

Keeping state between navigations in Ionic and AngularJS: A guide

In the process of developing my very first hybrid mobile application using Ionic and AngularJS, I have encountered a challenge that I am currently trying to resolve. The issue at hand involves maintaining the state of the graphical user interface between n ...

Retrieve information through an AJAX or JavaScript request and use it to fill the selected plugin's multiple selection feature

I have searched everywhere for a solution to this problem, but I haven't been able to find any helpful resources. I apologize in advance if this question has been asked before. What I need to do is to display the data from a JSON object that is fetch ...

Easy-peasy AJAX bookmarking

One of my tasks involves displaying a list of items on a webpage with the use of PHP. I am looking to incorporate a straightforward AJAX toggle feature that will allow users to bookmark an item from the list while they are exploring. If the item's bo ...

Updating the error state of a TextField Component in React MaterialUI upon clicking a button

After clicking a 'search' button, I want to validate input fields in my input form. Many solutions suggest validating the input live as it is entered, but I prefer not to do this because some of the validation processes are costly operations, su ...

Is there a way to increase the total of each row by two when a button is clicked?

Looking to enhance the sum of each row by two depending on whether a button is clicked. HTML: <table> <tr> <td> <input type="checkbox" class="prof" name="prof" value="0"> <input class=&quo ...

What is the best way to trigger dependent APIs when a button is clicked in a React Query application

On button click, I need to call 2 APIs where the second query depends on the result of the first query. I want to pass data from the first query to the second query and believe using "react-query" will reduce code and provide necessary states like "isFetch ...

Is it advisable to approve automatic pull requests initiated by dependabot for updating the yarn.lock file?

I've recently received some pull requests from "dependabot" in a JavaScript library I am working on, like the one found here. While I appreciate the effort to update dependencies to newer versions, it seems strange that each PR only updates the versi ...

Vercel enables faster PAAPI transactions through Edge Caching

When working on a Nextjs site hosted on Vercel and making a call to Amazon's paapi, it's important to keep in mind the limitations imposed by Amazon on the number of transactions allowed per second and per day. The approach I'm taking involv ...

The issue of Select2 with AJAX getting hidden behind a modal is causing

I'm currently facing an issue with Select2 within a modal. The problem can be seen here: https://gyazo.com/a1f4eb91c7d6d8a3730bfb3ca610cde6 The search results are displaying behind the modal. How can I resolve this issue? I have gone through similar ...

When using Jquery, hovering over an element will cause the full title to be

I have created a toggle div that displays an ellipsis (...) when the long title is longer than 30 characters. Now, I want the full text of the long title to appear when hovering over the div. Check out this JS Fiddle for reference. JS $('#popu ...

Allowing Angular2 Components and their Sub Components to access a shared instance of ngModel within a service

Currently, I have been working on constructing a complex view that requires multiple functionalities. To ensure proper organization, I have divided it into various custom components. I don't want to go into great detail, but I have managed to make it ...

transferring information between controllers after successful SSL connection

My goal is to efficiently pass data between controllers after each successful HTTP request. This is the current hierarchy: <div ng-controller="ParentCtrl as parent"> <div ng-controller="ChildOneCtrl as chi1"></div> <div ng-contr ...