1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.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 import org.openqa.selenium.htmlunit.HtmlUnitDriver;
23
24
25
26
27
28
29
30
31 public class HtmlStyle2Test extends WebDriverTestCase {
32
33
34
35
36 @Test
37 @Alerts("[object HTMLStyleElement]")
38 public void simpleScriptable() throws Exception {
39 final String html = DOCTYPE_HTML
40 + "<html><head>\n"
41 + "<style type='text/css' id='myId'>\n"
42 + "img { border: 0px }\n"
43 + "</style>\n"
44 + "<script>\n"
45 + LOG_TITLE_FUNCTION
46 + " function test() {\n"
47 + " log(document.getElementById('myId'));\n"
48 + " }\n"
49 + "</script>\n"
50 + "</head><body onload='test()'>\n"
51 + "</body></html>";
52
53 final WebDriver driver = loadPageVerifyTitle2(html);
54 if (driver instanceof HtmlUnitDriver) {
55 final HtmlPage page = (HtmlPage) getEnclosedPage();
56 assertTrue(HtmlStyle.class.isInstance(page.getHtmlElementById("myId")));
57 }
58 }
59
60
61
62
63 @Test
64 public void getText() throws Exception {
65 final String html = DOCTYPE_HTML
66 + "<html>\n"
67 + "<head>\n"
68 + " <title>foo</title>\n"
69 + " <style type='text/css' id='s'>\n"
70 + " img { border: 0px }\n"
71 + " </style>\n"
72 + "</head>\n"
73 + "<body>\n"
74 + "</body>\n"
75 + "</html>";
76
77 final WebDriver driver = loadPage2(html);
78 final String text = driver.findElement(By.id("s")).getText();
79 assertEquals("", text);
80 }
81
82
83
84
85 @Test
86 public void isDisplayed() throws Exception {
87 final String html = DOCTYPE_HTML
88 + "<html>\n"
89 + "<head>\n"
90 + " <title>foo</title>\n"
91 + " <style type='text/css' id='s'>\n"
92 + " img { border: 0px }\n"
93 + " </style>\n"
94 + "</head>\n"
95 + "<body>\n"
96 + "</body>\n"
97 + "</html>";
98
99 final WebDriver driver = loadPage2(html);
100 final boolean displayed = driver.findElement(By.id("s")).isDisplayed();
101 assertFalse(displayed);
102 }
103 }