Submitting a form doesn't appear to generate a new page...
"Richard Berger" <[email protected]>
| Newsgroups | gmane.comp.web.httpunit.devel |
|---|---|
| Message-ID | <[email protected]> |
Here's the situation:
....DrillSgt/drillservlet?Command=NewDrillCommand - provides the page
drill.jsp to the user. There are three forms on this page. The main
form (named "form") allows the user to enter an answer and push
submit. The form html looks like:
<form name="form" method="post"
action="drillservlet?Command=NewProblemCommand"
onsubmit="return(checkAndSubmit())">
...
<input type="submit" value="Submit" class="dsButton">
</form>
When the form is submitted, a new math problem is generated and the
page drill.jsp provided to the user with a new problem to solve.
When I try testing this in HttpUnit, I keep getting the same values on
the page - which is pretty much impossible statistically. I verified
that I am submitting the right form and have tried several different
ways of getting the updated page, including:
1. drillPage = doDrillForm.submit(); // This should update drillPage
to be the result of the submit, right?
2. submitButton.click(); conversation.getCurrentPage(); // Click the
submit button, then get the newly updated page from the conversation
Of course, this works fine by hand. Below is the code and the console
output....
public void testNewDrill() throws Exception {
WebConversation conversation = new WebConversation();
WebResponse welcomePage = login(conversation);
// Start a New Drill
WebForm newDrillForm = welcomePage.getForms()[0];
WebResponse drillPage = newDrillForm.submit();
HTMLElement numeratorElement = null;
HTMLElement denominatorElement = null;
HTMLElement operatorElement = null;
for (int i = 0; i < 4; i++ ) {
assertEquals("Page title", "\nDrill\n", drillPage.getTitle());
WebForm doDrillForm = drillPage.getFormWithName("form");
// Determine the problem
numeratorElement = drillPage.getElementWithID("Numerator");
denominatorElement = drillPage.getElementWithID("Denominator");
operatorElement = drillPage.getElementWithID("OperationSymbol");
System.out.println("Numerator: " + numeratorElement.getText());
System.out.println("Denominator: " + denominatorElement.getText());
// Solve the problem
String guess = computeStringAnswer(numeratorElement.getText(),
denominatorElement.getText(),
operatorElement.getText());
doDrillForm.setParameter("Guess", guess);
// Now get a new page by submitting this form
SubmitButton submitButton = doDrillForm.getSubmitButtons()[0];
assertEquals("NewProblemButton", submitButton.getID());
//submitButton.click();
drillPage = doDrillForm.submit(submitButton);
//drillPage = conversation.getCurrentPage();
}
Console output... (The Numerator and Denominator should be randomly
chosen between 1 and 10, odds of four exact matches in a row are about
1 in 100,000,000 :) ).
Numerator: 10
Denominator: 8
Numerator: 10
Denominator: 8
Numerator: 10
Denominator: 8
Numerator: 10
Denominator: 8
Thanks so much for any help or pointers!
RB
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV