Adjusting BackstopJS - Each scenario file is interpreted as an individual scenario rather than a group of scenarios in the configuration file

As I strive to scale BackstopJS by breaking down the original backstop.json file into a directory of structured scenario JSON files, I'm encountering an issue where the function in my config file interprets each JSON file as a single scenario instead of a collection of scenarios as intended.

In my config file (backstop.js):

var fs = require ('fs');
var allScenarios = [];

function loadScenarios (dirname, onError) {
    var files = fs.readdirSync(dirname);
    console.log(dirname);
    files.forEach (function (file) {
        content = fs.readFileSync(dirname + file, 'utf-8');
        allScenarios.push(JSON.parse(content));
        console.log("content");
    })
}

loadScenarios ('scenarios/',
    function (err) {
    throw err
    }
)


module.exports = {
    "id": "Scaled_Backstop",
    "viewports": [
        {
        "label": "desktop",
        "width": 1600,
        "height": 1024
        }
    ],
    "onBeforeScript": "puppet/onBefore.js",
    "onReadyScript": "puppet/onReady.js",
    "scenarios": allScenarios,
    "paths": {
        "bitmaps_reference": "backstop_data/bitmaps_reference",
        "bitmaps_test": "backstop_data/bitmaps_test",
        "engine_scripts": "backstop_data/engine_scripts",
        "html_report": "backstop_data/html_report",
        "ci_report": "backstop_data/ci_report"
      },
    "report": ["browser"],
    "engine": "puppeteer",
    "engineOptions": {
        "args": ["--no-sandbox"]
      },
    "asyncCaptureLimit": 5,
    "asyncCompareLimit": 50,
    "debug": false,
    "debugWindow": false
}

Within the scenarios directory, there are distinct JSON files storing scenarios. Here's an example from sample-one.json

{
  "scenarios": [
    {
      "label": "UltimateQA - Section of buttons-Title",
      "url": "https://ultimateqa.com/complicated-page",
      "delay": 1000,
      "postInteractionWait": 1000,
      "selectors": ["#Section_of_Buttons"],
      "selectorExpansion": true,
      "misMatchThreshold": 0.1,
      "requireSameDimensions": true
    },
    {
      "label": "UltimateQA - Section of buttons-ButtonSection",
      "url": "https://ultimateqa.com/complicated-page",
      "delay": 1000,
      "postInteractionWait": 1000,
      "selectors": [".et_pb_row.et_pb_row_2.et_pb_row_4col"],
      "selectorExpansion": true,
      "misMatchThreshold": 0.1,
      "requireSameDimensions": true
    },
    {
      "label": "UltimateQA - Section of buttons-LoginForm",
      "url": "https://ultimateqa.com/complicated-page",
      "delay": 1000,
      "postInteractionWait": 1000,
      "selectors": [".et_pb_module et_pb_login et_pb_login_0 et_pb_newsletter clearfix  et_pb_text_align_left et_pb_bg_layout_dark"],
      "selectorExpansion": true,
      "misMatchThreshold": 0.1,
      "requireSameDimensions": true
    },
    {
      "label": "UltimateQA - Section of buttons-ToggleForm",
      "url": "https://ultimateqa.com/complicated-page",
      "delay": 1000,
      "clickSelectors": [".et_pb_toggle_title"],
      "postInteractionWait": 1000,
      "selectors": [""],
      "selectorExpansion": true,
      "misMatchThreshold": 0.1,
      "requireSameDimensions": true
    },
    {
      "label": "UltimateQA - Section of buttons-TwitterButton",
      "url": "https://ultimateqa.com/complicated-page",
      "delay": 1000,
      "clickSelectors": [""],
      "postInteractionWait": 1000,
      "selectors": [".icon et_pb_with_border"],
      "selectorExpansion": true,
      "misMatchThreshold": 0.1,
      "requireSameDimensions": true
    }
  ]
}

Upon running

backstop test --configPath=./backstop.js
, BackstopJS shows it has only selected 3 scenarios out of the 11 scenarios across 3 files. It appears that the function is simply reading individual files as scenarios, not as collections of scenarios.

Am I overlooking a step in iterating through the files, or is there a different aspect that I'm missing entirely?

I initially considered using fetch, but implementing any fetch function to run BackstopJS proved unsuccessful.

While opting for 'fs' did run BackstopJS, I seem to be missing a crucial step in iterating through the files, as each file is being read as an isolated scenario, rather than part of a collection of scenarios.

Could it be an issue with the object orientation in JSON, where the same object cannot be declared in different files?

If anyone has a successful example of scaling a BackstopJS project with improved scenario organization and advanced functionality such as dynamic URLs and test flags, I am open to exploring alternative approaches. Enhancing BackstopJS functionality is my primary goal at the moment.

Thank you for your time and any insights!

Answer №1

My latest project focuses on scalability and utilizes YAML instead of JSON for test cases. This innovative approach has been embraced as a standard tool within my department, being integrated into multiple enterprise-level projects. Feel free to explore it and see if it aligns with your needs:

Check out the documentation here:

For access to the repository under the MIT license, visit:
https://github.com/precise-alloy/regression-test

