Hello
I’d like to pass some configuration values to my load tests, like base URLs or domain specific values for parameterization.
I know that I can pass environment values, but I’m not the biggest fan of those because they are rather implicit. I’d rather pass a config file explicitly or maybe CLI flags.
Does that possibility exist somehow?
Hi @maxeludwig !
Welcome to the community forums!
Yes, you could do that by the just parsing a JSON file, for example:
// load test config
const testConfig = JSON.parse(open('./config/test.json'));
Later on, just use the testConfig
object
Cheers!
Ah, but I have different config files depending on, for example, which environment I’d like to run the test in, so I’d rather not hard-code the config filename in the test.
@maxeludwig
You can pass the config filename in an environment variable
k6 run -e CONF=c1.json script.js
Then, you can parse the c1.json in the script like @olegbespalov mentioned:
var config = JSON.parse(open(__ENV.CONF))
3 Likes
Yes, I was referring to this approach initially:
I know that I can pass environment values, but I’m not the biggest fan of those because they are rather implicit. I’d rather pass a config file explicitly or maybe CLI flags.
It’s an okay approach. I guess I was hoping that k6 could do that work, especially because there is already a flag --config
which is for some reason only for the predefined options and ignores custom values.