Java Code Examples for com.meterware.httpunit.WebResponse#getForms()

The following examples show how to use com.meterware.httpunit.WebResponse#getForms() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnonPortalTest.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
 * @param resp
 * @param i
 * @throws SAXException
 * @throws IOException
 */
private void clickAll(WebResponse resp, int i, int maxDepth) throws SAXException,
		IOException
{

	if (i > maxDepth) return;
	processLinks(resp,i+1,maxDepth);
	
	WebForm[] formst = resp.getForms();
	log.info("Found "+formst.length+" forms");
	for ( WebForm f : formst ) {
		log.info("Processing "+f.getMethod()+" "+f.getAction());
		if ( "post".equals(f.getMethod()) ) {
			WebResponse formResp = performAction(f);
			if ( formResp != null ) {
				processLinks(formResp,i+1,maxDepth);
			}
		}
	}
}
 
Example 2
Source File: LinkTagTest.java    From ontopia with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the usage of the <webed:link> tag.
 * Tests that the tag submits the form and that it forwards to the 
 * correct page.
 */
public void testLinkTag() throws Exception {
  // First remove topics that may give the test false positives.
  WebResponse resp = wc.getResponse(webedTestLocation
      + "/test/LinkTag/testLinkTagCleanup.jsp");
  WebForm form = resp.getForms()[0];
  form.submit();
  
  // Go to the test page.
  resp = wc.getResponse(webedTestLocation
      + "/test/LinkTag/testLinkTag.jsp");
  // Make sure that no topics that could cause false positives exist.
  assertTrue("testLinkTag topic already exists before the test." , 
      wc.getCurrentPage().getText().indexOf("Topics: {}") >= 0);

  // Click the link.
  resp.getLinkWith("add topic with name \"testLinkTag\".").click();
  
  // Get the new page.
  resp = wc.getCurrentPage();
  // Check that one topic was created (and given name) as required.
  assertTrue("testLinkTag topic was not created by test." + wc.getCurrentPage().getText(), 
      wc.getCurrentPage().getText().indexOf("Topics: {1}") >= 0);
}
 
Example 3
Source File: ButtonTagTest.java    From ontopia with Apache License 2.0 6 votes vote down vote up
public void testImageAttributesButtonMapAbsoluteSrc () throws Exception {

  WebResponse resp = wc.getResponse(webedTestLocation
      + "/test/ButtonTag/testImageAttributesButtonMapAbsoluteSrc.jsp");
  WebForm form = resp.getForms()[0];
  // The button is rendered as the last item in the frames DOM
  Node button = getLastElementChild(form.getDOMSubtree());
  
  checkAttribute(button, "src","button.gif");
  checkAttribute(button, "border", "0");
  checkCommonImageAttributes(button);
  
  //Submit the form to check that no problems occur
  form.getButtons()[0].click();
  // Check for the correct forward
  assertEquals("Incorrect Result", webedTestApplication
      + "/test/defaultForward.html", wc.getCurrentPage().getURL().getPath());

}
 
Example 4
Source File: ListTagTest.java    From ontopia with Apache License 2.0 6 votes vote down vote up
public void testScrollingAttributes () throws Exception {
  
  WebResponse resp = wc.getResponse(webedTestLocation
      + "/test/ListTag/testScrollingAttributes.jsp");
  WebForm form = resp.getForms()[0];
  Node node = getLastElementChild(form.getDOMSubtree());
  
  checkScrollingAttributes(node, "-- unspecified --");
  
  //Submit the form to check that no problems occur
  form.submit();
  // Check for the correct forward
  assertEquals("Incorrect Result", webedTestApplication
      + "/test/defaultForward.html", wc.getCurrentPage().getURL().getPath());
  
}
 
Example 5
Source File: GeneralActionTest.java    From ontopia with Apache License 2.0 6 votes vote down vote up
public void testNotExclusive() throws Exception {

  WebResponse response = wc.getResponse(webedTestLocation
      + "/test/General/testNotExclusiveAction.jsp");
  
  WebForm form = response.getForms()[0];
  // Modify both fields
  form.setParameter(response.getElementWithID("NET1").getName(), "NET1V" );
  form.setParameter(response.getElementWithID("NET2").getName(), "NET2V");
  //Submit the form
  form.getButtons()[0].click();
  // Since neither action is exclusive, the response text should contain 
  // both "NET1V" and "NET2V"
  assertTrue("Response does not contain the expected text 'NET1V'", wc.getCurrentPage().getText().indexOf("NET1V") >= 0);
  assertTrue("Response does not contain the expected text 'NET2V'", wc.getCurrentPage().getText().indexOf("NET2V") >= 0);
}
 
