Search the web
Sign In
New User? Sign Up
TestFirstUserInterfaces
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Message search is now enhanced, find messages faster. Take it for a spin.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Re: XPath to test HTML   Message List  
Reply | Forward Message #1018 of 1051 |
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



Thu Sep 25, 2008 10:38 am

phlipcpp
Offline Offline
Send Email Send Email

Forward
Message #1018 of 1051 |
Expand Messages Author Sort by Date

... That wouldn't be very politic of me! Here's the first hit: http://www.google.com/codesearch?q=package%3Ahtmlunit+xpath ...
Phlip
phlipcpp
Offline Send Email
Sep 25, 2008
10:39 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help