If you prefer a different structure, the code in the repository can serve as a valuable reference for organizing test suites into separate files.

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

Issue with AMCharts: DateAxis on my XY graph unexpectedly zooms out to the year 1970 when stacked

Currently, I am attempting to display multiple processes throughout a single day on an AMChart XY axis. Everything seems to be functioning correctly initially, but as soon as I stack the data, the timeline unexpectedly zooms out all the way to 1970. Howev ...

Instructions for setting attributes on the ngForm object within a component class

My form data is represented as a JSON string using JSON.stringify(form.value) and it currently looks like this: "body":{ "panNo":"IRFPP1993A", "ackNo":"123456789" } I would like to modify the output to include an additional value, making it look like thi ...

Tips for creating a seamless horizontal scrolling effect in Angular when hovering (automatically)

One of the components I'm working on features a gallery with an X axis orientation. <div class="gallery"> <div (mouseenter)="scrollTo('left', $event)" (mouseleave)="clearIntervalRepeater()" class="left"></div> < ...

Tips to store Google fonts in the assets directory

I've included this link in my styles.scss @import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;600;700&display=swap'); While it works locally, the API fails on production or is blocked. How can I host it within my p ...

"Executing ng-click directive on a second click changes the route in AngularJS

Why does my ng-click only redirect to a new location on the second click? It should redirect to $location.path('/login.signin');, but it only works if I click the button again. It's strange. Where could this issue be originating from? Belo ...

Is there a way to use lodash to convert an array into an object?

Below is an array that I am working with: const arr = [ 'type=A', 'day=45' ]; const trans = { 'type': 'A', 'day': 45 } I would appreciate it if you could suggest the simplest and most efficient method to ...

Error: Cannot access the length property of an undefined value in the JEST test

I'm currently working on incorporating jest tests into my project, but I encountered an error when running the test. The issue seems to be related to a missing length method in the code that I am attempting to test. It appears to be originating from s ...

Positioning the comments box on Facebook platform allows users to

Need assistance, I recently integrated the Facebook comments box into my Arabic website, but I am facing an issue where the position of the box keeps moving to the left. Here is an example of my website: Could someone please suggest a solution to fix the ...

Setting field names and values dynamically in MongoDB can be achieved by using variables to dynamically build the update query

I am working on a website where users can place ads, but since the ads can vary greatly in content, I need to be able to set the field name and field value based on user input. To achieve this, I am considering creating an array inside each document to sto ...

A URL that quickly updates live content from a backend script

As a beginner, I am seeking guidance as to where to start on my journey of learning. I need assistance in creating a script that can efficiently fit within a small URI space and constantly updates itself with information from a server script. My target bro ...

Sending information to a PHP script using Ajax

I am working on a project that involves input fields sending data to a PHP page for processing, and then displaying the results without reloading the page. However, I have encountered an issue where no data seems to be passed through. Below is my current s ...

Is there a way to adjust the border color of my <select> element without disrupting the existing bootstrap CSS styling?

In my Bootstrap (v4.5.3) form, the select options appear differently in Firefox as shown in the image below: https://i.sstatic.net/3suke.png Upon form submission, I have JavaScript code for validation which checks if an option other than "-- Select an Op ...

Searching for specific data within an embedded documents array in MongoDB using ID

While working with mongodb and nodejs to search for data within an embedded document, I encountered a strange issue. The query functions as expected in the database but not when implemented in the actual nodejs code. Below is the structure of my data obje ...

Preserve HTML element states upon refreshing the page

On my webpage, I have draggable and resizable DIVs that I want to save the state of so they remain the same after a page refresh. This functionality is seen in features like Facebook chat where open windows remain open even after refreshing the page. Can ...

Guide to developing a reusable component or partial in react.js

My first experience with React.js involved a relatively simple task. I started by creating an app.js file that loads the initial page, containing my navigation menu and rendering the children props. However, I realized that instead of keeping the navigat ...

A guide on scheduling automatic data insertion in mongoose.js

I'm working on a website with Node.js and Mongoose, and I could use some guidance on how to automatically insert data into Mongoose with Node.js at specific times. For example, at the end of each month, I want my current data to be stored in the Mongo ...

I need to know the right way to send a file encoded in Windows-1255 using Express

I'm currently developing an API that is responsible for generating text files. The purpose of this API is to support legacy software that specifically requires the use of Windows 1255 encoding for these files. To create the content of the file, I am r ...

What is the method employed by the script to ascertain the value of n within the function(n)?

I've recently started learning about jQuery. I came across a program online that uses a function where the value of n starts from 0 and goes up to the total number of elements. In the example below, there is only one img element and jQuery targets thi ...

Adjusting the size of <nav> element to accommodate its child elements

I've exhausted all possible CSS solutions today in an attempt to make my parent nav tag home-main-nav-menu resize based on its children and grandchildren, but it just won't cooperate. If anyone could provide a clear explanation on how to solve th ...

Issue with custom validator in Angular 6: setTimeout function not functioning as expected

Currently, I am in the process of following a tutorial to implement Asynchronous validation in Angular. The goal is to create a custom validator named shouldBeUnique that will be triggered after a 2-second delay. To achieve this, I have utilized the setTim ...