Building a htmlunit accessor

Poster Content
nk4um User
Posts: 177
October 12, 2006 15:03Thanks
Hi Pete,

Thanks :). Got it working. Just spending time trying to make it useful now!

Cheers,

Chris
Like · Post Reply
nk4um Moderator
Posts: 901
October 11, 2006 11:42Alternative Choice
Forgot to say.  You can alternatively just use XUnit directly. So you make a test entry with a URI to make an HTTP request for a page using active:httpGet/Post etc.  You can then do XPath assertions or even pass the page response to another assertion service for validation.  Only limit here is that the page must be well-formed XHTML - if its not then you''d need to write a wrapper script that call ed the HTTP server and then passed the response through HTMLTidy or TagSoup.
Like · Post Reply
nk4um Moderator
Posts: 901
October 11, 2006 11:38Choices for integration
Hi Chris,

If you want to wrap this library as an accessor it looks relatively painless but you might want to think about the service implementation a bit.

First off the URI interface, maybe something like:

active:HTMLUnit+url@[url to test]+tests@[declarative test list]


Then to solve your problem of constructors for the WebClient.  You can get the string value of the url argument (ie ''url to test'') as follows:

String url=context.getThisRequest().getArgument("url");


I''ve not read the HTMLUnit API in detail but it looks like you can access the response as a HtmlPage object.  So your tests list can be a declarative set of assertions which you can iterate through, calling the appropriate method on HtmlPage and making assertions.

I would suggest that the accessor returns a BooleanAspect as its response - that way it can easily be called from within XUnit.

Make sense?

Cheers,

Peter
Like · Post Reply
nk4um User
Posts: 177
October 10, 2006 16:30Building a htmlunit accessor
Hi.

I am trying to create an accessor that would make use of html unit (http://htmlunit.sourceforge.net/) that I am planning to make use of with xunit. However, when implementing the accessor, I have encountered the problem if the htmlunit library only supplying methods for accessing web pages for URLs (both java.net.URL and String). Have you got any suggestions for how I can implement this accessor? Or is there a better way that I can test the html that is being produced by my apps?

Cheers,

Chris
Like · Post Reply