George Dinwiddie wrote:
> Phlip wrote:
>> I thought the industry would support more XPath testing by now. What
libraries
>> are out there (besides mine?)?
> HtmlUnit, for one. You won't like it, though, as it's written in Java.
That wouldn't be very politic of me!
Here's the first hit:
http://www.google.com/codesearch?q=package%3Ahtmlunit+xpath
htmlunit-plugin-0.3-src/.../plugin/htmlunit/HtmlUnitFunctionTagTest.java
75: functionTag.navigate("file:./tst/html/tables.html");
String xpath = "//head[title='tables page']";
functionTag.assertXPathMatches(xpath);
85: MockHtmlUnitHelper helper = setMockHelper();
String xpath = "//head[title='tables page']";
functionTag.clickElementWithXPath(xpath);
Firstly, where did the @ go? That should be @title = 'tables page' in the
predicate.
Next, I want to nest them. Suppose we have a report table which must contain a
certain HD. I want this:
assert_xpath :table, :report do # hits //table[@id='report']
assert_xpath 'tbody/tr/td[ . = "SubTotal" ]'
end
The do-end lets us avoid writing a run-on XPath expression. And if the inner
assert_xpath fails, its error diagnostic will only print out its current context
- the outer <table> - not the whole page.
Then you can stack up more assertions inside the block. The goal is not to
mirror your HTML in the tests, but to efficiently skip over the fuzzy details
that might change.
--
Phlip