How can we pass the Username, Password from the CLI, ie Ubuntu terminal in cypress-cucumber-preprocessor. I have tried running my test using the following npx cypress-tags run command
but it is not working. Could someone suggest what could be the problem here? I would like to login with the user/ password passing from CLI
Cypress version: 8.7.0
CYPRESS_baseUrl=https://one.bookpro.com/main/ npx cypress-tags run -e 'PRO_USERNAME=CypTest2,PRO_PASSWORD=CypTest123' -e TAGS='@login' GLOB='tests/cypress/integration/**/*.feature' --headless --browser chrome
My .env
file has the following
CYPRESS_PRO_USERNAME=CypTest1
CYPRESS_PRO_PASSWORD=CypTest123
If you add the package cypress-dotenv
npm install --save-dev dotenv cypress-dotenv
and set up cypress/plugins/index
like this
const tagify = require('cypress-tags');
const dotenvPlugin = require('cypress-dotenv');
module.exports = (on, config) => {
on('file:preprocessor', tagify(config));
config = dotenvPlugin(config)
return config
};
you can automatically get items added in the .env
file (check under Setting menu in the Cypress runner).
Same should work with cypress run
I think.
Note If you want to have .env
settings as default, but override on the command line sometimes, the above will not do it.
You need to merge the config as follows
module.exports = (on, config) => {
on('file:preprocessor', tagify(config));
const fromDotEnv = dotenvPlugin(config)
config = {
...fromDotEnv, // from the .env file
...config // CLI -e PRO_USERNAME=CypTest2,PRO_PASSWORD=CypTest123
}
return config
};
Also, I had to remove the '
around the PRO_USERNAME=CypTest2,PRO_PASSWORD=CypTest123
but that may be an OS issue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.