Can I pass Cypress.env inside of plugin/index.js file?

Viewed 862

I have created a cypress 'task' to grab data from DB , I dont want to store credentials for configDB in index file and wanted to pass it through cypress.json . Cypress.env didnt work is there a workaround ?

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

1 Answers

Refer here.

In plugins/index.js file, set it as 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
}
Related