passing username / password dynamically (CLI or other workaround)
See original GitHub issueWe are testing an add-in (plugin if you will) that is running inside another webapp (Outlook Web Access). To authenticate, we either use our own account (when developing) or specific test accounts (QA’s / automated testing).
However, we wish to nót hardcode the account details (so not hardcoded inside an exported module and not using a DataTable
, etc.) but pass them via the command line.
For example, using protractor, something like this is quite trivial, as you can just create a config
object that contains the fields username
and password
and overwrite these with separate flags using the CLI.
It seems this is a lot harder to achieve in Codecept. I know of the --profile
switch, but it seems like a hassle to make that work for multiple fields (like username + password).
Another approach I tried was to set process environment variables befóre running tests witha simple node script that prompts for username and password if these are not set.
However, I can not retrieve these inside my tests:
excerpt from e2e-credentials.js
:
process.env.OWA_CODECEPT_USER = username;
process.env.OWA_CODECEPT_PASS = password;
package.json
script:
"test:e2e:verbose": "node tools/e2e-credentials.js && codeceptjs run --steps --debug --verbose",
`CodeceptJs test:
loginToOwaPage.login(process.env.OWA_CODECEPT_USER, process.env.OWA_CODECEPT_PASS);
But this does not work, probably because these are not the same processes?
What would be the best way to achieve such a thing in CodeceptJs ?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:8 (2 by maintainers)
Top GitHub Comments
We had to do something similar because we needed to pass in dynamic environments generated by our CI and run against a proxy username/password. This is all done through the CLI and we have different scripts that run locally vs in our CI/CD all with different credentials.
codecept.conf.js
custom LaunchHelper
example script
You can use
.env
file with this package https://www.npmjs.com/package/env-cmd. So, you will just need to update your package.json to use something like:env-cmd .env.test codeceptjs run