MinkSelenium2Driver: Capture the console.log errors

I’m using Behat + phantomJS, and would like to see the errors thrown to the console.log.

CasperJs allows binding to this event:

casper.on('remote.message', function(resource) {
  this.log('LOG:' + resource);
});

This is provided by phantomjs

Would it be possible to have something similar in Behat? I can try to code it, but preferred to get some guidance on what’s the proper why.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

@amitaibu My solution was to set up a listener in the apps javascript:

testing = {
    errors: []
};
window.onerror = function(error, url, line) {
    testing.errors.push(error + ". Line: " + line);
};

And then in behat, in afterSuite, afterStep or whenever you feel is convenient,

$result = $context->getSession()->evaluateScript("testing.errors");