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

The following examples show how to use com.meterware.httpunit.WebResponse#getElementWithID() . 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: FieldTagTest.java    From ontopia with Apache License 2.0 5 votes vote down vote up
public void testTrimAttributeFalse () throws Exception {
  
  WebResponse resp = wc.getResponse(webedTestLocation
      + "/test/FieldTag/testTrimAttributeFalse.jsp");
  String original = wc.getResponse(webedTestLocation
      + "/test/FieldTag/value.txt").getText();

  HTMLElement field = resp.getElementWithID("FLD");
  WebForm form = resp.getForms()[0];
  String value = form.getParameterValue(field.getName());

  // Trimming should not be carried out
  assertEquals("Trimming occurred", original, value);

}
 
Example 2
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 3
Source File: FieldTagTest.java    From ontopia with Apache License 2.0 5 votes vote down vote up
/**
 * Change the contents of a given input field.
 * @param fieldID The ID of the field.
 * @param newValue The new value to put in the input field.
 * @throws SAXException
 */
protected void changeField(String fieldID, String newValue, 
    WebResponse response)
    throws SAXException {
  HTMLElement field = response.getElementWithID(fieldID);
  assertNotNull(field);
  WebForm forms[] = response.getForms();
  assertTrue(forms.length > 0);
  WebForm form = forms[1];
  form.setParameter(field.getName(), newValue);
}
 
Example 4
Source File: ViewToolsIT.java    From velocity-tools with Apache License 2.0 5 votes vote down vote up
/**
 * Utility function to check the text content of an HTML element
 * @param resp web response
 * @param id HTML element id
 * @param text expected start of the text
 * @throws Exception
 */
private void checkTextStart(WebResponse resp,String id,String text) throws Exception {
    HTMLElement element = resp.getElementWithID(id);
    assertNotNull(element);
    // do better reporting than assertTrue()
    if(!element.getText().startsWith(text))
    {
            throw new ComparisonFailure("Element id #" + id + " text does not start as expected:", element.getText() , text);
    }
}
 
Example 5
Source File: ViewToolsIT.java    From velocity-tools with Apache License 2.0 5 votes vote down vote up
/**
 * Utility function to check the text content of an HTML element
 * @param resp web response
 * @param id HTML element id
 * @param regex expected regex
 * @throws Exception
 */
private void checkTextRegex(WebResponse resp,String id,String regex) throws Exception {
    HTMLElement element = resp.getElementWithID(id);
    assertNotNull(element);
    Pattern pattern = Pattern.compile(regex);
    // strip new lines from string to be tested
    String text = element.getText().replace("\n","");
    Matcher matcher = pattern.matcher(text);
    if (!matcher.matches())
    {
        fail(element.getText()+" did not match "+regex);
    }
}
 
Example 6
Source File: ViewToolsIT.java    From velocity-tools with Apache License 2.0 3 votes vote down vote up
/**
 * Utility function to check the text content of an HTML element
 * @param resp web response
 * @param id HTML element id
 * @param start expected start of the text
 * @param end expected end of the text
 * @throws Exception
 */
private void checkTextStartEnd(WebResponse resp,String id,String start,String end) throws Exception {
    HTMLElement element = resp.getElementWithID(id);
    assertNotNull(element);
    assertTrue(element.getText().startsWith(start));
    assertTrue(element.getText().endsWith(end));
}
 
Example 7
Source File: ViewToolsIT.java    From velocity-tools with Apache License 2.0 2 votes vote down vote up
/**
 * Utility function to check the text content of an HTML element
 * @param resp web response
 * @param id HTML element id
 * @param text expected text
 * @throws Exception
 */
private void checkText(WebResponse resp,String id,String text) throws Exception {
    HTMLElement element = resp.getElementWithID(id);
    assertNotNull(element);
    assertEquals(text,element.getText());
}
 
Example 8
Source File: ViewToolsIT.java    From velocity-tools with Apache License 2.0 2 votes vote down vote up
/**
 * Utility function to check the text content of an HTML element
 * @param resp web response
 * @param id HTML element id
 * @param text expected contained text
 * @throws Exception
 */
private void checkTextContent(WebResponse resp,String id,String text) throws Exception {
    HTMLElement element = resp.getElementWithID(id);
    assertNotNull(element);
    assertTrue(element.getText().indexOf(text) != -1);
}