How can I use System Environment Variables in Angularjs Protractor?

18,981

Solution 1

I used export E2E_USER=username and that worked.

Solution 2

You have to use process.env.YOUR_ENV in NodeJS, so for example inside onPrepare function, not directly inside params:

exports.config = {
    onPrepare: function() {
        //load env variables for testing
        if (typeof process.env.URL !== "undefined") {
            browser.baseUrl = process.env.URL;
            console.log('Base URL = ' +process.env.URL);
        }
},
params: { ...
Share:
18,981
Brendan
Author by

Brendan

QA Engineer at Snap Inc. who is passionate about mobile user experience and software quality

Updated on June 19, 2022

Comments

  • Brendan
    Brendan almost 2 years

    My plan is to store a username and password as system environment variables and reference them in an Angularjs Protractor config file. I defined the variables in /etc/environment. This is what I've tried so far:

    params: {
      login: {
        user: $E2E_USER,
        pass: $E2E_PASS
      }
    }
    

    I also tried this:

    params: {
      login: {
        user: process.env.E2E_USER,
        pass: process.env.E2E_PASS
      }
    }
    

    Any help would be much appreciated!

  • jrharshath
    jrharshath about 8 years
    Might I clarify: process.env.E2E_USER works. The export command in this answer merely sets the environment variable E2E_USER. I presume when the OP asked the question, the variable wasn't set.
  • Sameer K
    Sameer K over 6 years
    I am trying to achieve the same with angular2 and protractor, but no luck. When i console log process.env, i do not see any of the environment variables. How can i fix my issue??