score:0

avoid wrapping your env file in env variable. by the way this should do the job with your file:

cypress.env("env")["host"]

score:1

first of all why not use process.env.host inside your spec files. second if you want to test in different host then what i have been doing is.

  1. create a folder (eg: configfiles)

  2. inside this create json files like (eg: host1.json, host2.json)

  3. inside your json file (in host1.json)

    { "env": { "host" : "host1" } }

  4. inside your plugins folder edit index.js

    const fs = require('fs-extra'); const path = require('path');

    function getconfigurationbyfile(file) { const pathtoconfigfile = path.resolve( 'cypress/configfiles', ${file}.json );

    return fs.readjson(pathtoconfigfile); }

    module.exports = (on, config) => { const file = config.env.host || 'host1';

    return getconfigurationbyfile(file); };

  5. then while running you can use npm cypress run --env host=host1

score:1

this is a late answer but you can achieve this by creating the variable in plugins (https://docs.cypress.io/guides/guides/environment-variables#option-5-plugins)

documentation states:

// .env file
user_name=atester

/

// plugins/index.js
require('dotenv').config()

module.exports = (on, config) => {
  // copy any needed variables from process.env to config.env
  config.env.username = process.env.user_name

  // do not forget to return the changed config object!
  return config
}

// integration/spec.js
it('has username to use', () => {
  expect(cypress.env('username')).to.be.a('string')
})

Related Query

More Query from same tag