开发者

Load page, wait, log any JavaScript errors to file?

I would like to check a large number of HTML files with inline JavaScript for JavaScript errors. What I'm envisioning doing is this: Script a browser to load a gi开发者_开发百科ven page, wait a few seconds, and finally check the browser logs. I'm unsure though both on how to script a browser to load a given page and on how to access the JavaScript error log. I think the type of errors I'm worried about should show up in any modern browser so I would just go with whatever makes it most convenient. I'd be working either under Mac OS X or Linux.

Anybody already tackle a similar problem? I've thought a bit about hacking something together based on a unit testing framework -- generate a trivial (assertTrue(true)) test for each page and rely on the errors making it fail -- but I'm hoping for something more elegant. Thank you.


There are several routes you could take, though I'm not convinced that automation is really necessary in this case.

If your Javascript wasn't inline, you could try something adventurous like Rhino with DOM support, and completely eschew the browser. I would heartily recommend separating your JS and your markup anyway.

If you're dead-set on creating an automated solution for this, I would perhaps take a look at the Selenium plugin/testing framework for Firefox. It enables automated UI testing, and if you're thorough enough with it you should be able to uncover any error cases you would have run into in using the site. It should also be able to report JS errors to you. If not, using it in conjunction with a service like ExceptionHub or Hoptoad will get you what you need.

You shouldn't have to resort to trying to unit-test JS in the DOM. That's a recipe for complication.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