CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

Dynamic Configuration is not working in Scenario or session

Open basalona opened this issue 3 years ago • 3 comments

What are you trying to achieve?

I am trying to pass dynamic configuration for Scenario or session to change to the browser like in the below example

Scenario('should be executed in firefox', ({ I }) => { // I.amOnPage(..) }).config({ browser: 'firefox' })

What do you get instead?

The browser opens in default (chromium)

Details

  • CodeceptJS version: 3.3.2
  • NodeJS Version: v16.14.2
  • Operating System: MacOs
  • Playwright version: 1.21.0

basalona avatar May 04 '22 08:05 basalona

I try with codeceptJs 3.3.3

in codecept.conf.js i have: helpers: { TestCafe: { url: '', show: true, windowSize: '1920x1080', browser: 'chrome', restart: false, myOwnParam: 'test text in config file', myNextOwnParam: process.env.profile }, CustomHelper: { require: './CustomHelper.ts' } },

in demo test (Typescript_Example_test.ts - downloaded from https://github.com/codeceptjs/typescript-boilerplate) i have: let myConfig = require('codeceptjs').config.get(); let variableForDynamicConfig = myConfig.helpers.TestCafe.myOwnParam; let variableFromCmd = myConfig.helpers.TestCafe.myNextOwnParam;

console.log('text visible in console from test:', variableForDynamicConfig, variableFromCmd); Feature('demo test');

when i run by cmd: npx codeceptjs run --profile someTextFromCmd

i got this: text visible in console from test: test text in config file someTextFromCmd CodeceptJS v3.3.3 #StandWithUkraine Using test root "C:_git\typescriptCodeceptJs"

demo test -- Running tests in:

  • Chrome 100.0.4896.127 / Windows 10

I mean this case working correctly.

When i start test as (copy and rework from : https://codecept.io/commands/ ) npx codeceptjs run --override '{ "helpers": {"TestCafe": {"myOwnParam": "dynamic text by override"}}}'

i got this:

Unexpected token h in JSON at position 2

SyntaxError: at JSON.parse () at module.exports (C:_git\typescriptCodeceptJs\node_modules\codeceptjs\lib\command\run.js:16:33) at Command. (C:_git\typescriptCodeceptJs\node_modules\codeceptjs\bin\codecept.js:9:11) at Command.listener (C:_git\typescriptCodeceptJs\node_modules\commander\index.js:315:8) at Command.emit (node:events:526:28) at Command.parseArgs (C:_git\typescriptCodeceptJs\node_modules\commander\index.js:651:12) at Command.parse (C:_git\typescriptCodeceptJs\node_modules\commander\index.js:474:21) at Object. (C:_git\typescriptCodeceptJs\node_modules\codeceptjs\bin\codecept.js:203:9) at Module._compile (node:internal/modules/cjs/loader:1103:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)

rebajz avatar May 05 '22 09:05 rebajz

@rebajz

When i start test as (copy and rework from : https://codecept.io/commands/ ) npx codeceptjs run --override '{ "helpers": {"TestCafe": {"myOwnParam": "dynamic text by override"}}}' i got this: Unexpected token h in JSON at position 2

I recall such issue is on Windows only (unless you run the command in WSL). Try to escape " by \: npx codeceptjs run --override '{ \"helpers\": {\"TestCafe\": {\"myOwnParam\": \"dynamic text by override\"}}}'

See #1188

mirao avatar Aug 20 '22 10:08 mirao

thanks, \ before " working :-)

rebajz avatar Aug 23 '22 12:08 rebajz