TestCafe Environment Variables are not properly defined and displaying as undefined

Exploring TestCafe and diving into the world of automated testing.

Trying to master the tools with guidance from

Successfully executing code on my Windows setup!

fixture`Getting Started`.page`http://devexpress.github.io/testcafe/example`;

test("My First Test", async t => {
    await t
    .typeText('#developer-name', 'John Smith')
    .click('#submit-button')
    .takeScreenshot();

    const articleHeader = await Selector('.result-content').find('h1');
    
    // Retrieve the text of the article header
    let headerText = await articleHeader.innerText;
    console.log(process.env.DEV_MODE);
});

This is how my Scripts Section looks:

"scripts": {
    "setnode": "set DEV_MODE=staging",
    "test:chrome": "npm run setnode & npx testcafe \"chrome --start-fullscreen\" e2e/tests"
  }

Upon running the command npm run test:chrome

The output appears as follows:

<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="295c40045d4c5a5d4a4845467b5811000c2f3b374899343839">[email protected]</a> setnode C:\TestCafeProjects\ui-testcafe-poc set DEV_MODE=staging

 Running tests in:
 - Chrome 79.0.3945.130 / Windows 10

Getting Started  

undefined   

√ My First Test

The mystery perplexes me: why does console.log show undefined instead of staging?

Answer №1

To ensure your scripts run sequentially instead of in parallel, make use of the && operand rather than the ampersand symbol (&).

It's worth noting that npm scripts execute the shell process in the background (cmd on Windows), and any variables set using the set command are scoped to their own session only. Consider updating your script to:

"scripts": {        
    "test:chrome": "set DEV_MODE=staging && npx testcafe \"chrome --start-fullscreen\" e2e/tests"
}

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 transfer data to a node in Node-RED using a specified setup and then access the setup again at a later point?

Currently, I am utilizing Node-RED on Bluemix and would like to enable users to upload a document. Below is the relevant code snippet within a function/template of a flow: <form action="/upload" method="POST"> <h1>Upload PDF</h1> &l ...

Issues with the w3c validator are preventing proper validation due to an unsuccessful SSL connection attempt

Everything seems to be running smoothly on my website when viewed in the browser. However, when I try to validate it using the W3C validator, I keep encountering an error message. https://i.stack.imgur.com/IGOA0.png Before reaching out here for help, I s ...

Issues arise after upgrading Node and npm, causing an inability to execute any npm command

Following an upgrade to the latest Node and npm version, I encounter an error when attempting any npm command: C:\Users\...>npm doctor TypeError: Cannot read property 'prefix' of undefined at parseField (C:\Users&bs ...

Node package command execution failing on Ubuntu 12.04 Real-Time System

I recently developed an npm package called docxgen, and here is the content of the package.json: { "name": "docxgen", "version": "1.0.5", "author": "Hans Thunam <<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3e565f50 ...

Navigating through embedded arrays in Angular

JSON Object const users = [{ "name":"Mark", "age":30, "isActive" : true, "cars":{ Owned : ["Ford", "BMW", "Fiat"], Rented : ["Ford", "BMW", "Fiat" ...

Ionic 4's http.get.subscribe method fails to retain the retrieved value

I'm aware this might be a repeated question, but I haven't come across a straightforward answer yet, so here it goes. Below is the code snippet in question: fetchData() { let dataArray: Array<any> = [, , ,]; this.prepareDataReque ...

No matching record found with the given id in Mongoose

I'm attempting to retrieve a record by its id but I'm facing some issues. var id = req.param('id'); var item = { '_id': id } videos.find(item, function(error, response) {}); Even though I have provided a valid id, it&apo ...

Angular 2 decorators grant access to private class members

Take a look at this piece of code: export class Character { constructor(private id: number, private name: string) {} } @Component({ selector: 'my-app', template: '<h1>{{title}}</h1><h2>{{character.name}} detai ...

Having trouble establishing a connection between the client and server while using Node.js with socket.io, Express, and an HTML file

While following a tutorial on YouTube for creating a simple web game with lobbies/rooms, I encountered an issue. When attempting to establish a connection between the client and server, the expected "a user connected" text did not show up in the console as ...

Even if the user is logged out of the website, Socket.io authorization remains persistent

I have successfully integrated the express-socket.io-session into my app and it is working as expected. However, I have encountered a specific issue. Please see the code snippet below: io.use(...); io.sockets.on("connection", function (socket) { soc ...

Creating a unique user interface for VSCode extension

Recently, I've delved into the world of developing extensions for Visual Studio. Unfortunately, my expertise in TypeScript and Visual Studio Code is quite limited. My goal is to create an extension that mirrors the functionality of activate-power-mod ...

Breaking down an object using symbols as keys in Typescript

I'm encountering an error when running this code Type 'symbol' cannot be used to index type '{ [x: string]: string; }'.: let symbol = Symbol() let obj = { [symbol] : 'value'} let { [symbol]: alias } = obj // ...

What is the method for obtaining the latitude and longitude of a location close to a given pair of

Currently working on a node.js application that utilizes express and mongodb. I am looking to fetch the latitude and longitude coordinates near a specific set of geographic coordinates. Curious about the necessary steps or techniques I should employ to a ...

What serves as the pip counterpart to package.json?

While I am familiar with the requirements.txt file, it only lists dependencies. However, I'm interested in other metadata such as package name, author, and main function. Is there a standard format for this information? I've heard of the setup.p ...

Tips for resolving rendering page issues in an express app

My application is a straightforward blog platform that showcases a schema for the title, entry, and date of each blog post. There is also an edit/delete feature that is currently under development. When attempting to use the edit/delete button on a selecte ...

Can you modify a specific column in a table using mat-table in Angular material?

For my project, I am utilizing Angular Material's table to present data in a tabular format. However, due to a new requirement, I now need to enable in-line editing for the last 2 columns alongside highlighting another column when the user clicks on t ...

What is the proper way to access the global `angular` variable in Angular and TypeScript when using AngularJS?

I'm currently integrating an Angular 4 component into a large monolithic AngularJS application. The challenge I face lies in the restrictions of the AngularJS project's build system, which limits me to only modifying the project's index.html ...

Error: Running the command 'yarn eg:'live-server'' is not a valid internal or external command

Currently, I am utilizing yarn v1.6.0 to manage dependencies. I have globally installed live-server by running the following command: yarn global-add live-server However, upon executing it as live server, I encounter the following error: 'live-ser ...

React dependency installation problem encountered

npm install axios moment react-file-base 64 redux redux-thunk npm ERR! 404 npm ERR! 404 Note that you can also install from a npm ERR! 404 tarball, folder, http url, or git url. npm ERR! A complete log of this run can be found in: C:\Users\apa10 ...

Do Not Activate the Android App with Deeplink in Ionic3

I'm currently using the ionic-plugin-deeplinks to enable deep linking within my app. Here are the steps I followed: $ ionic cordova plugin add ionic-plugin-deeplinks --variable URL_SCHEME=myapp --variable DEEPLINK_SCHEME=https --variable DEEPLINK_HOS ...