Online Training: Web test automation with CodeceptJS. Sign up now!

Accessing config in scenario

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

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) => {});

Alternative solution:

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

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.