我可以在plugin/index.js 文件中传递Cypress.env 吗?

Jam*_*jov 5 sql sql-server cypress

我创建了一个 cypress “任务”来从 DB 获取数据,我不想在索引文件中存储 configDB 的凭据,并希望通过 cypress.json 传递它。Cypress.env 不起作用有解决方法吗?

const configDB = {
      server: "xxx",
      port: xxx,
      domain: "US",
      user: "username",
      password: "password",
      database: "database",
      driver: "tedious",
      options: {
        enableArithAbort: true,
      },
    };
    const sql = require("mssql");

Run Code Online (Sandbox Code Playgroud)

Sre*_*.Bh 4

请参阅此处

plugins/index.js文件中,将其设置为config.env

module.exports = (on, config) => {
  // `on` is used to hook into various events Cypress emits
  // `config` is the resolved Cypress config

  // modify env var value
  config.env.ENVIRONMENT = 'dev';

  // return config to update the global configuration
  return config
}
Run Code Online (Sandbox Code Playgroud)