I am trying to write a simple node.js
application in order to run selenium in a dedicate shell and then close the shell and the corresponding child process (at the moment after a timeout of 5 seconds in order to test it).
Here the code I have so far:
const spawn = require('child_process').spawn;
const seleniumHub = spawn('java', ['-jar', 'selenium-server-standalone-2.48.2.jar'], { shell: true , detached: true });
seleniumHub.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
seleniumHub.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
});
seleniumHub.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
setTimeout(function () {
// process.kill(seleniumHub.pid); no errors but shell not closed
// seleniumHub.kill('SIGINT'); completely ignored
}, 5000);
Selenium correctly runs, but I am not able to close the opened shell.
If I try to close it through its pid, I get an error that the pid doesn't exist.
If I try to call the kill
method on the child process, it completely ignores the command.Any suggestion please?
Thanks
p.s. I am on a Windows machine