CodeceptJS
CodeceptJS copied to clipboard
Dynamic Configuration is not working in Scenario or session
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
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 (
@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
thanks, \ before " working :-)