2017-02-26 8 views
0

jasmineと分度器を使用していくつかのテストを行います。@beforeeachでrequire( 'child_process')を使用して.exeファイルを実行してから@aftereachを実行します。 問題は、.exeファイルが最初の仕様で1回だけ実行されることです。 ここbeforeEach(のコード) ノードを使用して.exeファイルを実行すると、分度器で一度だけ実行されます

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"); 
     }); 

    }); 

が、私は2つのスペックを書き、aftereachに私はあなたが非同期を終了し donedone.failメソッドを使用する必要があります

afterEach(function() { 
     console.log("close the browser"); 
     browser.restart(); 
    }); 

答えて

0

ブラウザを再起動がありbeforeEachTest.exeを実行してすぐに完了を呼び出します。これは、プロセスがまだ実行されている可能性があるため、望ましくない結果をもたらす可能性があります。私はすべてprocess.on('exit'が呼ばれるとは思わない。以下では、子プロセスからのイベントエミッタを使用して正しいトラックを開始するかもしれません。

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); 
    }); 

}); 
+0

私はあなたのsolution.Theの子プロセスが終了したが、それはそれは私達があなたのテストに関するより多くの情報が必要その後 – user1115684

+0

を実行されませんでした第二スペックonce.Inのみ実行してみました。 'describe'、' beforeEach'、 'it'ブロックの小さなスニペットを追加します。 – cnishina

関連する問題