Programmatically set reporter-json-folder etc as part of runner object
rhowk opened this issue · 8 comments
Via command line the json reporter folder is set by:
--reporter-json-folder='my-custom-folder'
We are trying to run the gherkin-testcafe programmatically and our setup looks like this:
const createTestCafe = require('gherkin-testcafe');
...
let failedCount;
try {
testcafe = await createTestCafe({ host, developerMode: true });
const { server1Info, server2Info } = testcafe.proxy;
logger.log('Ports used: ${server1Info.port}, ${server2Info.port}');
runner = await testcafe.createRunner({ src: './${brand}/' });
failedCount = await runner
.src(['tests/${brand}'])
.concurrency(1)
.browsers(getBrowser(platform, env))
.tags([tags])
.reporter('cucumber-json', join('reports', 'batch${jobnumber}', 'json', 'batch${jobnumber}.json'))
.screenshots({
path: './screenshots/${brand}',
takeOnFails: true,
})
.video('screenshots/video/${brand}', {
singleFile: true,
failedOnly: true,
pathPattern: '${jobnumber}_${brand}_${region}_${platform}.mp4'
})
.run(
{ debugMode, debugOnFail: debugMode }
);
} catch (error) {
logger.log('Test runner error', { error });
process.exit(1)
}
finally {
await testcafe.close();
logger.log('Test runner finished\');
if (failedCount > 0) {
process.exit(1)
}
process.exit(0)
}
jobnumber: is the # of the current run, may include mult versions of the next vars
brand: is one of our brands
region: our brands live in multiple countries
platform: mobile or pc
so we can have www.brand1.com or m.brand1.co.uk
depending on what we want to test.
We need to put the json in a custom folder, hence:
.reporter(cucumber-json
, join('reports', batch${jobnumber}
, 'json', batch${jobnumber}.json
))
but the command line specifies a directory not a file. What we end up with because our
testcafe-reporter-cucumber-json.json has the arg:
"reportFolder": "reports"
Is all the json gets written to the reports directory and then when I have to generate a report, I delete the reports/batch1234/json/batch1234.json file, because its empty, copy all the latest jsons from the report root to the batch1234/json directory and then compile the report.
The bad thing happening is that we are only getting one "good" json on the report root, the batch1234.json is blank. So how do i correctly set the reporter-json-folder, the reporter-app-name, etc via runner.reporter?
Hi @rhowk , actually you cannot setup correctly the reporter-json-folder, the reporter-app-name via runner.reporter.
To do so, I need to modify the code in order to read those infos from environment variables:
process.env['--reporter-json-folder'] = join('reports', 'batch${jobnumber}');
process.env['--reporter-app-name'] = 'foo';
process.env['--reporter-app-version']= 'bar;
// then create and start the runner
Do you think it could be a solution for you?
If yes, I will update the code and publish a new version.
Thanks
That would be fantastic! Love to be your guinea pig on this.
so I added :
process.env.reportFolder = join('reports', batch${jobnumber}'); process.env.appName = '${jobnumber}-${name}';
to runner .js and when I console log the process.env I see:
LC_CTYPE: 'en_US.UTF-8', SAUCE_ACCESS_KEY: '', NVM_BIN: '/Users/<myuser>/.nvm/versions/node/v14.17.0/bin', SNC_LIB: '/Applications/Secure Login Client.app/Contents/MacOS/lib/libsapcrypto.dylib', DEBUG: 'false', reportFolder: 'reports/batch720211836', appName: '720211836-domains.us.dabrand.pc'
at the end but still not writing json to correct place or even writing json at all for the reports.
Hi @rhowk, you still need to wait until I push a new release.
I plan the following change:
[6.3.0] - 2021-07-21
Added
-
feat(reporter): be able to set reporter options through environment variables.
- you can now set the
--reporter-json-folder
,--reporter-app-name
and--reporter-app-version
options as variable environments:
process.env['--reporter-json-folder'] = 'my-custom-folder'; process.env['--reporter-app-name'] = 'My App'; process.env['--reporter-app-version'] = 'x.y.z'; // then start tests via the TestCafé Runner
- you can now set the
Hi @rhowk , I have pushed the v6.3.0
on npm
.
Feel free to give any feedback.
Thanks
@hdorgeval we will test it out and get right back to you! Thanks so much!
@hdorgeval Worked like a charm. Thanks so much!
Hi @mattylips77, thanks for your feedback. It's always appreciated :)