0

I need to test around 30 to 40 websites. For checking if there is any client-side javascript errors, I will manually hit the websites in my browser and I will monitor in the console to see for javascript errors.

Is there any way I can automate the testing process using nodejs? Is there any way to validate if a page has javascript errors?

Pete
  • 57,112
  • 28
  • 117
  • 166
VJohn
  • 493
  • 1
  • 14
  • 23
  • You could try crawling them with a tool that can grab an html page and render it with all javascript in place, such as phantomjs, but i've never used it for this purpose so i'm not sure if it reports errors in the way you're looking for. – Kevin B Jul 14 '15 at 18:19
  • 1
    Yes you can use phantom js it will show all the javascript errors – KlwntSingh Jul 14 '15 at 18:22

2 Answers2

0

You can create a file JS that has something like below and push it to your websites.

window.onerror = function(message, url, number){
    // send this data to your node.js server via AJAX
    $.post("http://yourdomain.com/errorHandler", {"msg": message, "url": url, "lineNumber": number}, function(data){
        // code removed for brevity
    });
}

You can look at this thread for more information: Javascript global error handling

Community
  • 1
  • 1
hyde
  • 2,525
  • 4
  • 27
  • 49
0

I second the approach suggested above. Please use PhantomJS. I think the event you are looking for is: on error

Community
  • 1
  • 1
trk
  • 2,106
  • 14
  • 20