Question: How to add new parameters to the form of WebResponse object?
emily chen <[email protected]>
| Newsgroups | gmane.comp.web.httpunit.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi there,
I am a new user of httpUnit test framework. so far so good.
For every page of my web application, I need to login the user first, then test the sequence pages according the navigation rules. For example:
1: login the user, if success, then redirect to “Register Computer Page”.
2: During processing the register computer, we need to read the active user information (userId/password, which was saved to HTTPRequest in “login page”) form HTTPRequest object, and get the relative data from database.
But in the “Register ComputerPage”, the userId/password doesn’t exist because of security issue. In order to pass the testing, I need to add two new parameters as hidden filed to the FROM of WebResponse object. I search the mailing list, and could not find the answer. Could anybody give me some suggestion?
Question: How to add new parameters to the form of WebResponse object?
Here is my testing code:
public void testGoodLogin() throws Exception {
HttpUnitOptions.setLoggingHttpHeaders(true);
HttpUnitOptions.setExceptionsThrownOnScriptError(false);
WebConversation conversation = new WebConversation();
WebRequest request = new GetMethodWebRequest("http://localhost:8080/merchant/");
WebResponse response = conversation.getResponse(request);
//Get the login page!!
WebForm loginForm = response.getForms()[0];
request = loginForm.getRequest();
request.setParameter("userid", "lucy");
request.setParameter("password", "lucy");
//submit the loginForm form.
loginForm.submit();
response = conversation.getResponse(request);
assertFalse("Login not accepted", response.getText().indexOf("Error: User/Password not found") != -1);
LOGGER.logDebug(response.getText());
// SUCCESSFUL LOGIN, AND REDIRECT TO “Register Computer” Page!!
boolean isRegisterComputerPage = response.getText().indexOf(" Register Computer") != -1;
if (isRegisterComputerPage) {
doRegisteredTerminal(response); //test “Register Computer” Page
}
}
private void doRegisteredTerminal(WebResponse response) throws Exception {
String testJspPageName = "SecuredTerminalRegister.jsp";
WebForm terminalForm = null;
try {
terminalForm = response.getFormWithName("terminalForm");
} catch (SAXException e) {
LOGGER.logDebug("Cound not find form with name: terminalForm in " + testJspPageName);
fail("Cound not find form with name: terminalForm in " + testJspPageName);
}
WebRequest request = terminalForm.getRequest();
//NEED TO ADD NEW PARAMETER: userId/password TO terminalForm.
// but I don’t know how???? The following code doesn’t work.
response.getScriptableObject().set("userid", "webpayadmin");
response.getScriptableObject().set("password", "yippee");
//selected the first terminal.
String[] selectedTerminals = terminalForm.getOptionValues("register");
String selectTerminalName = selectedTerminals[0];
request.setParameter("register", selectTerminalName);
//submit the “terminalForm” form.
try {
terminalForm.submit();
} catch (IOException e) {
e.printStackTrace();
fail("Submit terminalForm failed");
} catch (SAXException e) {
e.printStackTrace();
fail("Submit terminalForm failed");
}
}
.
____________________________________________________________________________________
Be a better Globetrotter. Get better travel answers from someone who knows. Yahoo! Answers - Check it out.
http://answers.yahoo.com/dir/?link=list&sid=396545469
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Httpunit-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/httpunit-develop