Example 6
Source File: FieldTagTest.java    From ontopia with Apache License 2.0 6 votes vote down vote up
public void testHiddenAttributes () throws Exception {

  WebResponse resp = wc.getResponse(webedTestLocation
      + "/test/FieldTag/testHiddenAttributes.jsp");
  WebForm form = resp.getForms()[0];
  // The field is rendered as the last item in the frames DOM
  Node node = getLastElementChild(form.getDOMSubtree());
  
  checkType(node, "input");
  checkAttribute(node, "value", "VALUE");
  checkAttribute(node, "type", "hidden");
  checkCommonAttributes(node);
  
  //Submit the form to check that no problems occur
  form.submit();
  // Check for the correct forward
  assertEquals("Incorrect Result", webedTestApplication
      + "/test/defaultForward.html", wc.getCurrentPage().getURL().getPath());
  
}
 
Example 7
Source File: ListTagTest.java    From ontopia with Apache License 2.0 6 votes vote down vote up
public void testMultiselectAttributes () throws Exception {
  
  WebResponse resp = wc.getResponse(webedTestLocation
      + "/test/ListTag/testMultiselectAttributes.jsp");
  WebForm form = resp.getForms()[0];
  Node node = getLastElementChild(form.getDOMSubtree());
  
  checkMultiselectAttributes(node, "-- unspecified --");
  
  //Submit the form to check that no problems occur
  form.submit();
  // Check for the correct forward
  assertEquals("Incorrect Result", webedTestApplication
      + "/test/defaultForward.html", wc.getCurrentPage().getURL().getPath());
  
}
 
Example 8
Source File: ButtonTagTest.java    From ontopia with Apache License 2.0 6 votes vote down vote up
public void testImageAttributesButtonMapSrc () throws Exception {

  WebResponse resp = wc.getResponse(webedTestLocation
      + "/test/ButtonTag/testImageAttributesButtonMapSrc.jsp");
  WebForm form = resp.getForms()[0];
  // The button is rendered as the last item in the frames DOM
  Node button = getLastElementChild(form.getDOMSubtree());
  
  checkAttribute(button, "src", webedTestApplication + "/test/ButtonTag/button.gif");
  checkAttribute(button, "border", "0");
  checkCommonImageAttributes(button);
  
  //Submit the form to check that no problems occur
  form.getButtons()[0].click();
  // Check for the correct forward
  assertEquals("Incorrect Result", webedTestApplication
      + "/test/defaultForward.html", wc.getCurrentPage().getURL().getPath());

}
 
Example 9
Source File: InvokeTagTest.java    From ontopia with Apache License 2.0 6 votes vote down vote up
public void testTopicValueAttributes () throws Exception {  
  WebResponse resp = wc.getResponse(webedTestLocation
      + "/test/InvokeTag/testTopicValueAttributes.jsp");
  WebForm form = resp.getForms()[0];
  Node node = getLastElementChild(form.getDOMSubtree());
  
  // The "1" is the objectId of the TM object passed as the value.
  // Since we do not have access to the TM here, we must just do a 
  // hard coded check. 
  // NOTE: this value may change if the LTM parser changes.
  checkAttribute(node, "value", "1");
  checkCommonAttributes(node);
  
  //Submit the form to check that no problems occur
  form.submit();
  // Check for the correct forward
  assertEquals("Incorrect Result", webedTestApplication
      + "/test/defaultForward.html", wc.getCurrentPage().getURL().getPath());
  
}
 
Example 10
Source File: ButtonTagTest.java    From ontopia with Apache License 2.0 6 votes vote down vote up
public void testImageAttributesNoButtonMapImage () throws Exception {

  WebResponse resp = wc.getResponse(webedTestLocation
      + "/test/ButtonTag/testImageAttributesNoButtonMapImage.jsp");
  WebForm form = resp.getForms()[0];
  // The button is rendered as the last item in the frames DOM
  Node button = getLastElementChild(form.getDOMSubtree());
  
  checkAttribute(button, "src", "button.gif");
  checkCommonImageAttributes(button);
  
  //Submit the form to check that no problems occur
  form.getButtons()[0].click();
  // Check for the correct forward
  assertEquals("Incorrect Result", webedTestApplication
      + "/test/defaultForward.html", wc.getCurrentPage().getURL().getPath());

}
 
