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