Angular2 - Executing e2e tests in different environments
Switching between environments using environment variables
My recommendation is to try to use environment variables and switch between environments in the Protractor configuration file. You could export TEST_ENV=dev
and then have conditionals for the browser.baseUrl
Protractor config file
var baseUrl = '';
if (process.env.TEST_ENV === 'dev') {
baseUrl = 'http://devurl';
} else if (process.env.TEST_ENV === 'stage') {
baseUrl = 'http://stageurl';
} else {
baseUrl = 'http://produrl';
}
exports.config = {
baseUrl: baseUrl
}
For a better concrete example of a configuration file using process.env
, see the Testing Angular Applications, chapter 11 GitHub repo.
You could also change baseUrl parameter inline; however, if you are changing multiple variables based on the testing environment, I would suggest using environment variables:
ng e2e {protractor config file} --baseUrl='http://devurl'
Protractor global install?
Protractor does not need to be installed globally. The recommendation is to use the version installed locally from your node_modules directory. This will provide other developers repeatable steps using the same Protractor dependencies to run the e2e tests. Alternatively, if you are using the globally installed version, you will now have to instruct other developers to use a specific Protractor version.