本文整理汇总了Java中com.meterware.httpunit.WebForm.getRequest方法的典型用法代码示例。如果您正苦于以下问题:Java WebForm.getRequest方法的具体用法?Java WebForm.getRequest怎么用?Java WebForm.getRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.meterware.httpunit.WebForm
的用法示例。
在下文中一共展示了WebForm.getRequest方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: logOn
import com.meterware.httpunit.WebForm; //导入方法依赖的package包/类
private WebResponse logOn(WebConversation wc, String url, String user, String password)
throws Exception {
WebRequest req = new GetMethodWebRequest(WEB_ROOT + url);
WebResponse resp = wc.getResponse(req);
assertEquals("Got To Log On Page", "Log On", resp.getTitle());
WebForm form = resp.getForms()[0];
WebRequest request = form.getRequest();
request.setParameter("j_username", user);
request.setParameter("j_password", password);
return wc.getResponse(request);
}
示例2: submitform
import com.meterware.httpunit.WebForm; //导入方法依赖的package包/类
/**
* Submit a HTML form using values defined in the specified form Element in the xml configuration file.
*
*@param formElement form Element
*@return Response Object
*@exception MalformedURLException URL Error
*@exception IOException HTTP Error
*@exception SAXException Error parsing HTML
*@exception Exception Description of Exception
*@since
*/
public void submitform(Element formElement) throws NoResponseToProcess, MalformedURLException, IOException, SAXException, Exception {
if (lastResponse == null)
throw new NoResponseToProcess();
assertNotNull("No form element defined", formElement);
String formName = formElement.getAttribute("name");
assertNotNull("Test data:: Cannot find <form name=\"" + formName + "\">", formElement);
WebForm form = lastResponse.getFormWithName(formName);
assertNotNull("No form of name '" + formName + "' found on page: " + lastResponse.getURL(), form);
int originalIdents[] = dbResource.getAllIdents();
WebRequest request = form.getRequest();
NodeList inputElements = formElement.getElementsByTagName("input");
List names = Arrays.asList(request.getRequestParameterNames());
for (int i = 0; i < inputElements.getLength(); i++) {
Element inputElement = (Element) inputElements.item(i);
if (inputElement.hasAttribute("set")) {
String value = mapResource.getRegex(inputElement.getAttribute("set"),lastResponse);
String ipname = inputElement.getAttribute("name");
assertTrue("No <input name='" + ipname + "' > in <form name='" + formName + "'>", names.contains(ipname));
request.setParameter(ipname, value);
debug("Set: " + inputElement.getAttribute("name") + " " + value);
}
}
try {
lastResponse = conversation.getResponse(request);
}
catch (HttpNotFoundException e) {
fail(e.getMessage());
}
lastResponseElement = formElement;
mapResponses.put(formName, lastResponse);
if (formElement.hasAttribute("submit"))
assertEquals(formElement.getAttribute("submit"), request.getURL().getFile());
int modifiedIdents[] = dbResource.getAllIdents();
dbResource.compareIdents(originalIdents, modifiedIdents, formElement);
}
示例3: applicationLogin
import com.meterware.httpunit.WebForm; //导入方法依赖的package包/类
private WebRequest applicationLogin(WebConversation conversation,
WebResponse response) throws SAXException, Exception {
WebRequest request;
WebForm loginForm = response.getForms()[0];
request = loginForm.getRequest();
SelectionFormControl asDorianOptions = (SelectionFormControl) response
.getElementWithID("dorianName");
request
.setParameter("dorianName",asDorianOptions.getOptionValues()[1]);
response = tryGetResponse(conversation, request);
loginForm = response.getForms()[0];
request = loginForm.getRequest();
SelectionFormControl asUrlOptions = (SelectionFormControl) response
.getElementWithID("authenticationServiceURL");
String[] urls = asUrlOptions.getOptionValues();
request.setParameter("authenticationServiceURL", urls[1]);
response = tryGetResponse(conversation, request);
loginForm = response.getForms()[0];
request = loginForm.getRequest();
request.setParameter("username", "jdoe2");
request.setParameter("password", "K00lM0N$$2");
return request;
}