2202
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
1447
|
3 |
"{ Package: 'stx:goodies/regression' }"
|
359
|
4 |
|
|
5 |
"{ NameSpace: RegressionTests }"
|
|
6 |
|
|
7 |
TestCase subclass:#HTMLParserTests
|
|
8 |
instanceVariableNames:''
|
|
9 |
classVariableNames:''
|
|
10 |
poolDictionaries:''
|
1550
|
11 |
category:'tests-Regression-XML'
|
359
|
12 |
!
|
|
13 |
|
|
14 |
!HTMLParserTests class methodsFor:'documentation'!
|
|
15 |
|
|
16 |
documentation
|
|
17 |
"
|
|
18 |
documentation to be added.
|
|
19 |
|
|
20 |
[author:]
|
1447
|
21 |
mb (mb@SUNGSAM)
|
359
|
22 |
|
|
23 |
[instance variables:]
|
|
24 |
|
|
25 |
[class variables:]
|
|
26 |
|
|
27 |
[see also:]
|
|
28 |
|
|
29 |
"
|
|
30 |
!
|
|
31 |
|
|
32 |
history
|
|
33 |
"Created: / 15-01-2009 / 12:44:33 / mb"
|
|
34 |
! !
|
|
35 |
|
|
36 |
!HTMLParserTests methodsFor:'initialize / release'!
|
|
37 |
|
|
38 |
setUp
|
|
39 |
"common setup - invoked before testing."
|
|
40 |
|
1662
|
41 |
(Smalltalk classNamed:'stx_goodies_webServer_htmlTree') isNil ifTrue:[
|
|
42 |
(Smalltalk loadPackage:'stx:goodies/webServer/htmlTree') ifFalse:[
|
|
43 |
self error:'stx:goodies/webServer/htmlTree cannot be loaded'.
|
|
44 |
].
|
|
45 |
].
|
|
46 |
(Smalltalk classNamed:'stx_goodies_webServer_htmlTree') load.
|
|
47 |
|
|
48 |
"Modified: / 31-07-2017 / 11:40:25 / mawalch"
|
359
|
49 |
!
|
|
50 |
|
|
51 |
tearDown
|
|
52 |
"common cleanup - invoked after testing."
|
|
53 |
|
|
54 |
super tearDown
|
|
55 |
! !
|
|
56 |
|
|
57 |
!HTMLParserTests methodsFor:'tests'!
|
|
58 |
|
2202
|
59 |
test01a
|
|
60 |
"test the new parser"
|
|
61 |
|
359
|
62 |
|el|
|
|
63 |
|
|
64 |
el := HTML::HTMLParser parseText:'
|
|
65 |
<HEAD>
|
|
66 |
</HEAD>
|
|
67 |
'.
|
1677
|
68 |
"/ el inspect.
|
359
|
69 |
|
|
70 |
"
|
2202
|
71 |
self new test01a
|
359
|
72 |
"
|
2202
|
73 |
|
|
74 |
"Created: / 29-03-2019 / 10:35:20 / Claus Gittinger"
|
359
|
75 |
!
|
|
76 |
|
2202
|
77 |
test01b
|
|
78 |
"test the old parser"
|
|
79 |
|
|
80 |
|el|
|
|
81 |
|
|
82 |
el := HTMLParser parseText:'
|
|
83 |
<HEAD>
|
|
84 |
</HEAD>
|
|
85 |
'.
|
|
86 |
"/ el inspect.
|
|
87 |
|
|
88 |
"
|
|
89 |
self new test01b
|
|
90 |
"
|
|
91 |
|
|
92 |
"Created: / 29-03-2019 / 10:35:27 / Claus Gittinger"
|
|
93 |
!
|
|
94 |
|
|
95 |
test01c
|
|
96 |
"test the old parser"
|
|
97 |
|
|
98 |
|el|
|
|
99 |
|
|
100 |
el := HTMLParser parseText:'
|
|
101 |
<HTML>
|
|
102 |
<HEAD>
|
|
103 |
</HEAD>
|
|
104 |
</HTML>
|
|
105 |
'.
|
|
106 |
|
|
107 |
"
|
|
108 |
self new test01c
|
|
109 |
"
|
|
110 |
|
|
111 |
"Created: / 29-03-2019 / 11:22:27 / Claus Gittinger"
|
|
112 |
!
|
|
113 |
|
|
114 |
test02a
|
|
115 |
"test the new parser"
|
|
116 |
|
359
|
117 |
|doc|
|
|
118 |
|
|
119 |
doc := HTML::HTMLParser parseText:'
|
|
120 |
<!!--
|
|
121 |
Copyright 2004 ThoughtWorks, Inc
|
|
122 |
|
|
123 |
Licensed under the Apache License, Version 2.0 (the "License");
|
|
124 |
you may not use this file except in compliance with the License.
|
|
125 |
You may obtain a copy of the License at
|
|
126 |
|
|
127 |
http://www.apache.org/licenses/LICENSE-2.0
|
|
128 |
|
|
129 |
Unless required by applicable law or agreed to in writing, software
|
|
130 |
distributed under the License is distributed on an "AS IS" BASIS,
|
|
131 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
132 |
See the License for the specific language governing permissions and
|
|
133 |
limitations under the License.
|
|
134 |
-->
|
|
135 |
<html>
|
|
136 |
<head>
|
|
137 |
<meta content="text/html; charset=ISO-8859-1"
|
|
138 |
http-equiv="content-type">
|
|
139 |
<title>Test Open</title>
|
|
140 |
</head>
|
|
141 |
<body>
|
|
142 |
<table cellpadding="1" cellspacing="1" border="1">
|
|
143 |
<tbody>
|
|
144 |
<tr>
|
|
145 |
<td rowspan="1" colspan="3">Google Test Search<br>
|
|
146 |
</td>
|
|
147 |
</tr>
|
|
148 |
<tr>
|
|
149 |
<td>open</td>
|
|
150 |
<td>http://www.google.com/webhp?hl=en</td>
|
|
151 |
<td> </td>
|
|
152 |
</tr>
|
|
153 |
<tr>
|
|
154 |
<td>verifyTitle</td>
|
|
155 |
<td>Google</td>
|
|
156 |
<td> </td>
|
|
157 |
</tr>
|
|
158 |
<tr>
|
|
159 |
<td>type</td>
|
|
160 |
<td>q</td>
|
|
161 |
<td>Selenium OpenQA</td>
|
|
162 |
</tr>
|
|
163 |
<tr>
|
|
164 |
<td>verifyValue</td>
|
|
165 |
<td>q</td>
|
|
166 |
<td>Selenium OpenQA</td>
|
|
167 |
</tr>
|
|
168 |
<tr>
|
|
169 |
<td>clickAndWait</td>
|
|
170 |
<td>btnG</td>
|
|
171 |
<td> </td>
|
|
172 |
</tr>
|
|
173 |
<tr>
|
|
174 |
<td>verifyTextPresent</td>
|
|
175 |
<td>openqa.org</td>
|
|
176 |
<td> </td>
|
|
177 |
</tr>
|
|
178 |
<tr>
|
|
179 |
<td>verifyTitle</td>
|
|
180 |
<td>Selenium OpenQA - Google Search</td>
|
|
181 |
<td> </td>
|
|
182 |
</tr>
|
|
183 |
</tbody>
|
|
184 |
|
|
185 |
</table>
|
|
186 |
</body>
|
|
187 |
</html>
|
|
188 |
'.
|
1677
|
189 |
self assert:(doc children first tagName = 'head').
|
359
|
190 |
|
|
191 |
"
|
2202
|
192 |
self new test02a
|
359
|
193 |
"
|
2202
|
194 |
|
|
195 |
"Created: / 29-03-2019 / 10:35:45 / Claus Gittinger"
|
|
196 |
!
|
|
197 |
|
|
198 |
test02b
|
|
199 |
"test the old parser"
|
|
200 |
|
|
201 |
|doc firstMarkup|
|
|
202 |
|
|
203 |
doc := HTMLParser parseText:'
|
|
204 |
<!!--
|
|
205 |
Copyright 2004 ThoughtWorks, Inc
|
|
206 |
|
|
207 |
Licensed under the Apache License, Version 2.0 (the "License");
|
|
208 |
you may not use this file except in compliance with the License.
|
|
209 |
You may obtain a copy of the License at
|
|
210 |
|
|
211 |
http://www.apache.org/licenses/LICENSE-2.0
|
|
212 |
|
|
213 |
Unless required by applicable law or agreed to in writing, software
|
|
214 |
distributed under the License is distributed on an "AS IS" BASIS,
|
|
215 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
216 |
See the License for the specific language governing permissions and
|
|
217 |
limitations under the License.
|
|
218 |
-->
|
|
219 |
<html>
|
|
220 |
<head>
|
|
221 |
<meta content="text/html; charset=ISO-8859-1"
|
|
222 |
http-equiv="content-type">
|
|
223 |
<title>Test Open</title>
|
|
224 |
</head>
|
|
225 |
<body>
|
|
226 |
<table cellpadding="1" cellspacing="1" border="1">
|
|
227 |
<tbody>
|
|
228 |
<tr>
|
|
229 |
<td rowspan="1" colspan="3">Google Test Search<br>
|
|
230 |
</td>
|
|
231 |
</tr>
|
|
232 |
<tr>
|
|
233 |
<td>open</td>
|
|
234 |
<td>http://www.google.com/webhp?hl=en</td>
|
|
235 |
<td> </td>
|
|
236 |
</tr>
|
|
237 |
<tr>
|
|
238 |
<td>verifyTitle</td>
|
|
239 |
<td>Google</td>
|
|
240 |
<td> </td>
|
|
241 |
</tr>
|
|
242 |
<tr>
|
|
243 |
<td>type</td>
|
|
244 |
<td>q</td>
|
|
245 |
<td>Selenium OpenQA</td>
|
|
246 |
</tr>
|
|
247 |
<tr>
|
|
248 |
<td>verifyValue</td>
|
|
249 |
<td>q</td>
|
|
250 |
<td>Selenium OpenQA</td>
|
|
251 |
</tr>
|
|
252 |
<tr>
|
|
253 |
<td>clickAndWait</td>
|
|
254 |
<td>btnG</td>
|
|
255 |
<td> </td>
|
|
256 |
</tr>
|
|
257 |
<tr>
|
|
258 |
<td>verifyTextPresent</td>
|
|
259 |
<td>openqa.org</td>
|
|
260 |
<td> </td>
|
|
261 |
</tr>
|
|
262 |
<tr>
|
|
263 |
<td>verifyTitle</td>
|
|
264 |
<td>Selenium OpenQA - Google Search</td>
|
|
265 |
<td> </td>
|
|
266 |
</tr>
|
|
267 |
</tbody>
|
|
268 |
|
|
269 |
</table>
|
|
270 |
</body>
|
|
271 |
</html>
|
|
272 |
'.
|
|
273 |
firstMarkup := doc markup.
|
|
274 |
firstMarkup isTextElement ifTrue:[
|
|
275 |
firstMarkup := firstMarkup next
|
|
276 |
].
|
|
277 |
self assert:(firstMarkup tagName = 'html').
|
|
278 |
|
|
279 |
"
|
|
280 |
self new test02b
|
|
281 |
"
|
|
282 |
|
|
283 |
"Created: / 29-03-2019 / 10:35:55 / Claus Gittinger"
|
|
284 |
"Modified: / 29-03-2019 / 11:54:05 / Claus Gittinger"
|
359
|
285 |
!
|
|
286 |
|
|
287 |
test03
|
|
288 |
|doc|
|
|
289 |
|
|
290 |
doc := HTML::HTMLParser parseText:'
|
|
291 |
<!!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
292 |
<!!--
|
|
293 |
Copyright 2004 ThoughtWorks, Inc
|
|
294 |
|
|
295 |
Licensed under the Apache License, Version 2.0 (the "License");
|
|
296 |
you may not use this file except in compliance with the License.
|
|
297 |
You may obtain a copy of the License at
|
|
298 |
|
|
299 |
http://www.apache.org/licenses/LICENSE-2.0
|
|
300 |
|
|
301 |
Unless required by applicable law or agreed to in writing, software
|
|
302 |
distributed under the License is distributed on an "AS IS" BASIS,
|
|
303 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
304 |
See the License for the specific language governing permissions and
|
|
305 |
limitations under the License.
|
|
306 |
-->
|
|
307 |
<html>
|
|
308 |
<head>
|
|
309 |
<meta content="text/html; charset=ISO-8859-1"
|
|
310 |
http-equiv="content-type">
|
|
311 |
<title>Test Open</title>
|
|
312 |
</head>
|
|
313 |
<body>
|
|
314 |
<table cellpadding="1" cellspacing="1" border="1">
|
|
315 |
<tbody>
|
|
316 |
<tr>
|
|
317 |
<td rowspan="1" colspan="3">Google Test Search<br>
|
|
318 |
</td>
|
|
319 |
</tr>
|
|
320 |
<tr>
|
|
321 |
<td>open</td>
|
|
322 |
<td>http://www.google.com/webhp?hl=en</td>
|
|
323 |
<td> </td>
|
|
324 |
</tr>
|
|
325 |
<tr>
|
|
326 |
<td>verifyTitle</td>
|
|
327 |
<td>Google</td>
|
|
328 |
<td> </td>
|
|
329 |
</tr>
|
|
330 |
<tr>
|
|
331 |
<td>type</td>
|
|
332 |
<td>q</td>
|
|
333 |
<td>Selenium OpenQA</td>
|
|
334 |
</tr>
|
|
335 |
<tr>
|
|
336 |
<td>verifyValue</td>
|
|
337 |
<td>q</td>
|
|
338 |
<td>Selenium OpenQA</td>
|
|
339 |
</tr>
|
|
340 |
<tr>
|
|
341 |
<td>clickAndWait</td>
|
|
342 |
<td>btnG</td>
|
|
343 |
<td> </td>
|
|
344 |
</tr>
|
|
345 |
<tr>
|
|
346 |
<td>verifyTextPresent</td>
|
|
347 |
<td>openqa.org</td>
|
|
348 |
<td> </td>
|
|
349 |
</tr>
|
|
350 |
<tr>
|
|
351 |
<td>verifyTitle</td>
|
|
352 |
<td>Selenium OpenQA - Google Search</td>
|
|
353 |
<td> </td>
|
|
354 |
</tr>
|
|
355 |
</tbody>
|
|
356 |
|
|
357 |
</table>
|
|
358 |
</body>
|
|
359 |
</html>
|
|
360 |
'.
|
360
|
361 |
self assert:(doc children first tagName = 'head').
|
|
362 |
self assert:(doc docType = '-//W3C//DTD HTML 4.01 Transitional//EN').
|
359
|
363 |
|
|
364 |
"
|
|
365 |
self new test03
|
|
366 |
"
|
1975
|
367 |
!
|
|
368 |
|
|
369 |
test04_style
|
|
370 |
|doc headElement styleElement styleText|
|
|
371 |
|
|
372 |
"/ verify: no ampersand escaping in style elements
|
|
373 |
|
|
374 |
UserNotification ignoreIn:[
|
|
375 |
doc := HTML::HTMLParser parseText:'
|
|
376 |
<!!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
377 |
<html>
|
|
378 |
<head>
|
|
379 |
<style>foo bar &bla &froboz & & foo</style>
|
|
380 |
</head>
|
|
381 |
<body>
|
|
382 |
</body>
|
|
383 |
</html>
|
|
384 |
'.
|
|
385 |
].
|
|
386 |
headElement := doc children first.
|
|
387 |
self assert:(headElement tagName = 'head').
|
|
388 |
styleElement := headElement children first.
|
|
389 |
self assert:(styleElement tagName = 'style').
|
|
390 |
styleText := HTML::TextExtractor extractTextFromElement:styleElement.
|
1988
|
391 |
self assert:(styleText = 'foo bar &bla &froboz & & foo').
|
1975
|
392 |
|
|
393 |
"
|
|
394 |
self new test04_style
|
|
395 |
"
|
|
396 |
|
|
397 |
"Created: / 27-06-2018 / 12:58:48 / Claus Gittinger"
|
1988
|
398 |
"Modified: / 16-07-2018 / 19:49:23 / Claus Gittinger"
|
1975
|
399 |
!
|
|
400 |
|
|
401 |
test05_textExtraction
|
|
402 |
|doc bodyElement p|
|
|
403 |
|
|
404 |
"/ verify: no ampersand escaping in style elements
|
|
405 |
|
|
406 |
UserNotification ignoreIn:[
|
|
407 |
doc := HTML::HTMLParser parseText:'
|
|
408 |
<!!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
409 |
<html>
|
|
410 |
<body>
|
|
411 |
<p>
|
|
412 |
foo bar &bla &froboz & & foo
|
|
413 |
</p>
|
|
414 |
</body>
|
|
415 |
</html>
|
|
416 |
'.
|
|
417 |
].
|
|
418 |
bodyElement := doc body.
|
|
419 |
p := bodyElement children first.
|
|
420 |
self assert:(p extractedText = 'foo bar &bla &froboz & & foo').
|
|
421 |
|
|
422 |
"
|
|
423 |
self new test05_textExtraction
|
|
424 |
"
|
|
425 |
|
|
426 |
"Created: / 27-06-2018 / 15:28:31 / Claus Gittinger"
|
1987
|
427 |
!
|
|
428 |
|
|
429 |
test06_comments
|
|
430 |
|doc bodyElement|
|
|
431 |
|
|
432 |
"/ verify: no ampersand escaping in style elements
|
|
433 |
|
|
434 |
UserNotification ignoreIn:[
|
|
435 |
doc := HTML::HTMLParser parseText:'
|
|
436 |
<!!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
437 |
<html>
|
|
438 |
<body>
|
|
439 |
foo<!!--[foo]--><!!--bla-->bar
|
|
440 |
<!!--[foo]--><!!--bla-->
|
|
441 |
foo
|
|
442 |
<!!--[foo]--><!!--bla-->
|
|
443 |
bar
|
|
444 |
<!!--[foo]--><!!--bla-->
|
|
445 |
<p>
|
|
446 |
foo bar &bla &froboz & & foo
|
|
447 |
</p>
|
|
448 |
</body>
|
|
449 |
</html>
|
|
450 |
'.
|
|
451 |
].
|
|
452 |
bodyElement := doc body.
|
|
453 |
self assert:(bodyElement extractedText = 'foo bar foo bar foo bar &bla &froboz & & foo').
|
|
454 |
|
|
455 |
"
|
|
456 |
self new test06_comments
|
|
457 |
"
|
|
458 |
|
|
459 |
"Created: / 16-07-2018 / 19:43:12 / Claus Gittinger"
|
359
|
460 |
! !
|
|
461 |
|
|
462 |
!HTMLParserTests class methodsFor:'documentation'!
|
|
463 |
|
|
464 |
version
|
|
465 |
^ '$Header$'
|
1988
|
466 |
!
|
|
467 |
|
|
468 |
version_CVS
|
|
469 |
^ '$Header$'
|
359
|
470 |
! !
|
1550
|
471 |
|