use of com.gargoylesoftware.htmlunit.html.HtmlDefinitionList in project maven-doxia-sitetools by apache.
the class NestedItemsVerifier method verify.
/**
* {@inheritDoc}
*/
public void verify(String file) throws Exception {
HtmlPage page = htmlPage(file);
assertNotNull(page);
HtmlElement element = page.getHtmlElementById("contentBox");
assertNotNull(element);
HtmlDivision division = (HtmlDivision) element;
assertNotNull(division);
Iterator<HtmlElement> elementIterator = division.getHtmlElementDescendants().iterator();
// ----------------------------------------------------------------------
// Verify link
// ----------------------------------------------------------------------
HtmlSection section = (HtmlSection) elementIterator.next();
assertNotNull(section);
HtmlHeading2 h2 = (HtmlHeading2) elementIterator.next();
assertNotNull(h2);
assertEquals("List Section", h2.asText().trim());
HtmlAnchor a = (HtmlAnchor) elementIterator.next();
assertNotNull(a);
assertEquals("List_Section", a.getAttribute("name"));
// ----------------------------------------------------------------------
// Unordered lists
// ----------------------------------------------------------------------
section = (HtmlSection) elementIterator.next();
assertNotNull(section);
section = (HtmlSection) elementIterator.next();
assertNotNull(section);
HtmlHeading4 h4 = (HtmlHeading4) elementIterator.next();
assertNotNull(h4);
assertEquals("Unordered lists", h4.asText().trim());
a = (HtmlAnchor) elementIterator.next();
assertNotNull(a);
assertEquals("Unordered_lists", a.getAttribute("name"));
HtmlParagraph p = (HtmlParagraph) elementIterator.next();
assertNotNull(p);
assertEquals("Below is an unordered list, followed by six paragraphs.", p.asText().trim());
HtmlUnorderedList ul = (HtmlUnorderedList) elementIterator.next();
assertNotNull(ul);
HtmlListItem li = (HtmlListItem) elementIterator.next();
assertNotNull(li);
assertEquals("Item 1.", li.getFirstChild().asText().trim());
ul = (HtmlUnorderedList) elementIterator.next();
assertNotNull(ul);
li = (HtmlListItem) elementIterator.next();
assertNotNull(li);
p = (HtmlParagraph) elementIterator.next();
assertNotNull(p);
assertEquals("Item 11.", p.getFirstChild().asText().trim());
li = (HtmlListItem) elementIterator.next();
assertNotNull(li);
p = (HtmlParagraph) elementIterator.next();
assertNotNull(p);
assertEquals("Item 12.", p.getFirstChild().asText().trim());
li = (HtmlListItem) elementIterator.next();
assertNotNull(li);
assertEquals("Item 13.", li.getFirstChild().asText().trim());
li = (HtmlListItem) elementIterator.next();
assertNotNull(li);
assertEquals("Item 14.", li.getFirstChild().asText().trim());
li = (HtmlListItem) elementIterator.next();
assertNotNull(li);
assertEquals("Item 2.", li.getFirstChild().asText().trim());
li = (HtmlListItem) elementIterator.next();
assertNotNull(li);
assertEquals("Item 3.", li.getFirstChild().asText().trim());
li = (HtmlListItem) elementIterator.next();
assertNotNull(li);
assertEquals("Item 4.", li.getFirstChild().asText().trim());
ul = (HtmlUnorderedList) elementIterator.next();
assertNotNull(ul);
li = (HtmlListItem) elementIterator.next();
assertNotNull(li);
assertEquals("Item 41.", li.getFirstChild().asText().trim());
li = (HtmlListItem) elementIterator.next();
assertNotNull(li);
assertEquals("Item 42.", li.getFirstChild().asText().trim());
li = (HtmlListItem) elementIterator.next();
assertNotNull(li);
assertEquals("Item 43.", li.getFirstChild().asText().trim());
li = (HtmlListItem) elementIterator.next();
assertNotNull(li);
assertEquals("Item 44.", li.getFirstChild().asText().trim());
p = (HtmlParagraph) elementIterator.next();
assertNotNull(p);
assertEquals("Paragraph 1 below list.", p.asText().trim());
p = (HtmlParagraph) elementIterator.next();
assertNotNull(p);
assertEquals("Paragraph 2 below list.", p.asText().trim());
p = (HtmlParagraph) elementIterator.next();
assertNotNull(p);
assertEquals("Paragraph 3 below list.", p.asText().trim());
p = (HtmlParagraph) elementIterator.next();
assertNotNull(p);
assertEquals("Paragraph 4 below list.", p.asText().trim());
p = (HtmlParagraph) elementIterator.next();
assertNotNull(p);
assertEquals("Paragraph 5 below list.", p.asText().trim());
p = (HtmlParagraph) elementIterator.next();
assertNotNull(p);
assertEquals("Paragraph 6 below list.", p.asText().trim());
// ----------------------------------------------------------------------
// Ordered lists
// ----------------------------------------------------------------------
section = (HtmlSection) elementIterator.next();
assertNotNull(section);
h4 = (HtmlHeading4) elementIterator.next();
assertNotNull(h4);
assertEquals("Ordered lists", h4.asText().trim());
a = (HtmlAnchor) elementIterator.next();
assertNotNull(a);
assertEquals("Ordered_lists", a.getAttribute("name"));
p = (HtmlParagraph) elementIterator.next();
assertNotNull(p);
assertEquals("Below is an ordered list, followed by six paragraphs.", p.asText().trim());
HtmlOrderedList ol = (HtmlOrderedList) elementIterator.next();
assertNotNull(ol);
li = (HtmlListItem) elementIterator.next();
assertNotNull(li);
assertEquals("Item 1.", li.getFirstChild().asText().trim());
ol = (HtmlOrderedList) elementIterator.next();
assertNotNull(ol);
li = (HtmlListItem) elementIterator.next();
assertNotNull(li);
assertEquals("Item 11.", li.getFirstChild().asText().trim());
li = (HtmlListItem) elementIterator.next();
assertNotNull(li);
assertEquals("Item 12.", li.getFirstChild().asText().trim());
li = (HtmlListItem) elementIterator.next();
assertNotNull(li);
assertEquals("Item 13.", li.getFirstChild().asText().trim());
li = (HtmlListItem) elementIterator.next();
assertNotNull(li);
assertEquals("Item 14.", li.getFirstChild().asText().trim());
li = (HtmlListItem) elementIterator.next();
assertNotNull(li);
assertEquals("Item 2.", li.getFirstChild().asText().trim());
li = (HtmlListItem) elementIterator.next();
assertNotNull(li);
assertEquals("Item 3.", li.getFirstChild().asText().trim());
li = (HtmlListItem) elementIterator.next();
assertNotNull(li);
assertEquals("Item 4.", li.getFirstChild().asText().trim());
ol = (HtmlOrderedList) elementIterator.next();
assertNotNull(ol);
li = (HtmlListItem) elementIterator.next();
assertNotNull(li);
assertEquals("Item 41.", li.getFirstChild().asText().trim());
li = (HtmlListItem) elementIterator.next();
assertNotNull(li);
assertEquals("Item 42.", li.getFirstChild().asText().trim());
li = (HtmlListItem) elementIterator.next();
assertNotNull(li);
assertEquals("Item 43.", li.getFirstChild().asText().trim());
li = (HtmlListItem) elementIterator.next();
assertNotNull(li);
assertEquals("Item 44.", li.getFirstChild().asText().trim());
p = (HtmlParagraph) elementIterator.next();
assertNotNull(p);
assertEquals("Paragraph 1 below list.", p.asText().trim());
p = (HtmlParagraph) elementIterator.next();
assertNotNull(p);
assertEquals("Paragraph 2 below list.", p.asText().trim());
p = (HtmlParagraph) elementIterator.next();
assertNotNull(p);
assertEquals("Paragraph 3 below list.", p.asText().trim());
p = (HtmlParagraph) elementIterator.next();
assertNotNull(p);
assertEquals("Paragraph 4 below list.", p.asText().trim());
p = (HtmlParagraph) elementIterator.next();
assertNotNull(p);
assertEquals("Paragraph 5 below list.", p.asText().trim());
p = (HtmlParagraph) elementIterator.next();
assertNotNull(p);
assertEquals("Paragraph 6 below list.", p.asText().trim());
// ----------------------------------------------------------------------
// Definition lists
// ----------------------------------------------------------------------
section = (HtmlSection) elementIterator.next();
assertNotNull(section);
h4 = (HtmlHeading4) elementIterator.next();
assertNotNull(h4);
assertEquals("Definition lists", h4.asText().trim());
a = (HtmlAnchor) elementIterator.next();
assertNotNull(a);
assertEquals("Definition_lists", a.getAttribute("name"));
p = (HtmlParagraph) elementIterator.next();
assertNotNull(p);
assertEquals("Below is a definition list, followed by six paragraphs.", p.asText().trim());
HtmlDefinitionList dl = (HtmlDefinitionList) elementIterator.next();
assertNotNull(dl);
HtmlDefinitionTerm dt = (HtmlDefinitionTerm) elementIterator.next();
assertNotNull(dt);
assertEquals("Term 1.", dt.getFirstChild().asText().trim());
HtmlDefinitionDescription dd = (HtmlDefinitionDescription) elementIterator.next();
assertNotNull(dd);
assertEquals("Description 1.", dd.getFirstChild().asText().trim());
dt = (HtmlDefinitionTerm) elementIterator.next();
assertNotNull(dt);
assertEquals("Term 2.", dt.getFirstChild().asText().trim());
dd = (HtmlDefinitionDescription) elementIterator.next();
assertNotNull(dd);
assertEquals("Description 2.", dd.getFirstChild().asText().trim());
dl = (HtmlDefinitionList) elementIterator.next();
assertNotNull(dl);
dt = (HtmlDefinitionTerm) elementIterator.next();
assertNotNull(dt);
assertEquals("Term 21.", dt.getFirstChild().asText().trim());
dd = (HtmlDefinitionDescription) elementIterator.next();
assertNotNull(dd);
assertEquals("Description 21.", dd.getFirstChild().asText().trim());
p = (HtmlParagraph) elementIterator.next();
assertNotNull(p);
assertEquals("Paragraph 1 below list.", p.asText().trim());
p = (HtmlParagraph) elementIterator.next();
assertNotNull(p);
assertEquals("Paragraph 2 below list.", p.asText().trim());
p = (HtmlParagraph) elementIterator.next();
assertNotNull(p);
assertEquals("Paragraph 3 below list.", p.asText().trim());
p = (HtmlParagraph) elementIterator.next();
assertNotNull(p);
assertEquals("Paragraph 4 below list.", p.asText().trim());
p = (HtmlParagraph) elementIterator.next();
assertNotNull(p);
assertEquals("Paragraph 5 below list.", p.asText().trim());
p = (HtmlParagraph) elementIterator.next();
assertNotNull(p);
assertEquals("Paragraph 6 below list.", p.asText().trim());
assertFalse(elementIterator.hasNext());
}
use of com.gargoylesoftware.htmlunit.html.HtmlDefinitionList in project maven-doxia-sitetools by apache.
the class FaqVerifier method verify.
/**
* {@inheritDoc}
*/
public void verify(String file) throws Exception {
HtmlPage page = htmlPage(file);
assertNotNull(page);
HtmlElement element = page.getHtmlElementById("contentBox");
assertNotNull(element);
HtmlDivision division = (HtmlDivision) element;
assertNotNull(division);
Iterator<HtmlElement> elementIterator = division.getHtmlElementDescendants().iterator();
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
HtmlSection section = (HtmlSection) elementIterator.next();
HtmlHeading2 h2 = (HtmlHeading2) elementIterator.next();
assertEquals("Oft Asked Questions", h2.asText().trim());
HtmlAnchor a = (HtmlAnchor) elementIterator.next();
assertEquals(a.getAttribute("name"), "Oft_Asked_Questions");
a = (HtmlAnchor) elementIterator.next();
assertEquals("top", a.getAttribute("name"));
HtmlParagraph p = (HtmlParagraph) elementIterator.next();
element = elementIterator.next();
assertEquals("b", element.getTagName());
assertEquals("Contributing", element.asText().trim());
HtmlOrderedList ol = (HtmlOrderedList) elementIterator.next();
assertEquals("One stupid question & a silly answer?", ol.getFirstElementChild().asText().trim());
HtmlListItem li = (HtmlListItem) elementIterator.next();
assertEquals("One stupid question & a silly answer?", li.getFirstElementChild().asText().trim());
a = (HtmlAnchor) elementIterator.next();
assertEquals("#stupid-question", a.getAttribute("href"));
element = elementIterator.next();
assertEquals("b", element.getTagName());
assertEquals("stupid", element.asText().trim());
p = (HtmlParagraph) elementIterator.next();
element = elementIterator.next();
assertEquals("b", element.getTagName());
assertEquals("Using Maven", element.asText().trim());
ol = (HtmlOrderedList) elementIterator.next();
assertEquals("How do I disable a report on my site?", ol.getFirstElementChild().asText().trim());
li = (HtmlListItem) elementIterator.next();
assertNotNull(li);
assertEquals("How do I disable a report on my site?", li.getFirstElementChild().asText().trim());
a = (HtmlAnchor) elementIterator.next();
assertEquals("#disable-reports", a.getAttribute("href"));
section = (HtmlSection) elementIterator.next();
h2 = (HtmlHeading2) elementIterator.next();
assertEquals("Contributing", h2.asText().trim());
a = (HtmlAnchor) elementIterator.next();
assertEquals("Contributing", a.getAttribute("name"));
HtmlDefinitionList dl = (HtmlDefinitionList) elementIterator.next();
HtmlDefinitionTerm dt = (HtmlDefinitionTerm) elementIterator.next();
assertEquals("One stupid question & a silly answer?", dt.getFirstChild().asText().trim());
a = (HtmlAnchor) elementIterator.next();
assertEquals("stupid-question", a.getAttribute("name"));
element = elementIterator.next();
assertEquals("b", element.getTagName());
assertEquals("stupid", element.asText().trim());
HtmlDefinitionDescription dd = (HtmlDefinitionDescription) elementIterator.next();
p = (HtmlParagraph) elementIterator.next();
a = (HtmlAnchor) elementIterator.next();
assertEquals("#Using_Maven", a.getAttribute("href"));
assertEquals("local link", a.asText().trim());
a = (HtmlAnchor) elementIterator.next();
assertEquals("./cdc.html", a.getAttribute("href"));
assertEquals("source document", a.asText().trim());
a = (HtmlAnchor) elementIterator.next();
assertEquals("http://maven.apache.org/?l=a&m=b", a.getAttribute("href"));
assertEquals("external link", a.asText().trim());
element = elementIterator.next();
assertEquals("i", element.getTagName());
assertEquals("italic", element.asText().trim());
element = elementIterator.next();
assertEquals("b", element.getTagName());
assertEquals("non-US-ASCII characters: àéèç", element.asText().trim());
p = (HtmlParagraph) elementIterator.next();
assertEquals("right", p.getAttribute("align"));
a = (HtmlAnchor) elementIterator.next();
assertEquals("#top", a.getAttribute("href"));
assertEquals("[top]", a.asText().trim());
section = (HtmlSection) elementIterator.next();
h2 = (HtmlHeading2) elementIterator.next();
assertEquals("Using Maven", h2.asText().trim());
a = (HtmlAnchor) elementIterator.next();
assertEquals("Using_Maven", a.getAttribute("name"));
dl = (HtmlDefinitionList) elementIterator.next();
dt = (HtmlDefinitionTerm) elementIterator.next();
assertEquals("How do I disable a report on my site?", dt.getFirstChild().asText().trim());
a = (HtmlAnchor) elementIterator.next();
assertEquals("disable-reports", a.getAttribute("name"));
dd = (HtmlDefinitionDescription) elementIterator.next();
p = (HtmlParagraph) elementIterator.next();
element = elementIterator.next();
assertEquals("code", element.getTagName());
assertEquals("<source></source>", element.asText().trim());
HtmlDivision div = (HtmlDivision) elementIterator.next();
assertEquals("source", div.getAttribute("class"));
HtmlPreformattedText pre = (HtmlPreformattedText) elementIterator.next();
assertEquals("<source>1.5</source>", pre.asText().trim());
p = (HtmlParagraph) elementIterator.next();
assertEquals("right", p.getAttribute("align"));
a = (HtmlAnchor) elementIterator.next();
assertEquals("#top", a.getAttribute("href"));
assertEquals("[top]", a.asText().trim());
assertFalse(elementIterator.hasNext());
}
use of com.gargoylesoftware.htmlunit.html.HtmlDefinitionList in project htmlunit by HtmlUnit.
the class HTMLDListElementTest method simpleScriptable.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts("[object HTMLDListElement]")
public void simpleScriptable() throws Exception {
final String html = "<html><head>\n" + "<script>\n" + LOG_TITLE_FUNCTION + " function test() {\n" + " log(document.getElementById('myId'));\n" + " }\n" + "</script>\n" + "</head><body onload='test()'>\n" + " <dl id='myId'/>\n" + "</body></html>";
final WebDriver driver = loadPageVerifyTitle2(html);
if (driver instanceof HtmlUnitDriver) {
final WebElement element = driver.findElement(By.id("myId"));
assertTrue(toHtmlElement(element) instanceof HtmlDefinitionList);
}
}
Aggregations