1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.html;
16
17 import org.htmlunit.SimpleWebTestCase;
18 import org.junit.jupiter.api.Test;
19
20
21
22
23
24
25
26
27 public class HtmlOrderedListTest extends SimpleWebTestCase {
28
29
30
31
32 @Test
33 public void asNormalizedText() throws Exception {
34 final String html = DOCTYPE_HTML
35 + "<html><head>\n"
36 + "</head><body>\n"
37 + " <ol id='foo'>\n"
38 + " <li>first item</li>\n"
39 + " <li>second item</li>\n"
40 + "something without li node\n"
41 + " <li>third item</li>\n"
42 + " </ol>\n"
43 + " </table>\n"
44 + "</body></html>";
45
46 final HtmlPage page = loadPage(html);
47 final HtmlElement node = page.getHtmlElementById("foo");
48 final String expectedText = "1. first item"
49 + "\n2. second item"
50 + "\nsomething without li node"
51 + "\n3. third item";
52
53 assertEquals(expectedText, node.asNormalizedText());
54 assertEquals(expectedText, page.asNormalizedText());
55 }
56
57
58
59
60
61 @Test
62 public void asXml() throws Exception {
63 final String content = DOCTYPE_HTML
64 + "<html><head></head><body>\n"
65 + "<ol id='myNode'></ol>\n"
66 + "foo\n"
67 + "</form></body></html>";
68 final HtmlPage page = loadPage(content);
69 final HtmlElement element = page.getHtmlElementById("myNode");
70
71
72 assertEquals("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n"
73 + "<html>\r\n"
74 + " <head/>\r\n"
75 + " <body>\r\n"
76 + " <ol id=\"myNode\"></ol>\n"
77 + "foo\n"
78 + "</body>\r\n"
79 + "</html>", page.asXml());
80 }
81 }