What are you trying to achieve?
I wanted to control what browser is run using --profile and fallback to chrome if --profile was not provided.
What do you get instead?
I got errors like "Error: Cannot find the browser. "undefined:headless" is neither a known browser alias, nor a path to an executable file.".
I tried debugging by putting console.log(process.env.profile, typeof process.env.profile); in my codecept.conf.js and got "undefined string".
Details
- CodeceptJS version: 3.3.3
- NodeJS Version: v16.15.1
- Operating System:
- puppeteer || webdriverio || testcafe version (if related): testcafe@1.19.0
- Configuration file:
require('ts-node/register');
const {
setHeadlessWhen,
setBrowser,
setTestHost,
} = require('@codeceptjs/configure');
console.log(process.env.profile, typeof process.env.profile);
setHeadlessWhen(process.env.CI);
setBrowser(process.env.profile || 'chrome');
setTestHost(process.env.TEST_HOST);
exports.config = {
tests: './tests/e2e/codecept/features/*.ts',
output: './tests/e2e/codecept/output',
helpers: {
TestCafe: {
url: process.env.BASE_URL || 'http://localhost:3000',
},
},
include: {
// I: './tests/e2e/codecept/custom-steps.ts',
},
bootstrap: null,
mocha: {},
name: 'seymour-portal',
};
Investigation
I did a bit of debugging and it looks like the issue is the way that the run command (and other commands) set the profile.
|
// registering options globally to use in config |
|
// Backward compatibility for --profile |
|
process.profile = options.profile; |
|
process.env.profile = options.profile; |
It appears that when you assign to process.env.profile Node stringifies the value. So if options.profile is undefined then it gets stringified to "undefined" instead of resulting in the env not being set.
What are you trying to achieve?
I wanted to control what browser is run using
--profileand fallback to chrome if--profilewas not provided.What do you get instead?
I got errors like "Error: Cannot find the browser. "undefined:headless" is neither a known browser alias, nor a path to an executable file.".
I tried debugging by putting
console.log(process.env.profile, typeof process.env.profile);in my codecept.conf.js and got "undefined string".Details
Investigation
I did a bit of debugging and it looks like the issue is the way that the run command (and other commands) set the profile.
CodeceptJS/lib/command/run.js
Lines 8 to 11 in 58bf5d9
It appears that when you assign to
process.env.profileNode stringifies the value. So ifoptions.profileis undefined then it gets stringified to "undefined" instead of resulting in the env not being set.