Skip to content

dynamic configurations are persisted for nested objects #1776

@cviejo

Description

@cviejo

What are you trying to achieve?

Trying to change config dynamically for one test and have the helper config revert to the values defined in codecept.conf.js after the test. Specifically trying to set the user-agent via args array options for chrome, although the problem applies to any nested configuration objects.

What do you get instead?

Nested configurations are not reset to their original state (prior to using Scenario().config()).

codecept.conf.js:
exports.config = {
   tests: 'src/*.test.js',
   output: './output',
   helpers: {
      Puppeteer: {
         waitForNavigation: ['domcontentloaded', 'networkidle0'],
         chrome: {
            restart: true,
            defaultViewport: null,
            args: [
               '--disable-notifications',
               '--no-sandbox',
               '--disable-setuid-sandbox',
            ]
         }
      }
   },
   include: {
      I: './src/custom-steps.js',
   },
};
test:
Scenario('test something with an android user-agent', async I => {
   /* ... */
}).config({
   chrome: {
      args: [
         '--disable-notifications',
         '--no-sandbox',
         '--disable-setuid-sandbox',
         `--user-agent="Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Mobile Safari/537.36"`,
         `--window-size=600,960`,
      ],
   },
});

Every subsequent test after this one will open a 600x960 window with an android user-agent. I'm guessing all other chrome options are overwritten as well. Similar behaviour with other helpers.

Details

  • CodeceptJS version: 2.2.0
  • NodeJS Version: v8.16.0
  • Operating System: osx 10.14.4

Comments

This is related to this line:

https://github.com/Codeception/CodeceptJS/blob/38e04f564cbb3e954dc591636c9d2f26a3f8c920/lib/listener/config.js#L20

I'd open a pr with something along the lines of:

	helper._setConfig(deepMerge(deepClone(oldConfig), config));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions