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 problem is that the .exe file is executed only once with the first spec. here is the code in the beforeEach()
beforeEach((done) => {
console.log("before each is called");
var exec = require('child_process').execFile;
browser.get('URL');
console.log("fun() start");
var child = exec('Test.exe', function(err, data) {
if (err) {
console.log(err);
}
console.log('executed');
done();
process.on('exit', function() {
child.kill();
console.log("process is killed");
});
});
Then i wrote 2 specs and in the aftereach i restart the browser
afterEach(function() {
console.log("close the browser");
browser.restart();
});
You should use the
done
anddone.fail
methods to exit the asyncbeforeEach
. You begin to executeTest.exe
and immediately call done. This could have undesired results since the process could still be executing. I do not believeprocess.on('exit'
every gets called. Below might get you started on the right track using event emitters from the child process.