Example 11
Source File: MockLearner.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private WebResponse handleActivity(WebResponse resp) throws SAXException, IOException, InterruptedException {
// log.debug(resp.getText());

WebResponse nextResp = null;
WebForm[] forms = resp.getForms();
if ((forms != null) && (forms.length > 0)) {
    log.debug("There " + (forms.length == 1 ? "is " : "are ") + forms.length
	    + (forms.length == 1 ? " form in the page " : " forms in the page"));
    nextResp = handlePageWithForms(resp);
    
} else {
    nextResp = handlePageWithoutForms(resp);
}

return isActivityFinished(nextResp) ? nextResp : handleActivity(nextResp);
   }
 
Example 12
Source File: ListTagTest.java    From ontopia with Apache License 2.0 5 votes vote down vote up
public void testRadioAttributes () throws Exception {
  
  WebResponse resp = wc.getResponse(webedTestLocation
      + "/test/ListTag/testRadioAttributes.jsp");
  WebForm form = resp.getForms()[0];
  Node node = getLastElementChild(form.getDOMSubtree());
  
  checkCommonRadioAttributes(node);
  
  HashMap knownContents = getKnownContents();
  
  for (int i = 0; i < getElementChildCount(node); i=i+2) {
    Node option = getNthElementChild(node, i);
    checkType(option, "input");
    checkNameAttribute(option, "listTest");
    String objectId = option.getAttributes().getNamedItem("value").getNodeValue();
    String value = option.getNextSibling().getNodeValue();
    
    if (selectedObjectId().equals(objectId)) checkAttribute(option, "checked", "checked");
    String text = (String)knownContents.get(objectId);
    assertNotNull("Unexpected option - value: "+ objectId + " with content: " + value, text);
    assertEquals("Incorrect option content", text, value);
    knownContents.remove(objectId);
  }
  
  assertTrue("Items expected but not found: " + knownContents, knownContents.isEmpty());
  
  //Submit the form to check that no problems occur
  form.submit();
  // Check for the correct forward
  assertEquals("Incorrect Result", webedTestApplication
      + "/test/defaultForward.html", wc.getCurrentPage().getURL().getPath());
  
}
 
Example 13
Source File: ButtonTagTest.java    From ontopia with Apache License 2.0 5 votes vote down vote up
public void testReadonlyButtonTrue() throws Exception {
  WebResponse resp = wc.getResponse(webedTestLocation
      + "/test/ButtonTag/testReadonlyButtonTrue.jsp");
  WebForm form = resp.getForms()[0];
  // The button is rendered as the last item in the frames DOM
  Node button = getLastElementChild(form.getDOMSubtree());
  
  Node id = button.getAttributes().getNamedItem("id");
  assertFalse("Button element with readonly=\"true\" was rendered.", 
      id.getNodeValue().equals("ID"));
}
 
Example 14
Source File: InvokeTagTest.java    From ontopia with Apache License 2.0 5 votes vote down vote up
public void testReadonlyTrue() throws Exception {
  WebResponse resp = wc.getResponse(webedTestLocation
      + "/test/InvokeTag/testReadonlyTrue.jsp");
  WebForm form = resp.getForms()[0];
  // The invoke is rendered as the last item in the frames DOM
  Node invoke = getLastElementChild(form.getDOMSubtree());
  
  Node value = invoke.getAttributes().getNamedItem("value");
  assertFalse("Invoke element rendered on read-only form.", 
      value != null && value.getNodeValue().equals("no-value-given"));
}
 
Example 15
Source File: FieldTagTest.java    From ontopia with Apache License 2.0 5 votes vote down vote up
/**
 * Check the contents of a given input field.
 * @param fieldID The ID of the field.
 * @throws SAXException
 */
protected String getFieldValue(String fieldID, WebResponse response)
    throws SAXException {
  HTMLElement field = response.getElementWithID(fieldID);
  assertNotNull(field);
  WebForm forms[] = response.getForms();
  assertTrue(forms.length > 0);
  WebForm form = forms[1];
  return form.getParameterValue(field.getName());
}
 
Example 16
Source File: FormTagTest.java    From ontopia with Apache License 2.0 5 votes vote down vote up
public void testRelativeActionURI() throws Exception {   
  WebResponse resp = wc.getResponse(webedTestLocation
      + "/test/FormTag/testRelativeActionURI.jsp");
  WebForm form = resp.getForms()[0];
  
  assertEquals("Incorrect action", "TestTarget", form.getAction());
}
 
