1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.html;
16
17 import org.htmlunit.WebDriverTestCase;
18 import org.htmlunit.junit.annotation.Alerts;
19 import org.junit.jupiter.api.Test;
20 import org.openqa.selenium.By;
21 import org.openqa.selenium.WebDriver;
22
23
24
25
26
27
28
29
30
31
32 public class HTMLSpanElementTest extends WebDriverTestCase {
33
34
35
36
37 @Test
38 @Alerts("no")
39 public void doScroll() throws Exception {
40 final String html = DOCTYPE_HTML
41 + "<html>\n"
42 + " <head>\n"
43 + " <script>\n"
44 + LOG_TITLE_FUNCTION
45 + " function test() {\n"
46 + " var span = document.getElementById('s');\n"
47 + " if(span.doScroll) {\n"
48 + " log('yes');\n"
49 + " span.doScroll();\n"
50 + " span.doScroll('down');\n"
51 + " } else {\n"
52 + " log('no');\n"
53 + " }\n"
54 + " }\n"
55 + " </script>\n"
56 + " </head>\n"
57 + " <body onload='test()'><span id='s'>abc</span></body>\n"
58 + "</html>";
59
60 loadPageVerifyTitle2(html);
61 }
62
63
64
65
66 @Test
67 @Alerts("[object HTMLSpanElement] undefined")
68 public void cite() throws Exception {
69 final String html = DOCTYPE_HTML
70 + "<html>\n"
71 + " <head>\n"
72 + " <script>\n"
73 + LOG_TITLE_FUNCTION
74 + " function test() {\n"
75 + " debug(document.createElement('span'));\n"
76 + " }\n"
77 + " function debug(e) {\n"
78 + " log(e + ' ' + e.cite);\n"
79 + " }\n"
80 + " </script>\n"
81 + " </head>\n"
82 + " <body onload='test()'></body>\n"
83 + "</html>";
84
85 loadPageVerifyTitle2(html);
86 }
87
88
89
90
91 @Test
92 @Alerts("beforeSpace afterSpace")
93 public void getText() throws Exception {
94 final String html = DOCTYPE_HTML
95 + "<html><head></head><body>\n"
96 + "<div id='foo'><span>beforeSpace</span><span> </span><span>afterSpace</span></div>\n"
97 + "</body></html>";
98
99 final WebDriver driver = loadPage2(html);
100 assertEquals(getExpectedAlerts()[0], driver.findElement(By.id("foo")).getText());
101 }
102 }