Monday, August 1st, 2005

Automatic testing of your web pages with JavaScript

Category: Toolkit

<p> We have talked about Selenium (cure to Mercury ;), and JsUnit.

Jon Tirsen (ThoughtWorker) has a nice proof of concept that has been added to scriptaculous. This Firefox enabled addition allows for automatic testing of your web pages with JavaScript:

new Test.Unit.Runner({

  test_InPlaceEditor: function() { with(this) {
    inPlaceEditor = new Ajax.InPlaceEditor($('tobeedited'), 
      'inplaceeditor_result.html');

    Event.simulateEvent('tobeedited','mouseover');
    assertEqual("rgb(238, 238, 238)", 
      Element.getStyle('tobeedited','background-color'));

    Event.simulateEvent('tobeedited','mouseout');
    assertEqual("transparent", 
      Element.getStyle('tobeedited','background-color'));

    Event.simulateEvent('tobeedited','mouseover');
    Event.simulateEvent('tobeedited','click');
    assertHidden($('tobeedited'));

Related Content:

3 Comments »

Comments feed

People might also be interested in Dojo’s unit testing harness, which supports unit testing in Rhino through an ant task. Dojo also has the concept of a “fake dom” to test against, which was strongly influenced by Mark Anderson’s work on burstlib. Basically the fake dom provides a set of objects that mimic the behavior of having a real DOM to test against in a command line environment.

For example, to test a Dojo button, you might write tests like this:

function test_button_ctor(){
var b1 = new dojo.webui.widgets.Button();

jum.assertTrue(“test10″, typeof b1 == “object”);
jum.assertTrue(“test20″, b1.widgetType == “Button”);
jum.assertTrue(“test21″, typeof b1["attachProperty"] == “undefined”);

var db1 = new dojo.webui.widgets.DomButton();
jum.assertTrue(“test30″, typeof db1 == “object”);
jum.assertTrue(“test40″, db1.widgetType == “Button”);
jum.assertTrue(“test50″, db1.attachProperty == “dojoAttachPoint”);
jum.assertTrue(“test60″, typeof db1.domNode != “undefined”);

}

(sorry about the formatting… not sure how to provide formatting for your content).

And while unit testing is nice for testing code accuracy, it of course doesn’t do much in the way of testing interactions and timing issues. Bob Clary’s Mozilla Spiders Extension, http://bclary.com/2004/07/10/mozilla-spiders , looks like a promising start for this important part of testing.

Comment by Dylan Schiemann — August 1, 2005

So these things are kind of interesting, but Selenium has fatal architectural flaws (you want for some seconds and then just say “it should be done”…what?). Donovan Preston, python hacker extrordinaire, has been working on a new tool like Selenium called LiveTest.

It is ,as they say, all that.

We’ll be adding it to our unit-testing arsenal for Dojo and encourage everyone else to have a gander at it.

Comment by Alex Russell — August 1, 2005

There’s also the Test.Builder framework that JSAN uses.

Comment by Adrian Howard — August 5, 2005

Leave a comment

You must be logged in to post a comment.