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