Mickael
1
Hi,
How to access the config value from a Scenario?
I would like to send params when running the scripts with -o but I struggle to understand how I can read them inside a scenario.
Ex: npx codeceptjs run --override ‘{ “data”: {“id”: 555 }}’
In a Scenario:
…
I.sendGetRequest(’/todos/555’);
…
I would like to have the ‘555’ in the request to be dynamic.
Thanks
davert
2
Take a look at this config
I take a dynamic parameter, and add it to container:
After, I can access this parameter from a container:
Scenario('asdas', (I, project) => {});
Mickael
4
First of all, thanks for your prompt replies/help.
I looked at all of them, but I was missing the part on how to make the values came from the command line (process.args) instead of process.env.
But I think the best approach in my case is to use https://codecept.io/commands#run
So now I just update the REST endpoints dynamically:
codecept.conf.js
REST: { endpoint: null,
And command line sample:
npx codeceptjs run --override '{ "helpers": {"REST": {"endpoint": "https://jsonplaceholder.typicode.com"}}}'
I’m still stuck on how to send other custom params from process.args, but the solution above is a first step.
Thanks again
Mickael
5
Ok just found this in the doc when searching for event listeners:
So now I just use let config = require('codeceptjs').config.get();
to get access to the dynamic configs.
3 Likes
arvi
6
Hey Thanks, this is working fine
Appium: {
app: process.cwd() + “/codeceptJS//APKs/myapk.apk”
}
However, I am looking to pass this process.cwd() from command line while overriding the “app” key in this json.
Something like : npx codeceptjs run --override '{“env”:“sit”,“helpers”:{“Appium”:{“app”:process.cwd() + “/codeceptJS//APKs/myapk.apk”}}
But it is not working and obviously giving JSON not correct error.
Could you please help.
Mickael
7
My 2cents on this, you cannot have “process.cwd()” in the command line, it needs to be in plain text.
This will fail:
npx codeceptjs run --override '{“env”:“sit”,“helpers”:{“Appium”:{“app”:process.cwd() + “/codeceptJS//APKs/myapk.apk”}}
This will work:
npx codeceptjs run --override '{“env”:“sit”,“helpers”:{“Appium”:{“app”:“path/to/codeceptJS//APKs/myapk.apk”}}
arvi
8
Thanks a lot again Mickael. I actually want to override the path to apk via command line to test multiple apk through package.json file.
Mickael
9
Thats off topic, but you my guess is that you could achieve that with a shell script.