It's all spinning wheels and self-doubt until the first pot of coffee.

AJAX Testing and Logging

Okay, okay, I'll admit it: I'm an architecture astronaut. I'd join Architecture Astronauts Anonymous--but that'd be AAA, and we already use them for our car insurance. Anyway, here's my current trip into orbit:

If you click on that, you should see a page with a large textarea appear, in which a running log of tests begins. So far, all but two of the tests succeed for me in Safari, FireFox, and MSIE6. I've got a bit more work to do on writing tests, though, as well as working on the server side.

But, there are things going on behind the scenes in this test harness that I want to share right now before I fly off into space.

Testing with AJAX

First off, about a week ago, I mentioned an experiment in REST and XML with which I was starting to play. In a nutshell, it's a bastard hybrid between a wiki and an XML database, with a REST API. Well, at the time, I was just poking at it with invocations of cURL from the command line.

But, my eventual goal was to get this thing hooked up with a browser via XMLHttpRequests and JavaScript. Before just flying off to wire up any UI demos, though, I wanted to run it through some repeatable tests. So first, I made my own XmlHTTPRequest wrapper:

Then, I went in search of unit testing frameworks for in-browser JavaScript. I found a few neat things--including JsUnit, Selenium, and httpunit.

But, none of these quite fulfilled my requirements of a) being simple, b) working well with code continuity broken by asynchronous HTTP requests, and c) being learned by me in an impatient jiffy. So, I made this:

It's by no means general or even all that nice to look at, but I've got half a mind to further refactor this into my own AJAX-friendly mini-rendition of JUnit. To anyone out there: Let me know if this would be useful, or if I'm just wasting my time.

Logging in Browser-based JavaScript

Along the way through reinventing my own testing wheel, I also got fed up with the usual ways I was used to generating debugging and informative messages from my JavaScript code. So, I went off in search for something like Log4J in Java or the logging module in Python.

The closest I came was to selenium-logging.js in the Selenium package, but that wasn't really what I wanted. So, I made this:

It's by no means general or even all that nice to look at, but I've got half a mind to further expand this into my own JavaScript mini-rendition of logging. Imagine logging from a browser-based JavaScript app to a server-based REST-ified syslog. Seems like it could be useful, if done right. To anyone out there: Let me know if this would be useful, or if I'm just wasting my time.

But wait, there's more...

I'll break off here and continue in another post with the server-side things I started doing with WSGI.

Archived Comments

  • your js Log class is great for conventional, syslog-style logging, i.e. recording exceptional (client-side) events over time during lights-out operation. for the other type of commonly seen JS logging, viz. interactive "alert debugging", there's a neat approach that would be great to wire into your logger: the cache-and-bookmarklet approach [1]? all you do is cache log events locally in a browser in a buffer and then create a bookmarklet that reads and dumps the buffer into the page DOM or a popup, or an alert, etc. basically it's a multiline, on-demand trace console. [1] http://bob.pythonmac.org/archives/2005/07/03/bookmarklet-based-debugging/
  • Would love to see you enhance the AJAX testing stuff!!! Thanks for what you've done so far! Matt
  • Probably we could share our knowledge about logging? I created already a project for logging in JavaScript, which is hosted at http://log4js.berlios.de/ and its API is very close to the log4j API.

    Currently there is also an Appender to send the logs via AJAX back to the server to log them there.

  • Sorry if this comment is irrelevant.

    Do you know of any AJAX based logging framework using which I can dynamically update the logs on a web-page.

    Somewhat similar to writing log.debug("Update log!"); as in log4j. Where if I write something like log.updateScreen("Update Screen"); from my Java code it updates the screen with the log.