Example 17
Source File: MockUser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected WebForm fillForm(WebResponse resp, int formIndex, Map<String, Object> params)
    throws SAXException, IOException {
WebForm[] forms = resp.getForms();
if ((forms == null) || (forms.length <= formIndex)) {
    MockUser.log.debug(resp.getText());
    throw new TestHarnessException(username + " cannot find a form with index " + formIndex);
}
WebForm form = forms[formIndex];
if (params != null) {
    for (Map.Entry<String, Object> entry : params.entrySet()) {
	Object value = entry.getValue();
	if (value instanceof String) {
	    form.setParameter(entry.getKey(), (String) entry.getValue());
	} else if (value instanceof File) {
	    form.setParameter(entry.getKey(), (File) entry.getValue());
	} else if (value instanceof String[]) {
	    form.setParameter(entry.getKey(), (String[]) entry.getValue());
	} else if (value instanceof UploadFileSpec[]) {
	    form.setParameter(entry.getKey(), (UploadFileSpec[]) entry.getValue());
	} else {
	    throw new TestHarnessException(
		    "Unsupported parameter value type:" + entry.getValue().getClass().getName());
	}
    }
}
return form;
   }
 
Example 18
Source File: FieldTagTest.java    From ontopia with Apache License 2.0 5 votes vote down vote up
public void testReadonlyTrueFieldFalse() throws Exception {
  WebResponse resp = wc.getResponse(webedTestLocation
      + "/test/FieldTag/testReadonlyTrueFieldFalse.jsp");
  WebForm form = resp.getForms()[0];
  // The field is rendered as the last item in the frames DOM
  Node field = getLastElementChild(form.getDOMSubtree());
  
  Node id = field.getAttributes().getNamedItem("id");
  assertTrue("Field element with readonly=\"false\" not rendered on " +
      "read-only form.", 
      id.getNodeValue().equals("ID"));
}
 
Example 19
Source File: ButtonTagTest.java    From ontopia with Apache License 2.0 5 votes vote down vote up
public void testReadonlyButtonEvalFalse() throws Exception {
  WebResponse resp = wc.getResponse(webedTestLocation
      + "/test/ButtonTag/testReadonlyButtonEvalFalse.jsp");
  WebForm form = resp.getForms()[0];
  // The button is rendered as the last item in the frames DOM
  Node button = getLastElementChild(form.getDOMSubtree());
  
  Node id = button.getAttributes().getNamedItem("id");
  assertTrue("Button element with readonly evaluating to false was not " +
      "rendered.", id.getNodeValue().equals("ID"));
}
 
Example 20
Source File: FormTagTest.java    From ontopia with Apache License 2.0 4 votes vote down vote up
public void testAttributes() throws Exception {
  WebResponse resp = wc.getResponse(webedTestLocation
      + "/test/FormTag/testAttributes.jsp");
  WebForm form = resp.getForms()[0];
  Node formNode = form.getDOMSubtree();
  
  checkType(formNode, "form");
  checkAttribute(formNode, "id", "ID");
  checkAttribute(formNode, "method", "POST");
  checkAttribute(formNode, "name", Constants.FORM_EDIT_NAME);
  checkAttribute(formNode, "action", webedTestApplication + "/process");
  checkAttribute(formNode, "onsubmit", "return true;");
  checkForExtraAttributes(formNode);
  
  Node tm = getNthElementChild(formNode, 0);
  checkType(tm, "input");
  checkAttribute(tm, "type", "hidden");
  checkAttribute(tm, "name","tm");
  checkAttribute(tm, "value", "test.ltm");
  checkForExtraAttributes(tm);
      
  Node actionGroup = getNthElementChild(formNode, 1);
  checkType(actionGroup, "input");
  checkAttribute(actionGroup, "type", "hidden");
  checkAttribute(actionGroup, "name", "ag");
  checkAttribute(actionGroup, "value", "testActionGroup");
  checkForExtraAttributes(actionGroup);
  
  Node requestId = getNthElementChild(formNode, 2);
  checkType(requestId, "input");
  checkAttribute(requestId, "type", "hidden");
  checkAttribute(requestId, "name", "requestid");
  checkAttributeStartsWith(requestId, "value", "rid");
  checkForExtraAttributes(requestId);
  
  Node linkForward = getNthElementChild(formNode, 3);
  checkType(requestId, "input");
  checkAttribute(linkForward, "type", "hidden");
  checkAttribute(linkForward, "name", "linkforward");
  checkAttributeStartsWith(linkForward, "id", "linkforwardrid");
  checkForExtraAttributes(linkForward);
  
  assertNull("Unexpected element", getNthElementChild(formNode, 4));
 
  //Submit the form to check that no problems occur
  form.submit();
  // Check for the correct forward
  assertEquals("Incorrect Result", webedTestApplication
      + "/test/defaultForward.html", wc.getCurrentPage().getURL().getPath());
}