[TFUI] test-driven Ajax
2007-03-08 17:46:49 GMT
Adam Sroka wrote:
> ...Given that most web apps
> today are highly dependent on the Ajax stack I would not trust these
> frameworks unless they have *greatly* improved since the last time I
> looked at them.
If I can avoid my usual plagues and disasters for just a couple more
weeks now, I will _finally_ be publishing a chapter of /TFUI/.
(Woo-hoo! and _incredibly_ sorry about the wait, everyone!)
The chapter shows how to use Rails and Ajax to write a test runner, in
the style of Watir or Selenium. It uses Ajax to edit and maintain test
cases in a web page, and tests target pages in an IFrame.
The chapter shows how to build the core of this tool from Rails, its
existing test rigs, and some new test rigs I assemble on the fly. It
Anyone proficient with Rails can sample the test runner itself here:
It currently beats on a couple of my Rails projects. If you install it
but don't build a controller for it, you get assert_xpath and
assert_js. (Only the wiki can do assert_ajax!)
Here's an extreme example of assert_xpath:
assert_xpath '/ul/li/table/tr/td/strong[ . = "test_hammy_squirrel" ]' do
assert_xpath '../../../../ul/li/table/tr/td/strong[ . = "script" ]' do
assert_xpath '../../../../div[ . = "# something tests hammy squirrel" ]'
The first assertion takes a string, parses it as XML, and puts it into
a secret member variable called <at> xdoc. The assert_xpath requires a
valid path, so you can put lots of query details into the path. Then
assert_xpath upgrades <at> xdoc to point to the selected node, and it
calls a block. assert_xpath inside the block then works on the
selected node. In the above example (which could be more ...
exemplary), the nested assert_xpath calls respond by reaching back up
the tree of nodes, and finding distant cousins of the selected nodes.
assert_xpath can then query out its important details:
assert_xpath '/form/textarea' do |textarea|
assert_js textarea.attributes['onkeydown'] do
assert_xpath 'Statement' do
assert_xpath '//Identifier[ <at> name = "Callee" and . =
That might be better than "assert_match /onkeydown.*editor_keydown/,
Ajax command finishes. You can populate the callback with assertions
to check that your Ajax updated your DOM correctly.
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!