Executing .exe File Using Node Runs Only Once In Protractor
I write some tests using jasmine and protractor i want in the @beforeeach to execute .exe file using require('child_process') and then @aftereach i will restart the browser. The pr
Solution 1:
You should use the done
and done.fail
methods to exit the async beforeEach
. You begin to execute Test.exe
and immediately call done. This could have undesired results since the process could still be executing. I do not believe process.on('exit'
every gets called. Below might get you started on the right track using event emitters from the child process.
beforeEach((done) => {
const execFile = require('child_process').execFile;
browser.get('URL');
// child is of type ChildProcess
const child = execFile('Test.exe', (error, stdout, stderr) => {
if (error) {
done.fail(stderr);
}
console.log(stdout);
});
// ChildProcess has event emitters and should be used to check if Test.exe
// is done, has an error, etc.
// See: https://nodejs.org/api/child_process.html#child_process_class_childprocess
child.on('exit', () => {
done();
});
child.on('error', (err) => {
done.fail(stderr);
});
});
Post a Comment for "Executing .exe File Using Node Runs Only Once In Protractor"