passing username / password dynamically (CLI or other workaround) #3016
Replies: 8 comments
-
why do you put creds file in different place? is it not possible to have it inside codeceptjs folder? |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
So right now, my solution is a (git) ignored |
Beta Was this translation helpful? Give feedback.
-
is it possible that you have a default account? let's say if you provide
this will be used instead of default account. |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
Why not simply pass them into the node as env variables, simply prepend them before your run command
|
Beta Was this translation helpful? Give feedback.
-
You can use |
Beta Was this translation helpful? Give feedback.
-
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 const config = {
// your config
}
// check if you have env variables
if (process.env.npm_config_proxyusername !== undefined && process.env.npm_config_proxypassword !== undefined) {
// set the username/password into a custom helper
config.helpers.LaunchHelper.username = process.env.npm_config_proxyusername
config.helpers.LaunchHelper.password = process.env.npm_config_proxypassword
} custom LaunchHelper class LaunchHelper extends Helper {
async launchApplication() {
const I = actor()
I.amOnPage('/')
if (this.config.username && this.config.password) {
const puppeteer = this.helpers.Puppeteer
const page = await puppeteer.page
await page.authenticate({ username: this.config.username, password: this.config.password })
}
}
}
module.exports = LaunchHelper example script npm run e2e:headless --url="$CI_ENVIRONMENT_URL" --proxyusername="$proxy_username" --proxypassword="$proxy_password" |
Beta Was this translation helpful? Give feedback.
-
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 fieldsusername
andpassword
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
:package.json
script:"test:e2e:verbose": "node tools/e2e-credentials.js && codeceptjs run --steps --debug --verbose",
`CodeceptJs test:
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 ?
Beta Was this translation helpful? Give feedback.
All reactions