How to run npm run command in onComplete hook in wdio

Viewed 33

In wdio test project, I want to generate and open allure report once test execution is completed and to do this I've added a command ("allure-report": "allure generate ui-tests/allure-results --clean && allure open") as a script in package.json file. To open the allure report post-execution, I need to run this command "npm run allure-report" manually, which successfully opens the report in the web browser. But instead of running this command manually every time post-execution, I want to add this command to be executed itself by putting it in the onComplete hook in the wdio.config.js file.

To do this I have added the following in onComplete hook which is not working:

onComplete: function(exitCode) { require('child_process').spawnSync('npm', ['run', 'allure-report'], {cwd: __dirname + '/package.json' }) }

Does anyone know how to make this command run itself in onComplete hook post test execution which open the allure report

0 Answers
Related