'How to pass env and TAGS together in cypress command

How can we pass the env and tags together using command line argument in cypress?

I have the feature file with Scenario:

@prodSmoke
Scenario: Test
    Given The user is on home page
    And The user click on login

This is my package.json file from where I am requesting to run only the prodSmoke tag:-

"scripts": {
   "e2e:run:dev": "npx cypress open --env fileConfig=dev -e TAGS=\"@prodSmoke\""
}

When I run this using command :-

npm run e2e:run:dev

It is not selecting the dev env. It always runs in qa env only. Because this config.env.fileConfig particular line of code doesn't return any value.

Though I have dev.json file created in config folder and below is the index.js file :

 require("dotenv").config();
 const cucumber = require("cypress-cucumber-preprocessor").default;
 const fs = require("fs-extra");
 const path = require("path");
 
 getConfigurationByFile = (file) => {
   const pathToConfigFile = path.resolve("cypress", "config", `${file}.json`);
   return fs.readJson(pathToConfigFile);
 }
 
 module.exports = (on, config) => {
   on("file:preprocessor", cucumber());
   const file = config.env.fileConfig || 'qa' 
   return getConfigurationByFile(file);
   
 };

If I do not use the TAGS in the command, then it is selecting the env as mentioned in the command:

"scripts": {
   "e2e:run:dev": "npx cypress open --env fileConfig=dev"
}

Above command works perfect.

I am pretty sure it's an issue with the TAGS variable which is not letting the config.env.fileConfig to resolve properly and which is because it always runs the scripts in qa.

Can anyone help me out here?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source