2016-05-24 7 views
1

何らかの理由でcucumberjsの基本的なアフターフックを書いていますが、期待通りに動作していません。シナリオが失敗したときにスクリーンショットを添付してブラウザコンソールログを書き込むと思われます。しかし、それは、HTMLレポートの機能の後にスクリーンショットを添付し、後で2番目のシナリオの間にブラウザのコンソールログを表示しますenter image description here.Anyは何が問題なのか?フック後フットが期待どおりに動作しない

 this.After(function(scenario, callback) {  
     if (scenario.isFailed()) { 
      global.browser.takeScreenshot().then(function(base64png) { 
      var decodedImage = new Buffer(base64png,'base64').toString('binary'); 
      scenario.attach(decodedImage, 'image/png'); 
     }); 
     global.browser.manage().logs().get('browser').then(function (browserlog){   
     browserlog.forEach(function (log) { 
      if (log.level.value > 900) { 
      console.error(log.message.substring(log.message.indexOf('Error'),log.message.indexOf('\n'))) 
      } 
     })   
     }); 
     callback(); 
    } else { 
     callback(); 
    } 

}); 

答えて

0

cucumberjsのgithubのページによればhttps://github.com/cucumber/cucumber-js#attachments

画像や他のバイナリデータがstream.Readableを使用して取り付けることができます。その場合には、)(添付するコールバックを渡すと、必須になり:

this.After(function(scenario, next) { 
    browser.takeScreenshot().then(function(png) { 
    var decodedImage = new Buffer(png, 'base64').toString('binary'); 
    scenario.attach(decodedImage, 'image/png', next); 
    }, function(err) { 
    next(err); 
    }); 
}); 

this.After(function(scenario, next) { 
    global.browser.manage().logs().get('browser').then(function (browserlog){ 
    browserlog.forEach(function (log) { 
     if (log.level.value > 900) { 
     console.error(log.message.substring(log.message.indexOf('Error'),log.message.indexOf('\n'))) 
     } 
    }); 
    }); 
}); 

次の2つの別々のフックにフックした後、単一の分割でき

関連する問題