NullPointerException from getFormWithID
Brought to you by:
russgold
Here are the relevant lines of code from my .java files:
31 WebResponse resp = wc.getResponse(URL);
32 WebResponse content = wc.getFrameContents("content");
33 WebForm form = content.getForms()[0];
34 System.out.println("***** \"" + form.getID() + "\"");
35 form = content.getFormWithID("loginForm");
36 System.out.println(form.getID());
and here is the output in the terminal:
***** "loginForm"
java.lang.NullPointerException
at RealEdController.login(RealEdController.java:36)
Would you provide a little more context please? Your stack trace doesn't show any httpunit code in the trace. If you could post a junit test case to reproduce the problem that would be a big help.
Here's my attempt at a reproducer. It doesn't show the problem. Can you modify it to reproduce the problem?
/** Bug 3152752 from the sourceforge area */
public void testFrameNPE() throws Exception {
defineWebPage( "Text", "This is a trivial page" );
defineWebPage( "Form", "This is a page with a simple form: " +
"<form id='loginForm' action=submit><input type=submit></form>");
defineResource( "Frames.html",
"<html><head><frameset>" +
" <frame name='content' src='Form.html'>" +
" <frame name='text' src='Text.html'>" +
"</frameset></html>" );
WebConversation wc = new WebConversation();
WebResponse resp = wc.getResponse(getHostPath() + "/Frames.html");
assertNotNull(resp);
WebResponse content = wc.getFrameContents("content");
assertNotNull(content);
assertNotNull(content.getForms());
assertTrue(content.getForms().length > 0);
WebForm form = content.getForms()[0];
assertNotNull(form);
assertEquals("loginForm", form.getID());
form = content.getFormWithID("loginForm");
assertNotNull(form);
assertEquals("loginForm", form.getID());
}
Dear httpunit user!
Thank you for your bug report. We appreciate the time and effort you are putting into this.
Please supply a testcase with the expected result for the bug report that you are asking a solution for and we'll look into implementing it. For a start you might want to get the trunk version from the subversion repository (see https://sourceforge.net/svn/?group_id=6550\)
and have a look at the source code of some of the more than 700 JUnit based testcase in there.
If you do not use or have subversion tool you can still directly browse our test cases via:
http://httpunit.svn.sourceforge.net/viewvc/httpunit/trunk/httpunit/test/com/meterware/httpunit/
Looking into one or more of the Junit Java source files
should give you a clue on what a proper testcase for httpunit looks like, often you will probably only have to "clone" an existing testcase and modify it slightly to your needs.
When you are ready you might want to attach the testcase (and if you already have started implementing a solution for it it also the actual code) to the patch section of the sourceforge.net tracker for patches of the httpunit project at
https://sourceforge.net/tracker/?atid=306550&group_id=6550&func=browse.
The main communication about further details of the development is via the httpunit developer mailinglist. You are most welcome to sign up via
https://lists.sourceforge.net/lists/listinfo/httpunit-develop
Yours
The httpunit developer team
(Russell, Wolfgang, Mark, Patrick and Tim as of 2008-04)
Dear kinetic87
Thank you for your bug report.
Please supply a test case as per the FAX of the httpunit developer mailing list. At least we'd need some small html snippet that shows when the form id is set to null when it shouldn't be null.
Yours
Wolfgnag