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
invents:
assert_xpath
assert_js
assert_ajax
Anyone proficient with Rails can sample the test runner itself here:
http://phlip.svnrepository.com/svn/yar_wiki/README
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_xml x.target!
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" ]''
end
end
The first assertion takes a string, parses it as XML, and puts it into
a secret member variable called @xdoc. The assert_xpath requires a
valid path, so you can put lots of query details into the path. Then
assert_xpath upgrades @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_js lexes intermediate JavaScript source into XML, so
assert_xpath can then query out its important details:
assert_xpath ''/form/textarea'' do |textarea|
assert_js textarea.attributes[''onkeydown''] do
assert_xpath ''Statement[1]'' do
assert_xpath ''//Identifier[ @name = "Callee" and .
"editor_keydown" ]''
end
end
end
That might be better than "assert_match /onkeydown.*editor_keydown/,
my_javascript". The match could break when irrelevant details change.
assert_ajax works by registering a JavaScript callback to file when an
Ajax command finishes. You can populate the callback with assertions
to check that your Ajax updated your DOM correctly.
--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!