Tips for successfully passing a parameter to the --world-parameters or npm run command for it to be utilized by scripts within the package

Although there are similar questions already asked, I still have a specific scenario that I need help with:

In the example I am working on, I am using this repository and I have a script block in my package.json as follows:

I want to be able to pass a parameter from the command line to specify the environment for testing, something like:

-- testEnv=staging

How can I modify the script block below to accommodate this change?

I have attempted to set different configurations for the world parameter like so:

 --world-parameters \"{\\\"environment\\\": \\\"Dev\\\"}\"

However, managing multiple versions of world parameter configurations has become confusing, so I am looking to use command line to send variable values through instead.

"scripts": {
             "test-chrome": "./node_modules/.bin/cucumber-js.cmd --tags @Run --format json:./testlab/support/reports/report.json",
}

Answer №1

TestCafe provides the ability to utilize environment variables and maintain a config.json file where you can store the baseUrl:

For example, you could execute the following:

export testEnv=staging
npm run test-chrome

Then include that value in your configuration file.

{
    baseUrl: process.env.testEnv
}

Alternatively, if you prefer a default baseUrl, you can create a helper class that simply returns

const targetUrl = process.env.testEnv || config.baseUrl
.

Answer №2

As of the release of version 1.20.0, TestCafe now allows users to define the base URL for test pages across all interfaces:

  • Command Line Interface (CLI)
  • Programmatic API with runner.run({baseUrl})
  • Configuration File

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

Error: unable to locate the react-redux context value; make sure the component is enclosed in a < Provider > tag

import React, { Component } from 'react' import { createStore } from 'redux' import { Provider, connect, useSelector } from 'react-redux' function rootReducer(state = { name: 'store' }, action) { return state ...

An error has occurred: Angular is unable to recognize the expression for ng-click and is throwing a syntax error

It's driving me crazy. The code is working fine, but I keep getting this error in the console. The line of code is part of an accordion menu created using Angular and UI-Router. <li ng-repeat="item in group.items"><a ng-click="setActiveView( ...

What is the best way to store global NPM packages in the cache on Travis CI?

When it comes to caching locally installed packages, you can achieve this by following the instructions in your .travis.yml file: # .travis.yml ... cache: directories: - node_modules ... However, what about caching globally installed packages ($ npm ...

The Vue3 property 'x' is not recognized on type 'Function' as a global property

I have encountered a strange issue with my Quasar app. I am attempting to define a global variable that consists of metadata about the application in an object format. Despite successfully compiling the app and displaying the correct information on the HTM ...

Designing versatile buttons with HTML

When accessing the website on a phone, I have trouble seeing and tapping on these two buttons because they are too far apart. I would like to change it so that once a file is selected, the 'choose file' button will be replaced by the upload butto ...

Discovering a website's console content using the "web-request" npm package

I recently added the web-request NPM package to my project with the goal of retrieving console messages from a specific website. However, I encountered an issue as I was unsure of how to achieve this. var result = await WebRequest.get('http://disco ...

How can I retrieve an array of data from Firebase Firestore using React Native?

I have been working on fetching Array data from Firebase Firestore. The data is being fetched successfully, but it is all displaying together. Is there a way to fetch each piece of data one by one? Please refer to the image for a better understanding of ...

Issue with popup display in React Big Calendar

I'm currently working on a calendar project using React-Big-Calendar, but I've run into an issue with the popup feature not functioning properly. <div className={styles.calendarContainer} style={{ height: "700px" }}> <C ...

Developing a Customized Styling Guide Using Node.JS and User Specifications

Seeking a method to generate a personalized user style sheet utilizing input from users. Users can choose options like background colors, and the app will generate a custom style sheet based on their selections. Their input will be captured through HTML in ...

Highlighting text within ReactJS using Rasa NLU entities

Currently, I am working on a React application that retrieves data from the Rasa HTTP API and displays it. My goal is to tag the entities in a sentence. The code functions correctly for single-word entities but encounters issues with two-word entities (onl ...

Error in semantic release: Unable to retrieve the name property as it is undefined

While attempting to release a package from my app, I encountered an error during the publish step: [2:28:46 PM] [semantic-release] › ℹ Running semantic-release version 18.0.0 [2:28:46 PM] [semantic-release] › ✔ Loaded plugin "verifyCondition ...

How should .has(), .get() and .set() be properly implemented for a JavaScript Map() within an ExpressJS server?

Feeling thrown off by javascript Map()? My query revolves around javascript Map() - the set, get, and has() functions. Despite thinking I was an expert, it seems I still have things to learn... Situation: I'm dealing with a 'global' map sto ...

Issue with Selenium webdriver functionality in Electron development build

I've been working on an Electron project where I render an HTML page with a button that, when clicked, triggers a Node.js script (via IPC) using Selenium to scrape webpages. Here is the structure of my project: -app/ --index.html --ma ...

JavaScript API for Tableau

Could you please clarify the functions described below? newViz = createTableauViz(containerDiv, url, options); function listenForMarkSelection() { newViz.addEventListener(tableau.TableauEventName.MARKS_SELECTION, handleMarksSelection); } funct ...

An effective method to showcase the HTML content retrieved by getElementsByClassName using JSON.parse()

Can someone help me modify this code so that it displays the value of favFood? It currently works with getElementById but not getElementsByClassName, and I want to use a class: server file - ProcesssingFileOnServer.php: <?php $myObj = new stdClass(); ...

Tips for locking the button in the navigation bar while scrolling

I noticed that when I have 6 fields in my navbar, with 5 of them being links and one as a dropdown, the scrolling of the page causes all fields to remain fixed except for the dropdown field.Check out this image description for reference https://i.stack.im ...

Include the JS file after finishing the control processing

I've been grappling with an issue for several days now. The view I have is populated by my controller through an API call, which works perfectly fine in rendering the HTML. $http.get(url). success(function(data, status, headers, config) { ...

Error encountered when extending Typography variant in TypeScript with Material UI v5: "No overload matches this call"

Currently, I am in the process of setting up a base for an application using Material UI v5 and TypeScript. My goal is to enhance the Material UI theme by adding some custom properties alongside the default ones already available. The configuration in my ...

tips for selecting various API requests based on the selected drop down menu choice

Hey there! I'm looking to enhance my login page by adding a feature that allows users to select from a dropdown menu with different options. Each option will be linked to a specific API, and based on the API response, the user's ability to log in ...

Unable to retrieve the JSON response item

Currently, I am in the process of setting up an AJAX call with the intention of manipulating the response data. Upon inspecting my browser's network console, this is the response I am seeing: { "message": "success", "file": "dump.xml" } Thi ...