1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.libraries;
16
17 import java.time.Duration;
18 import java.util.Arrays;
19 import java.util.Collections;
20 import java.util.List;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.htmlunit.WebDriverTestCase;
25 import org.htmlunit.junit.annotation.Alerts;
26 import org.htmlunit.junit.annotation.HtmlUnitNYI;
27 import org.junit.jupiter.api.Assertions;
28 import org.junit.jupiter.api.BeforeAll;
29 import org.junit.jupiter.api.Disabled;
30 import org.junit.jupiter.api.Test;
31 import org.openqa.selenium.By;
32 import org.openqa.selenium.WebDriver;
33 import org.openqa.selenium.WebDriverException;
34 import org.openqa.selenium.WebElement;
35
36
37
38
39
40
41
42
43
44
45 public class YuiTest extends WebDriverTestCase {
46 private static final Log LOG = LogFactory.getLog(YuiTest.class);
47
48
49
50
51 @BeforeAll
52 public static void startServer() throws Exception {
53 startWebServer("src/test/resources/libraries/yui/2.3.0", null);
54 }
55
56
57
58
59 @Test
60 public void logger() throws Exception {
61 doTest("logger.html");
62 }
63
64
65
66
67 @Test
68 public void animation() throws Exception {
69 doTest("animation.html");
70 }
71
72
73
74
75 @Test
76 public void tabView() throws Exception {
77 doTest("tabview.html");
78 }
79
80
81
82
83 @Test
84 public void dateMath() throws Exception {
85 doTest("datemath.html", "btnRun");
86 }
87
88
89
90
91 @Test
92 public void calendar() throws Exception {
93 doTest("calendar.html", "btnRun");
94 }
95
96
97
98
99 @Test
100 public void colorPicker() throws Exception {
101 doTest("colorpicker.html");
102 }
103
104
105
106
107 @Test
108 @Disabled
109 public void config() throws Exception {
110
111
112 Assertions.fail("YUI test has a bug that causes this to fail.");
113
114 }
115
116
117
118
119 @Test
120 public void dataSource() throws Exception {
121 doTest("datasource.html", "btnRun");
122 }
123
124
125
126
127 @Test
128 public void dom() throws Exception {
129 doTest("dom.html", Arrays.asList(getExpectedAlerts()));
130 }
131
132
133
134
135 @Test
136 public void dragDrop() throws Exception {
137 doTest("dragdrop.html", Arrays.asList(getExpectedAlerts()));
138 }
139
140
141
142
143 @Test
144 public void dataTable() throws Exception {
145 doTest("datatable.html", "btnRun");
146 }
147
148
149
150
151 @Test
152 @Alerts(CHROME = {"test_blank_image", "test_insertimage", "test_image_props",
153 "test_close_window", "test_regex",
154 "test_createlink", "test_selected_element", "test_dom_path"},
155 EDGE = {"test_blank_image", "test_insertimage", "test_image_props",
156 "test_close_window", "test_regex",
157 "test_createlink", "test_selected_element", "test_dom_path"},
158 FF = "test_createlink",
159 FF_ESR = "test_createlink")
160 @HtmlUnitNYI(CHROME = {"test_blank_image", "test_insertimage", "test_image_props",
161 "test_close_window", "test_bold", "test_selected_element",
162 "test_dom_path", "test_createlink"},
163 EDGE = {"test_blank_image", "test_insertimage", "test_image_props",
164 "test_close_window", "test_bold", "test_selected_element",
165 "test_dom_path", "test_createlink"},
166 FF = {"test_blank_image", "test_insertimage", "test_image_props",
167 "test_bold", "test_createlink", "test_hidden_elements"},
168 FF_ESR = {"test_blank_image", "test_insertimage", "test_image_props",
169 "test_bold", "test_createlink", "test_hidden_elements"})
170 public void editor() throws Exception {
171 doTest("editor.html", Arrays.asList(getExpectedAlerts()));
172 }
173
174
175
176
177 @Test
178 @Alerts("")
179 @HtmlUnitNYI(CHROME = "org.htmlunit.ScriptException: TypeError: Cannot call method \"appendChild\" of null",
180 EDGE = "org.htmlunit.ScriptException: TypeError: Cannot call method \"appendChild\" of null",
181 FF = "org.htmlunit.ScriptException: TypeError: Cannot call method \"appendChild\" of null",
182 FF_ESR = "org.htmlunit.ScriptException: TypeError: Cannot call method \"appendChild\" of null")
183 public void yuiLoaderRollup() throws Exception {
184 doTest("yuiloader_rollup.html");
185 }
186
187
188
189
190 @Test
191 @Alerts("test_page_modules")
192 public void yuiLoaderConfig() throws Exception {
193
194 doTest("yuiloader_config.html", Arrays.asList(getExpectedAlerts()));
195 }
196
197
198
199
200 @Test
201 public void yuiLoader() throws Exception {
202 doTest("yuiloader.html");
203 }
204
205
206
207
208 @Test
209 @Alerts("testConstructor")
210 public void module() throws Exception {
211 doTest("module.html", Arrays.asList(getExpectedAlerts()));
212 }
213
214
215
216
217 @Test
218 public void imageLoader() throws Exception {
219 doTest("imageloader.html");
220 }
221
222
223
224
225 @Test
226 public void element() throws Exception {
227 doTest("element.html");
228 }
229
230 private void doTest(final String fileName, final String buttonToClick) throws Exception {
231 doTest(fileName, Collections.emptyList(), buttonToClick, 0);
232 }
233
234 private void doTest(final String fileName) throws Exception {
235 doTest(fileName, Collections.emptyList(), null, 0);
236 }
237
238 private void doTest(final String fileName, final List<String> knownFailingTests) throws Exception {
239 doTest(fileName, knownFailingTests, null, 0);
240 }
241
242 private void doTest(final String fileName, final List<String> knownFailingTests,
243 final String buttonToPush, final long timeToWait) throws Exception {
244
245
246 final String url = URL_FIRST + "tests/" + fileName;
247 assertNotNull(url);
248
249 final WebDriver driver = getWebDriver();
250 try {
251 driver.get(url);
252 }
253 catch (final WebDriverException e) {
254 assertTrue(e.getMessage(), e.getMessage().startsWith(getExpectedAlerts()[0]));
255 return;
256 }
257
258 if (buttonToPush != null) {
259 driver.findElement(By.id(buttonToPush)).click();
260 }
261
262 driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
263 final WebElement logDiv = driver.findElement(By.className("yui-log-bd"));
264 final WebElement lastMessage = logDiv.findElement(
265 By.xpath("pre[last() and contains(string(.), 'Testing completed')]"));
266
267 LOG.info(lastMessage.getText());
268
269 driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(0));
270 final List<WebElement> tests = driver.findElements(By.xpath("//p[span[@class='pass' or @class='fail']]"));
271 if (tests.isEmpty()) {
272 Assertions.fail("No tests were executed!");
273 }
274
275 for (final WebElement pre : tests) {
276 final String[] parts = pre.getText().split(" ");
277 final String result = parts[0];
278 final String testName = parts[1].substring(0, parts[1].length() - 1);
279 if ("pass".equalsIgnoreCase(result)) {
280 assertTrue("Test case '" + testName + "' is in the known failing list, but passes!", !knownFailingTests
281 .contains(testName));
282 }
283 else {
284 assertTrue("Test case '" + testName + "' is not in the known failing list, but fails!",
285 knownFailingTests.contains(testName));
286 }
287 }
288 }
289 }