0

我们如何使用 cypress 中的命令行参数一起传递 env 和标签?

我有场景的功能文件:

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

这是我要求仅运行 prodSmoke 标记的 package.json 文件:-

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

当我使用命令运行它时:-

npm run e2e:run:dev

它没有选择开发环境。它始终仅在 qa 环境中运行。因为这config.env.fileConfig行特定的代码不返回任何值。

虽然我dev.json在 config 文件夹中创建了文件,但下面是index.js文件:

 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);
   
 };

如果我不在命令中使用 TAGS,则它正在选择命令中提到的 env:

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

上面的命令完美无缺。

我很确定这是 TAGS 变量的问题,它无法config.env.fileConfig正确解决,这是因为它总是在 qa 中运行脚本。

有谁可以帮我离开这里吗?

4

0 回答 0