-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In environment configuration file, add the custom variables in deep structures #3157
Comments
You can do this by modifying your plugins file (by default, in |
Hello @flotwig, thanks for your reply. // promisified fs module
const fs = require('fs-extra')
const path = require('path')
function getConfigurationByFile (file) {
const pathToConfigFile = path.resolve('..', 'config', `${file}.json`)
return fs.readJson(pathToConfigFile)
}
// plugins file
module.exports = (on, config) => {
// accept a configFile value or use development by default
const file = config.env.configFile || 'beta'
return getConfigurationByFile(file)
} And my {
"execTimeout": "120000",
"id_env": {
"CC_COOKIES": "aaaa"
...
},
"tw_env":{
"CC_COOKIES": "bbbb"
...
},
"hk_env":{
"CC_COOKIES": "cccc"
...
}
} In my case, I put {
"execTimeout": "120000",
"env": {
...
},
} But which can not be separated define the env variables by different mateix (here is country). |
If I'm understanding correctly, you want to run your tests 6 times in total, 3 times in each environment, once for each country? If this is the case, no, there is not currently a way to do this with just a static config file. You have some options.
['hk', 'tw', 'id'].forEach((country) => {
describe(`${country}...`, () => {
// your tests
})
}) |
@chuchu1313 You could probably utilize our Module API to do what you want. https://on.cypress.io/module-api |
@flotwig @jennifer-shehane Thanks for your reply. // cypress_run.js
const env = process.argv[2]
const country = process.argv[3]
fs.readFile('cypress/config/' + env + '.json', 'utf8', function (err, data) {
const configs = JSON.parse(data)
cypress.run({
spec: runFiles,
env: configs[country]
})
}) |
Current behavior:
To define an environment variable, in the config file (e.g. cypress/config/development.json) I can add variables on the first level of JSON format.
The second level needs to be named env, like below
Desired behavior:
Assumed I have two environments (
development
&qa
), and have two config files to define the different environment variables, but still needs to test in three different countries in each environment, and the variable is different depending on the countries.The desired config structure may be like below
e.g:
development.json
e.g:
qa.json
So I can get the variables based on the environment and countries, it could be more flexibility for configs.
Current behavior needs to create 6 different files
(
development_id.json
,development_tw.json
,development_h.jsonk
,qa_id.json
,qa_tw.json
,qa_hk.json
)The text was updated successfully, but these errors were encountered: