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
19 import org.apache.commons.lang3.StringUtils;
20 import org.htmlunit.WebDriverTestCase;
21 import org.junit.jupiter.api.BeforeEach;
22 import org.junit.jupiter.api.Test;
23 import org.openqa.selenium.By;
24 import org.openqa.selenium.WebDriver;
25 import org.openqa.selenium.WebElement;
26
27
28
29
30
31
32
33
34 public abstract class MochiKitTest extends WebDriverTestCase {
35
36
37
38
39 public abstract String srcFolder();
40
41
42
43
44 @Test
45 public void async() throws Exception {
46 doTest("Async");
47 }
48
49
50
51
52 @Test
53 public void base() throws Exception {
54 doTest("Base");
55 }
56
57
58
59
60 @Test
61 public void color() throws Exception {
62 doTest("Color");
63 }
64
65
66
67
68 @Test
69 public void dateTime() throws Exception {
70 doTest("DateTime");
71 }
72
73
74
75
76 @Test
77 public void dom() throws Exception {
78 doTest("DOM");
79 }
80
81
82
83
84 @Test
85 public void domSafari() throws Exception {
86 doTest("DOM-Safari");
87 }
88
89
90
91
92
93
94
95
96
97
98
99
100
101 @Test
102 public void format() throws Exception {
103 doTest("Format");
104 }
105
106
107
108
109 @Test
110 public void iter() throws Exception {
111 doTest("Iter");
112 }
113
114
115
116
117 @Test
118 public void logging() throws Exception {
119 doTest("Logging");
120 }
121
122
123
124
125 @Test
126 public void mochiKit() throws Exception {
127 doTest("MochiKit");
128 }
129
130
131
132
133 @Test
134 public void selector() throws Exception {
135 doTest("Selector");
136 }
137
138
139
140
141 @Test
142 public void signal() throws Exception {
143 doTest("Signal");
144 }
145
146
147
148
149 @Test
150 public void style() throws Exception {
151 doTest("Style");
152 }
153
154
155
156
157 @Test
158 public void visual() throws Exception {
159 doTest("Visual");
160 }
161
162 private void doTest(final String testName) throws Exception {
163 final String url = URL_FIRST + "tests/test_MochiKit-" + testName + ".html";
164 assertNotNull(url);
165
166 final WebDriver driver = getWebDriver();
167 driver.get(url);
168
169
170 driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
171 driver.findElement(By.linkText("Toggle passed tests")).click();
172 driver.findElement(By.linkText("Toggle failed tests")).click();
173 driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(0));
174
175 String expected = loadExpectation(testName);
176 expected = expected.trim();
177 expected = StringUtils.replace(expected, "\r\n", "\n");
178 final WebElement div = driver.findElement(By.xpath("//div[@class = 'tests_report']"));
179
180 assertNotNull(div);
181 String actual = div.getText().trim();
182 actual = StringUtils.replace(actual, "\n\n", "\n");
183 assertEquals(expected.trim(), actual);
184 }
185
186 private String loadExpectation(final String testName) throws Exception {
187 final String resourcePrefix = "/libraries/MochiKit/" + srcFolder() + "/test-" + testName;
188 return loadExpectation(resourcePrefix, ".expected.txt");
189 }
190
191
192
193
194
195 @BeforeEach
196 public void setUp() throws Exception {
197 startWebServer("src/test/resources/libraries/MochiKit/" + srcFolder(), null, null);
198 }
199 }