You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
passing username / password dynamically (CLI or other workaround) #1533
We 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:
changed the title [-]There is no good way to introduce custom CLI arguments at all[/-][+]passing username / password dynamically (CLI or other workaround)[/+]on Mar 1, 2019
The point is that we don't want to: sometimes account passwords change, or you want to be able to test with your own account, which you don't want to store anywhere etc.
This is also what I tried, but could not get to work: I think that the actual tests used inside codeceptjs don't have access to process.env... I'll try this again without a script that prompts for it but just exporting it before running the codecept command
Why not simply pass them into the node as env variables, simply prepend them before your run command USERNAME=username PASSWORD=password ./node_modules/.bin/codeceptjs run .... then you simply access them inside your framework via:
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
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
constconfig={// your config}// check if you have env variablesif(process.env.npm_config_proxyusername!==undefined&&process.env.npm_config_proxypassword!==undefined){// set the username/password into a custom helperconfig.helpers.LaunchHelper.username=process.env.npm_config_proxyusernameconfig.helpers.LaunchHelper.password=process.env.npm_config_proxypassword}
Activity
[-]There is no good way to introduce custom CLI arguments at all[/-][+]passing username / password dynamically (CLI or other workaround)[/+]kobenguyent commentedon Mar 1, 2019
why do you put creds file in different place? is it not possible to have it inside codeceptjs folder?
michahell commentedon Mar 1, 2019
The point is that we don't want to: sometimes account passwords change, or you want to be able to test with your own account, which you don't want to store anywhere etc.
michahell commentedon Mar 1, 2019
So right now, my solution is a (git) ignored
credentials.jsfile, but I find this a workaround and not a solution.kobenguyent commentedon Mar 1, 2019
is it possible that you have a default account? let's say if you provide
this will be used instead of default account.
michahell commentedon Mar 1, 2019
This is also what I tried, but could not get to work: I think that the actual tests used inside codeceptjs don't have access to
process.env... I'll try this again without a script that prompts for it but just exporting it before running thecodeceptcommandxMutaGenx commentedon Mar 4, 2019
Why not simply pass them into the node as env variables, simply prepend them before your run command
USERNAME=username PASSWORD=password ./node_modules/.bin/codeceptjs run ....then you simply access them inside your framework via:gabrielcaires commentedon Mar 7, 2019
You can use
.envfile 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 runaustinmehmet commentedon Apr 15, 2019
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