O'Reilly logo

Test Driven Ajax (on Rails) by Phlip

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using an IFRAME to Test Web Sites

An IFRAME is like a miniature web browser inside a web page. If we can reliably transmit extra JavaScript commands into this browser, they can test its web page. To achieve that effect is why we built all this Wiki stuff; to put both the test cases and the tested web browser into the same user interface. Now that we have just enough Wiki features, we use them to add the IFRAME.

First, we find a home in our Wiki for a new IFRAME. Our Wiki runs inside a TABLE with three TDs. The first TD contains the page name, and the second contains our Wiki's contents.

The third TD is hiding, waiting for us to do this to it:

  • Make the test_ prefix on each YAML node clickable

  • Clicking it will:

    • open the right TD panel

    • push an IFRAME into it

    • navigate the IFRAME to the value of our test's page node

    • evaluate the script node as Ruby with a JavaScriptGenerator

    • route the output JavaScript into that IFRAME's page

    • test that target web page

  • Then extend RJS to provide assertions

  • And bubble all errors up

That will be enough to start this project, and finish this Short Cut. The remaining features, such as adding a normal Wiki interface to our Wiki, can wait for all those hard parts. And very soon we will have an Ajax Wiki that can test Ajax web sites, including ones written with Rails and Brand X.

Oh, and if we teach the Wiki to interpret more YAML markup, and accept different test runner engines, we will grow an extremely light and flexible acceptance test runner, useful far beyond mere Ajax! ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required