aspose file tools*
The moose likes Testing and the fly likes HttpUnit problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "HttpUnit problems" Watch "HttpUnit problems" New topic
Author

HttpUnit problems

Andrey Ilyin
Greenhorn

Joined: Sep 19, 2005
Posts: 2
Hello,

I've got some problems using HttpUnit for testing web app (Struts).



The problem is that when I run this tests, sometimes buttons[3] becomes null, sometimes does not. I think it depends on server response time. I've tried using


but it has the same problems, sometimes it works sometimes it dont. Tried setting redirect delay with HttpUnitOptions.setRedirectDelay(10*1000), but it does not help (most of navigation is forward).

Whenever I try this in debug mode, on inspecting buttons[] is can see it's good and filled with buttons, but when I run it or debug without breakpoins, NullPointerException is thrown...
Robert Watkins
Greenhorn

Joined: Sep 20, 2005
Posts: 25
It's almost certainly related to something occuring in your JSP.

buttons[3] will be null if the buttons can not be found in the resulting HTML. Exactly why that is the case is what you need to determine. Note that you _do_ know that you're getting some HTML back from the server - otherwise you would get the NPE when assigning buttons[3] in the first place (as you wouldn't have found the form)

Two suggestions:
  • Explicitly check the number of buttons in the test; if it's not right, dump the HTML for analysis.
  • Use a conditional break point in your debugger; the condition, of course, is for a null value for buttons[3].


  • Software is too expensive to build cheaply...
    Andrey Ilyin
    Greenhorn

    Joined: Sep 19, 2005
    Posts: 2
    Well, I think the problem is that httpunit is not downloading the page completely, so I get some of html, but do not get the buttons/links.

    I do get them when I set breakpoint and examine html, I suppose this gives httpunit some time to get full page.

    My question is how do I get httpunit wait for whole page to load?
    Robert Watkins
    Greenhorn

    Joined: Sep 20, 2005
    Posts: 25
    Read the source, Luke... HttpUnit already does wait for the page to load.

    Check out the WebResponse class... getForms() calls getReceivedPage() which calls getText(), which calls loadResponseText(), which blocks and gets all the data as long as there is data to read.

    I seriously recommend you assert the number of buttons, and dump the respone text if the length is wrong - this will let you examine the situation in the wild _after_ the problem is detected (which avoids any timing problems).

    FWIW: The only time I ever saw a similar problem, it was a badly configured proxy server in the middle - it would occasionally truncate responses, usually on a 4K boundary.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: HttpUnit problems