1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.html.serializer;
16
17 import org.htmlunit.SimpleWebTestCase;
18 import org.htmlunit.html.DomElement;
19 import org.htmlunit.html.HtmlElement;
20 import org.htmlunit.html.HtmlNumberInput;
21 import org.htmlunit.html.HtmlPage;
22 import org.htmlunit.html.HtmlTable;
23 import org.htmlunit.html.HtmlTableCell;
24 import org.htmlunit.junit.annotation.Alerts;
25 import org.junit.jupiter.api.Test;
26
27
28
29
30
31
32
33 public class HtmlSerializerNormalizedText2Test extends SimpleWebTestCase {
34
35
36
37
38
39 @Test
40 @Alerts("\n")
41 public void getNormalizedTextWhiteSpaceBreak() throws Exception {
42 getNormalizedTextWhiteSpaceBreak(null);
43 }
44
45
46
47
48
49 @Test
50 @Alerts("\n")
51 public void getNormalizedTextWhiteSpaceBreakNormal() throws Exception {
52 getNormalizedTextWhiteSpaceBreak("normal");
53 }
54
55
56
57
58
59 @Test
60 @Alerts("\n")
61 public void getNormalizedTextWhiteSpaceBreakNowrap() throws Exception {
62 getNormalizedTextWhiteSpaceBreak("nowrap");
63 }
64
65
66
67
68
69 @Test
70 @Alerts("\n")
71 public void getNormalizedTextWhiteSpaceBreakPre() throws Exception {
72 getNormalizedTextWhiteSpaceBreak("pre");
73 }
74
75
76
77
78
79 @Test
80 @Alerts("\n")
81 public void getNormalizedTextWhiteSpaceBreakPreWrap() throws Exception {
82 getNormalizedTextWhiteSpaceBreak("pre-wrap");
83 }
84
85
86
87
88
89 @Test
90 @Alerts("\n")
91 public void getNormalizedTextWhiteSpaceBreakPreLine() throws Exception {
92 getNormalizedTextWhiteSpaceBreak("pre-line");
93 }
94
95 private void getNormalizedTextWhiteSpaceBreak(final String whiteSpace) throws Exception {
96 final String htmlContent = DOCTYPE_HTML
97 + "<html>\n"
98 + "<head></head>\n"
99 + "<body>\n"
100 + " <br id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">\n"
101 + "</body></html>";
102
103 final HtmlPage page = loadPage(htmlContent);
104
105 final String text = page.getElementById("tester").asNormalizedText();
106 assertEquals(getExpectedAlerts()[0], text);
107 }
108
109
110
111
112
113 @Test
114 @Alerts("")
115 public void getNormalizedTextWhiteSpaceInputHidden() throws Exception {
116 getNormalizedTextWhiteSpaceInputHidden(null);
117 }
118
119
120
121
122
123 @Test
124 @Alerts("")
125 public void getNormalizedTextWhiteSpaceInputHiddenNormal() throws Exception {
126 getNormalizedTextWhiteSpaceInputHidden("normal");
127 }
128
129
130
131
132
133 @Test
134 @Alerts("")
135 public void getNormalizedTextWhiteSpaceInputHiddenNowrap() throws Exception {
136 getNormalizedTextWhiteSpaceInputHidden("nowrap");
137 }
138
139
140
141
142
143 @Test
144 @Alerts("")
145 public void getNormalizedTextWhiteSpaceInputHiddenPre() throws Exception {
146 getNormalizedTextWhiteSpaceInputHidden("pre");
147 }
148
149
150
151
152
153 @Test
154 @Alerts("")
155 public void getNormalizedTextWhiteSpaceInputHiddenPreWrap() throws Exception {
156 getNormalizedTextWhiteSpaceInputHidden("pre-wrap");
157 }
158
159
160
161
162
163 @Test
164 @Alerts("")
165 public void getNormalizedTextWhiteSpaceInputHiddenPreLine() throws Exception {
166 getNormalizedTextWhiteSpaceInputHidden("pre-line");
167 }
168
169 private void getNormalizedTextWhiteSpaceInputHidden(final String whiteSpace) throws Exception {
170 final String htmlContent = DOCTYPE_HTML
171 + "<html>\n"
172 + "<head></head>\n"
173 + "<body>\n"
174 + "<form id='form1'>\n"
175 + " <input type='hidden' name='tester' id='tester' "
176 + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'"))
177 + " value=' A B C\t \t D \nEF\nG \n H <br> I '>\n"
178 + "</form>\n"
179 + "</body></html>";
180
181 final HtmlPage page = loadPage(htmlContent);
182
183 final String text = page.getElementById("tester").asNormalizedText();
184 assertEquals(getExpectedAlerts()[0], text);
185 }
186
187
188
189
190
191 @Test
192 @Alerts("")
193 public void getNormalizedTextWhiteSpaceScript() throws Exception {
194 getNormalizedTextWhiteSpaceScript(null);
195 }
196
197
198
199
200
201 @Test
202 @Alerts("")
203 public void getNormalizedTextWhiteSpaceScriptNormal() throws Exception {
204 getNormalizedTextWhiteSpaceScript("normal");
205 }
206
207
208
209
210
211 @Test
212 @Alerts("")
213 public void getNormalizedTextWhiteSpaceScriptNowrap() throws Exception {
214 getNormalizedTextWhiteSpaceScript("nowrap");
215 }
216
217
218
219
220
221 @Test
222 @Alerts("")
223 public void getNormalizedTextWhiteSpaceScriptPre() throws Exception {
224 getNormalizedTextWhiteSpaceScript("pre");
225 }
226
227
228
229
230
231 @Test
232 @Alerts("")
233 public void getNormalizedTextWhiteSpaceScriptPreWrap() throws Exception {
234 getNormalizedTextWhiteSpaceScript("pre-wrap");
235 }
236
237
238
239
240
241 @Test
242 @Alerts("")
243 public void getNormalizedTextWhiteSpaceScriptPreLine() throws Exception {
244 getNormalizedTextWhiteSpaceScript("pre-line");
245 }
246
247 private void getNormalizedTextWhiteSpaceScript(final String whiteSpace) throws Exception {
248 final String htmlContent = DOCTYPE_HTML
249 + "<html>\n"
250 + "<head></head>\n"
251 + "<body>\n"
252 + " <script id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">"
253 + "var x; \n \t \n var y;</script>\n"
254 + "</body></html>";
255
256 final HtmlPage page = loadPage(htmlContent);
257
258 final String text = page.getElementById("tester").asNormalizedText();
259 assertEquals(getExpectedAlerts()[0], text);
260 }
261
262
263
264
265
266 @Test
267 @Alerts("")
268 public void getNormalizedTextWhiteSpaceStyle() throws Exception {
269 getNormalizedTextWhiteSpaceStyle(null);
270 }
271
272
273
274
275
276 @Test
277 @Alerts("")
278 public void getNormalizedTextWhiteSpaceStyleNormal() throws Exception {
279 getNormalizedTextWhiteSpaceStyle("normal");
280 }
281
282
283
284
285
286 @Test
287 @Alerts("")
288 public void getNormalizedTextWhiteSpaceStyleNowrap() throws Exception {
289 getNormalizedTextWhiteSpaceStyle("nowrap");
290 }
291
292
293
294
295
296 @Test
297 @Alerts("")
298 public void getNormalizedTextWhiteSpaceStylePre() throws Exception {
299 getNormalizedTextWhiteSpaceStyle("pre");
300 }
301
302
303
304
305
306 @Test
307 @Alerts("")
308 public void getNormalizedTextWhiteSpaceStylePreWrap() throws Exception {
309 getNormalizedTextWhiteSpaceStyle("pre-wrap");
310 }
311
312
313
314
315
316 @Test
317 @Alerts("")
318 public void getNormalizedTextWhiteSpaceStylePreLine() throws Exception {
319 getNormalizedTextWhiteSpaceStyle("pre-line");
320 }
321
322 private void getNormalizedTextWhiteSpaceStyle(final String whiteSpace) throws Exception {
323 final String htmlContent = DOCTYPE_HTML
324 + "<html>\n"
325 + "<head></head>\n"
326 + "<body>\n"
327 + " <style id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">"
328 + " A B C\t \t D \nEF\nG \n H <br> I </style>\n"
329 + "</body></html>";
330
331 final HtmlPage page = loadPage(htmlContent);
332
333 final String text = page.getElementById("tester").asNormalizedText();
334 assertEquals(getExpectedAlerts()[0], text);
335 }
336
337
338
339
340
341 @Test
342 @Alerts("")
343 public void getNormalizedTextWhiteSpaceNoframes() throws Exception {
344 getNormalizedTextWhiteSpaceNoframes(null);
345 }
346
347
348
349
350
351 @Test
352 @Alerts("")
353 public void getNormalizedTextWhiteSpaceNoframesNormal() throws Exception {
354 getNormalizedTextWhiteSpaceNoframes("normal");
355 }
356
357
358
359
360
361 @Test
362 @Alerts("")
363 public void getNormalizedTextWhiteSpaceNoframesNowrap() throws Exception {
364 getNormalizedTextWhiteSpaceNoframes("nowrap");
365 }
366
367
368
369
370
371 @Test
372 @Alerts("")
373 public void getNormalizedTextWhiteSpaceNoframesPre() throws Exception {
374 getNormalizedTextWhiteSpaceNoframes("pre");
375 }
376
377
378
379
380
381 @Test
382 @Alerts("")
383 public void getNormalizedTextWhiteSpaceNoframesPreWrap() throws Exception {
384 getNormalizedTextWhiteSpaceNoframes("pre-wrap");
385 }
386
387
388
389
390
391 @Test
392 @Alerts("")
393 public void getNormalizedTextWhiteSpaceNoframesPreLine() throws Exception {
394 getNormalizedTextWhiteSpaceNoframes("pre-line");
395 }
396
397 private void getNormalizedTextWhiteSpaceNoframes(final String whiteSpace) throws Exception {
398 final String htmlContent = DOCTYPE_HTML
399 + "<html>\n"
400 + "<head></head>\n"
401 + "<body>\n"
402 + " <noframes id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">"
403 + " A B C\t \t D \nEF\nG \n H <br> I </noframes>\n"
404 + "</body></html>";
405
406 final HtmlPage page = loadPage(htmlContent);
407
408 final String text = page.getElementById("tester").asNormalizedText();
409 assertEquals(getExpectedAlerts()[0], text);
410 }
411
412
413
414
415
416 @Test
417 @Alerts("A B C D EF G H \n"
418 + " I")
419 public void getNormalizedTextWhiteSpaceDiv() throws Exception {
420 getNormalizedTextWhiteSpaceDiv(null);
421 }
422
423
424
425
426
427 @Test
428 @Alerts("A B C D EF G H \n"
429 + " I")
430 public void getNormalizedTextWhiteSpaceDivNormal() throws Exception {
431 getNormalizedTextWhiteSpaceDiv("normal");
432 }
433
434
435
436
437
438 @Test
439 @Alerts("A B C D EF G H \n"
440 + " I")
441 public void getNormalizedTextWhiteSpaceDivNowrap() throws Exception {
442 getNormalizedTextWhiteSpaceDiv("nowrap");
443 }
444
445
446
447
448
449 @Test
450 @Alerts("A B C D EF G H \n"
451 + " I")
452 public void getNormalizedTextWhiteSpaceDivPre() throws Exception {
453 getNormalizedTextWhiteSpaceDiv("pre");
454 }
455
456
457
458
459
460 @Test
461 @Alerts("A B C D EF G H \n"
462 + " I")
463 public void getNormalizedTextWhiteSpaceDivPreWrap() throws Exception {
464 getNormalizedTextWhiteSpaceDiv("pre-wrap");
465 }
466
467
468
469
470
471 @Test
472 @Alerts("A B C D EF G H \n"
473 + " I")
474 public void getNormalizedTextWhiteSpaceDivPreLine() throws Exception {
475 getNormalizedTextWhiteSpaceDiv("pre-line");
476 }
477
478 private void getNormalizedTextWhiteSpaceDiv(final String whiteSpace) throws Exception {
479 final String htmlContent = DOCTYPE_HTML
480 + "<html>\n"
481 + "<head></head>\n"
482 + "<body>\n"
483 + " <div id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">"
484 + " A B C\t \t D \nEF\nG \n H <br> I </div>\n"
485 + "</body></html>";
486
487 final HtmlPage page = loadPage(htmlContent);
488
489 final String text = page.getElementById("tester").asNormalizedText();
490 assertEquals(getExpectedAlerts()[0], text);
491 }
492
493
494
495
496
497 @Test
498 @Alerts(" A B C\t \t D \n"
499 + "EF\n"
500 + "G \n"
501 + " H I ")
502 public void getNormalizedTextWhiteSpacePre() throws Exception {
503 getNormalizedTextWhiteSpacePre(null);
504 }
505
506
507
508
509
510 @Test
511 @Alerts(" A B C\t \t D \n"
512 + "EF\n"
513 + "G \n"
514 + " H I ")
515 public void getNormalizedTextWhiteSpacePreNormal() throws Exception {
516 getNormalizedTextWhiteSpacePre("normal");
517 }
518
519
520
521
522
523 @Test
524 @Alerts(" A B C\t \t D \n"
525 + "EF\n"
526 + "G \n"
527 + " H I ")
528 public void getNormalizedTextWhiteSpacePreNowrap() throws Exception {
529 getNormalizedTextWhiteSpacePre("nowrap");
530 }
531
532
533
534
535
536 @Test
537 @Alerts(" A B C\t \t D \n"
538 + "EF\n"
539 + "G \n"
540 + " H I ")
541 public void getNormalizedTextWhiteSpacePrePre() throws Exception {
542 getNormalizedTextWhiteSpacePre("pre");
543 }
544
545
546
547
548
549 @Test
550 @Alerts(" A B C\t \t D \n"
551 + "EF\n"
552 + "G \n"
553 + " H I ")
554 public void getNormalizedTextWhiteSpacePrePreWrap() throws Exception {
555 getNormalizedTextWhiteSpacePre("pre-wrap");
556 }
557
558
559
560
561
562 @Test
563 @Alerts(" A B C\t \t D \n"
564 + "EF\n"
565 + "G \n"
566 + " H I ")
567 public void getNormalizedTextWhiteSpacePrePreLine() throws Exception {
568 getNormalizedTextWhiteSpacePre("pre-line");
569 }
570
571 private void getNormalizedTextWhiteSpacePre(final String whiteSpace) throws Exception {
572 final String htmlContent = DOCTYPE_HTML
573 + "<html>\n"
574 + "<head></head>\n"
575 + "<body>\n"
576 + " <pre id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">"
577 + " A B C\t \t D \nEF\nG \n H <br> I </pre>\n"
578 + "</body></html>";
579
580 final HtmlPage page = loadPage(htmlContent);
581
582 final String text = page.getElementById("tester").asNormalizedText();
583 assertEquals(getExpectedAlerts()[0], text);
584 }
585
586
587
588
589
590 @Test
591 @Alerts(" A B C D \n"
592 + "EF\n"
593 + "G \n"
594 + " H <br> I")
595 public void getNormalizedTextWhiteSpaceTextArea() throws Exception {
596 getNormalizedTextWhiteSpaceTextArea(null);
597 }
598
599
600
601
602
603 @Test
604 @Alerts(" A B C D \n"
605 + "EF\n"
606 + "G \n"
607 + " H <br> I")
608 public void getNormalizedTextWhiteSpaceTextAreaNormal() throws Exception {
609 getNormalizedTextWhiteSpaceTextArea("normal");
610 }
611
612
613
614
615
616 @Test
617 @Alerts(" A B C D \n"
618 + "EF\n"
619 + "G \n"
620 + " H <br> I")
621 public void getNormalizedTextWhiteSpaceTextAreaNowrap() throws Exception {
622 getNormalizedTextWhiteSpaceTextArea("nowrap");
623 }
624
625
626
627
628
629 @Test
630 @Alerts(" A B C D \n"
631 + "EF\n"
632 + "G \n"
633 + " H <br> I")
634 public void getNormalizedTextWhiteSpaceTextAreaPre() throws Exception {
635 getNormalizedTextWhiteSpaceTextArea("pre");
636 }
637
638
639
640
641
642 @Test
643 @Alerts(" A B C D \n"
644 + "EF\n"
645 + "G \n"
646 + " H <br> I")
647 public void getNormalizedTextWhiteSpaceTextAreaPreWrap() throws Exception {
648 getNormalizedTextWhiteSpaceTextArea("pre-wrap");
649 }
650
651
652
653
654
655 @Test
656 @Alerts(" A B C D \n"
657 + "EF\n"
658 + "G \n"
659 + " H <br> I")
660 public void getNormalizedTextWhiteSpaceTextAreaPreLine() throws Exception {
661 getNormalizedTextWhiteSpaceTextArea("pre-line");
662 }
663
664 private void getNormalizedTextWhiteSpaceTextArea(final String whiteSpace) throws Exception {
665 final String htmlContent = DOCTYPE_HTML
666 + "<html>\n"
667 + "<head></head>\n"
668 + "<body>\n"
669 + " <textarea id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">"
670 + " A B C\t \t D \nEF\nG \n H <br> I </textarea>\n"
671 + "</body></html>";
672
673 final HtmlPage page = loadPage(htmlContent);
674
675 final String text = page.getElementById("tester").asNormalizedText();
676 assertEquals(getExpectedAlerts()[0], text);
677 }
678
679
680
681
682
683 @Test
684 @Alerts("A B C D EF G H <br> I")
685 public void getNormalizedTextWhiteSpaceTitle() throws Exception {
686 getNormalizedTextWhiteSpaceTitle(null);
687 }
688
689
690
691
692
693 @Test
694 @Alerts("A B C D EF G H <br> I")
695 public void getNormalizedTextWhiteSpaceTitleNormal() throws Exception {
696 getNormalizedTextWhiteSpaceTitle("normal");
697 }
698
699
700
701
702
703 @Test
704 @Alerts("A B C D EF G H <br> I")
705 public void getNormalizedTextWhiteSpaceTitleNowrap() throws Exception {
706 getNormalizedTextWhiteSpaceTitle("nowrap");
707 }
708
709
710
711
712
713 @Test
714 @Alerts("A B C D EF G H <br> I")
715 public void getNormalizedTextWhiteSpaceTitlePre() throws Exception {
716 getNormalizedTextWhiteSpaceTitle("pre");
717 }
718
719
720
721
722
723 @Test
724 @Alerts("A B C D EF G H <br> I")
725 public void getNormalizedTextWhiteSpaceTitlePreWrap() throws Exception {
726 getNormalizedTextWhiteSpaceTitle("pre-wrap");
727 }
728
729
730
731
732
733 @Test
734 @Alerts("A B C D EF G H <br> I")
735 public void getNormalizedTextWhiteSpaceTitlePreLine() throws Exception {
736 getNormalizedTextWhiteSpaceTitle("pre-line");
737 }
738
739 private void getNormalizedTextWhiteSpaceTitle(final String whiteSpace) throws Exception {
740 final String htmlContent = DOCTYPE_HTML
741 + "<html>\n"
742 + "<head>\n"
743 + "<title id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">"
744 + " A B C\t \t D \nEF\nG \n H <br> I </title>\n"
745 + "</head>\n"
746 + "<body>\n"
747 + "</body></html>";
748
749 final HtmlPage page = loadPage(htmlContent);
750
751 final String text = page.getElementById("tester").asNormalizedText();
752 assertEquals(getExpectedAlerts()[0], text);
753 }
754
755
756
757
758
759 @Test
760 @Alerts("A B C D EF G H"
761 + " I")
762 public void getNormalizedTextWhiteSpaceSelect() throws Exception {
763 getNormalizedTextWhiteSpaceSelect(null);
764 }
765
766
767
768
769
770 @Test
771 @Alerts("A B C D EF G H"
772 + " I")
773 public void getNormalizedTextWhiteSpaceSelectNormal() throws Exception {
774 getNormalizedTextWhiteSpaceSelect("normal");
775 }
776
777
778
779
780
781 @Test
782 @Alerts("A B C D EF G H"
783 + " I")
784 public void getNormalizedTextWhiteSpaceSelectNowrap() throws Exception {
785 getNormalizedTextWhiteSpaceSelect("nowrap");
786 }
787
788
789
790
791
792 @Test
793 @Alerts("A B C D EF G H"
794 + " I")
795 public void getNormalizedTextWhiteSpaceSelectPre() throws Exception {
796 getNormalizedTextWhiteSpaceSelect("pre");
797 }
798
799
800
801
802
803 @Test
804 @Alerts("A B C D EF G H"
805 + " I")
806 public void getNormalizedTextWhiteSpaceSelectPreWrap() throws Exception {
807 getNormalizedTextWhiteSpaceSelect("pre-wrap");
808 }
809
810
811
812
813
814 @Test
815 @Alerts("A B C D EF G H"
816 + " I")
817 public void getNormalizedTextWhiteSpaceSelectPreLine() throws Exception {
818 getNormalizedTextWhiteSpaceSelect("pre-line");
819 }
820
821 private void getNormalizedTextWhiteSpaceSelect(final String whiteSpace) throws Exception {
822 final String htmlContent = DOCTYPE_HTML
823 + "<html>\n"
824 + "<head></head>\n"
825 + "<body>\n"
826 + " <form>\n"
827 + " <select id='tester' "
828 + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">\n"
829 + " <option> A B C\t \t D \nEF\nG \n H <br> I </option>\n"
830 + " <option>Second</option>\n"
831 + " </select>\n"
832 + "</body></html>";
833
834 final HtmlPage page = loadPage(htmlContent);
835
836 final String text = page.getElementById("tester").asNormalizedText();
837 assertEquals(getExpectedAlerts()[0], text);
838 }
839
840
841
842
843
844 @Test
845 @Alerts("A B C D EF G H <br> I")
846 public void getNormalizedTextWhiteSpaceInputSubmit() throws Exception {
847 getNormalizedTextWhiteSpaceInputSubmit(null);
848 }
849
850
851
852
853
854 @Test
855 @Alerts("A B C D EF G H <br> I")
856 public void getNormalizedTextWhiteSpaceInputSubmitNormal() throws Exception {
857 getNormalizedTextWhiteSpaceInputSubmit("normal");
858 }
859
860
861
862
863
864 @Test
865 @Alerts("A B C D EF G H <br> I")
866 public void getNormalizedTextWhiteSpaceInputSubmitNowrap() throws Exception {
867 getNormalizedTextWhiteSpaceInputSubmit("nowrap");
868 }
869
870
871
872
873
874 @Test
875 @Alerts("A B C D EF G H <br> I")
876 public void getNormalizedTextWhiteSpaceInputSubmitPre() throws Exception {
877 getNormalizedTextWhiteSpaceInputSubmit("pre");
878 }
879
880
881
882
883
884 @Test
885 @Alerts("A B C D EF G H <br> I")
886 public void getNormalizedTextWhiteSpaceInputSubmitPreWrap() throws Exception {
887 getNormalizedTextWhiteSpaceInputSubmit("pre-wrap");
888 }
889
890
891
892
893
894 @Test
895 @Alerts("A B C D EF G H <br> I")
896 public void getNormalizedTextWhiteSpaceInputSubmitPreLine() throws Exception {
897 getNormalizedTextWhiteSpaceInputSubmit("pre-line");
898 }
899
900 private void getNormalizedTextWhiteSpaceInputSubmit(final String whiteSpace) throws Exception {
901 final String htmlContent = DOCTYPE_HTML
902 + "<html>\n"
903 + "<head></head>\n"
904 + "<body>\n"
905 + "<form id='form1'>\n"
906 + " <input type='submit' name='tester' id='tester' "
907 + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'"))
908 + " value=' A B C\t \t D \nEF\nG \n H <br> I '>\n"
909 + "</form>\n"
910 + "</body></html>";
911
912 final HtmlPage page = loadPage(htmlContent);
913
914 final String text = page.getElementById("tester").asNormalizedText();
915 assertEquals(getExpectedAlerts()[0], text);
916 }
917
918
919
920
921
922 @Test
923 @Alerts("Submit Query")
924 public void getNormalizedTextInputSubmitNoValue() throws Exception {
925 final String htmlContent = DOCTYPE_HTML
926 + "<html>\n"
927 + "<head></head>\n"
928 + "<body>\n"
929 + "<form id='form1'>\n"
930 + " <input type='submit' name='tester' id='tester'>\n"
931 + "</form>\n"
932 + "</body></html>";
933
934 final HtmlPage page = loadPage(htmlContent);
935
936 final String text = page.getElementById("tester").asNormalizedText();
937 assertEquals(getExpectedAlerts()[0], text);
938 }
939
940
941
942
943
944 @Test
945 @Alerts("")
946 public void getNormalizedTextInputSubmitBlankValue() throws Exception {
947 final String htmlContent = DOCTYPE_HTML
948 + "<html>\n"
949 + "<head></head>\n"
950 + "<body>\n"
951 + "<form id='form1'>\n"
952 + " <input type='submit' name='tester' id='tester' value=' \t' >\n"
953 + "</form>\n"
954 + "</body></html>";
955
956 final HtmlPage page = loadPage(htmlContent);
957
958 final String text = page.getElementById("tester").asNormalizedText();
959 assertEquals(getExpectedAlerts()[0], text);
960 }
961
962
963
964
965
966 @Test
967 @Alerts("A B C D EF G H <br> I")
968 public void getNormalizedTextWhiteSpaceInputReset() throws Exception {
969 getNormalizedTextWhiteSpaceInputReset(null);
970 }
971
972
973
974
975
976 @Test
977 @Alerts("A B C D EF G H <br> I")
978 public void getNormalizedTextWhiteSpaceInputResetNormal() throws Exception {
979 getNormalizedTextWhiteSpaceInputReset("normal");
980 }
981
982
983
984
985
986 @Test
987 @Alerts("A B C D EF G H <br> I")
988 public void getNormalizedTextWhiteSpaceInputResetNowrap() throws Exception {
989 getNormalizedTextWhiteSpaceInputReset("nowrap");
990 }
991
992
993
994
995
996 @Test
997 @Alerts("A B C D EF G H <br> I")
998 public void getNormalizedTextWhiteSpaceInputResetPre() throws Exception {
999 getNormalizedTextWhiteSpaceInputReset("pre");
1000 }
1001
1002
1003
1004
1005
1006 @Test
1007 @Alerts("A B C D EF G H <br> I")
1008 public void getNormalizedTextWhiteSpaceInputResetPreWrap() throws Exception {
1009 getNormalizedTextWhiteSpaceInputReset("pre-wrap");
1010 }
1011
1012
1013
1014
1015
1016 @Test
1017 @Alerts("A B C D EF G H <br> I")
1018 public void getNormalizedTextWhiteSpaceInputResetPreLine() throws Exception {
1019 getNormalizedTextWhiteSpaceInputReset("pre-line");
1020 }
1021
1022 private void getNormalizedTextWhiteSpaceInputReset(final String whiteSpace) throws Exception {
1023 final String htmlContent = DOCTYPE_HTML
1024 + "<html>\n"
1025 + "<head></head>\n"
1026 + "<body>\n"
1027 + "<form id='form1'>\n"
1028 + " <input type='reset' name='tester' id='tester' "
1029 + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'"))
1030 + " value=' A B C\t \t D \nEF\nG \n H <br> I '>\n"
1031 + "</form>\n"
1032 + "</body></html>";
1033
1034 final HtmlPage page = loadPage(htmlContent);
1035
1036 final String text = page.getElementById("tester").asNormalizedText();
1037 assertEquals(getExpectedAlerts()[0], text);
1038 }
1039
1040
1041
1042
1043
1044 @Test
1045 @Alerts("Reset")
1046 public void getNormalizedTextInputResetNoValue() throws Exception {
1047 final String htmlContent = DOCTYPE_HTML
1048 + "<html>\n"
1049 + "<head></head>\n"
1050 + "<body>\n"
1051 + "<form id='form1'>\n"
1052 + " <input type='reset' name='tester' id='tester' >\n"
1053 + "</form>\n"
1054 + "</body></html>";
1055
1056 final HtmlPage page = loadPage(htmlContent);
1057
1058 final String text = page.getElementById("tester").asNormalizedText();
1059 assertEquals(getExpectedAlerts()[0], text);
1060 }
1061
1062
1063
1064
1065
1066
1067 @Test
1068 @Alerts("")
1069 public void getNormalizedTextInputResetBlankValue() throws Exception {
1070 final String htmlContent = DOCTYPE_HTML
1071 + "<html>\n"
1072 + "<head></head>\n"
1073 + "<body>\n"
1074 + "<form id='form1'>\n"
1075 + " <input type='reset' name='tester' id='tester' value=' \t'>\n"
1076 + "</form>\n"
1077 + "</body></html>";
1078
1079 final HtmlPage page = loadPage(htmlContent);
1080
1081 final String text = page.getElementById("tester").asNormalizedText();
1082 assertEquals(getExpectedAlerts()[0], text);
1083 }
1084
1085
1086
1087
1088
1089 @Test
1090 @Alerts("unchecked")
1091 public void getNormalizedTextWhiteSpaceInputCheckbox() throws Exception {
1092 getNormalizedTextWhiteSpaceInputCheckbox(null);
1093 }
1094
1095
1096
1097
1098
1099 @Test
1100 @Alerts("unchecked")
1101 public void getNormalizedTextWhiteSpaceInputCheckboxNormal() throws Exception {
1102 getNormalizedTextWhiteSpaceInputCheckbox("normal");
1103 }
1104
1105
1106
1107
1108
1109 @Test
1110 @Alerts("unchecked")
1111 public void getNormalizedTextWhiteSpaceInputCheckboxNowrap() throws Exception {
1112 getNormalizedTextWhiteSpaceInputCheckbox("nowrap");
1113 }
1114
1115
1116
1117
1118
1119 @Test
1120 @Alerts("unchecked")
1121 public void getNormalizedTextWhiteSpaceInputCheckboxPre() throws Exception {
1122 getNormalizedTextWhiteSpaceInputCheckbox("pre");
1123 }
1124
1125
1126
1127
1128
1129 @Test
1130 @Alerts("unchecked")
1131 public void getNormalizedTextWhiteSpaceInputCheckboxPreWrap() throws Exception {
1132 getNormalizedTextWhiteSpaceInputCheckbox("pre-wrap");
1133 }
1134
1135
1136
1137
1138
1139 @Test
1140 @Alerts("unchecked")
1141 public void getNormalizedTextWhiteSpaceInputCheckboxPreLine() throws Exception {
1142 getNormalizedTextWhiteSpaceInputCheckbox("pre-line");
1143 }
1144
1145 private void getNormalizedTextWhiteSpaceInputCheckbox(final String whiteSpace) throws Exception {
1146 final String htmlContent = DOCTYPE_HTML
1147 + "<html>\n"
1148 + "<head></head>\n"
1149 + "<body>\n"
1150 + "<form id='form1'>\n"
1151 + " <input type='checkbox' name='tester' id='tester' "
1152 + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'"))
1153 + " value=' A B C\t \t D \nEF\nG \n H <br> I '>\n"
1154 + "</form>\n"
1155 + "</body></html>";
1156
1157 final HtmlPage page = loadPage(htmlContent);
1158
1159 final String text = page.getElementById("tester").asNormalizedText();
1160 assertEquals(getExpectedAlerts()[0], text);
1161 }
1162
1163
1164
1165
1166
1167 @Test
1168 @Alerts("unchecked")
1169 public void getNormalizedTextWhiteSpaceInputRadio() throws Exception {
1170 getNormalizedTextWhiteSpaceInputRadio(null);
1171 }
1172
1173
1174
1175
1176
1177 @Test
1178 @Alerts("unchecked")
1179 public void getNormalizedTextWhiteSpaceInputRadioNormal() throws Exception {
1180 getNormalizedTextWhiteSpaceInputRadio("normal");
1181 }
1182
1183
1184
1185
1186
1187 @Test
1188 @Alerts("unchecked")
1189 public void getNormalizedTextWhiteSpaceInputRadioNowrap() throws Exception {
1190 getNormalizedTextWhiteSpaceInputRadio("nowrap");
1191 }
1192
1193
1194
1195
1196
1197 @Test
1198 @Alerts("unchecked")
1199 public void getNormalizedTextWhiteSpaceInputRadioPre() throws Exception {
1200 getNormalizedTextWhiteSpaceInputRadio("pre");
1201 }
1202
1203
1204
1205
1206
1207 @Test
1208 @Alerts("unchecked")
1209 public void getNormalizedTextWhiteSpaceInputRadioPreWrap() throws Exception {
1210 getNormalizedTextWhiteSpaceInputRadio("pre-wrap");
1211 }
1212
1213
1214
1215
1216
1217 @Test
1218 @Alerts("unchecked")
1219 public void getNormalizedTextWhiteSpaceInputRadioPreLine() throws Exception {
1220 getNormalizedTextWhiteSpaceInputRadio("pre-line");
1221 }
1222
1223 private void getNormalizedTextWhiteSpaceInputRadio(final String whiteSpace) throws Exception {
1224 final String htmlContent = DOCTYPE_HTML
1225 + "<html>\n"
1226 + "<head></head>\n"
1227 + "<body>\n"
1228 + "<form id='form1'>\n"
1229 + " <input type='radio' name='tester' id='tester' "
1230 + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'"))
1231 + " value=' A B C\t \t D \nEF\nG \n H <br> I '>\n"
1232 + "</form>\n"
1233 + "</body></html>";
1234
1235 final HtmlPage page = loadPage(htmlContent);
1236
1237 final String text = page.getElementById("tester").asNormalizedText();
1238 assertEquals(getExpectedAlerts()[0], text);
1239 }
1240
1241
1242
1243
1244
1245 @Test
1246 @Alerts("1. first item\n"
1247 + "2. A B C D EF G H \n"
1248 + " I\n"
1249 + "3. third item\n"
1250 + "4. 4. item\n"
1251 + "some text\n"
1252 + "5. last item")
1253 public void getNormalizedTextWhiteSpaceOrderedList() throws Exception {
1254 getNormalizedTextWhiteSpaceOrderedList(null);
1255 }
1256
1257
1258
1259
1260
1261 @Test
1262 @Alerts("1. first item\n"
1263 + "2. A B C D EF G H \n"
1264 + " I\n"
1265 + "3. third item\n"
1266 + "4. 4. item\n"
1267 + "some text\n"
1268 + "5. last item")
1269 public void getNormalizedTextWhiteSpaceOrderedListNormal() throws Exception {
1270 getNormalizedTextWhiteSpaceOrderedList("normal");
1271 }
1272
1273
1274
1275
1276
1277 @Test
1278 @Alerts("1. first item\n"
1279 + "2. A B C D EF G H \n"
1280 + " I\n"
1281 + "3. third item\n"
1282 + "4. 4. item\n"
1283 + "some text\n"
1284 + "5. last item")
1285 public void getNormalizedTextWhiteSpaceOrderedListNowrap() throws Exception {
1286 getNormalizedTextWhiteSpaceOrderedList("nowrap");
1287 }
1288
1289
1290
1291
1292
1293 @Test
1294 @Alerts("1. first item\n"
1295 + "2. A B C D EF G H \n"
1296 + " I\n"
1297 + "3. third item\n"
1298 + "4. 4. item\n"
1299 + "some text\n"
1300 + "5. last item")
1301 public void getNormalizedTextWhiteSpaceOrderedListPre() throws Exception {
1302 getNormalizedTextWhiteSpaceOrderedList("pre");
1303 }
1304
1305
1306
1307
1308
1309 @Test
1310 @Alerts("1. first item\n"
1311 + "2. A B C D EF G H \n"
1312 + " I\n"
1313 + "3. third item\n"
1314 + "4. 4. item\n"
1315 + "some text\n"
1316 + "5. last item")
1317 public void getNormalizedTextWhiteSpaceOrderedListPreWrap() throws Exception {
1318 getNormalizedTextWhiteSpaceOrderedList("pre-wrap");
1319 }
1320
1321
1322
1323
1324
1325 @Test
1326 @Alerts("1. first item\n"
1327 + "2. A B C D EF G H \n"
1328 + " I\n"
1329 + "3. third item\n"
1330 + "4. 4. item\n"
1331 + "some text\n"
1332 + "5. last item")
1333 public void getNormalizedTextWhiteSpaceOrderedListPreLine() throws Exception {
1334 getNormalizedTextWhiteSpaceOrderedList("pre-line");
1335 }
1336
1337 private void getNormalizedTextWhiteSpaceOrderedList(final String whiteSpace) throws Exception {
1338 final String htmlContent = DOCTYPE_HTML
1339 + "<html>\n"
1340 + "<head></head>\n"
1341 + "<body>\n"
1342 + " <ol id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">\n"
1343 + " <li>first item</li>\n"
1344 + " <li> A B C\t \t D \nEF\nG \n H <br> I </li>\n"
1345 + " <li>third item</li><li>4. item</li>\n"
1346 + " some text \n"
1347 + " <li>last item</li>\n"
1348 + " </ol>\n"
1349 + "</body></html>";
1350
1351 final HtmlPage page = loadPage(htmlContent);
1352
1353 final String text = page.getElementById("tester").asNormalizedText();
1354 assertEquals(getExpectedAlerts()[0], text);
1355 }
1356
1357
1358
1359
1360
1361 @Test
1362 @Alerts("first item\n"
1363 + "A B C D EF G H \n"
1364 + " I\n"
1365 + "third item\n"
1366 + "4. item\n"
1367 + "some text\n"
1368 + "last item")
1369 public void getNormalizedTextWhiteSpaceUnorderedList() throws Exception {
1370 getNormalizedTextWhiteSpaceUnorderedList(null);
1371 }
1372
1373
1374
1375
1376
1377 @Test
1378 @Alerts("first item\n"
1379 + "A B C D EF G H \n"
1380 + " I\n"
1381 + "third item\n"
1382 + "4. item\n"
1383 + "some text\n"
1384 + "last item")
1385 public void getNormalizedTextWhiteSpaceUnorderedListNormal() throws Exception {
1386 getNormalizedTextWhiteSpaceUnorderedList("normal");
1387 }
1388
1389
1390
1391
1392
1393 @Test
1394 @Alerts("first item\n"
1395 + "A B C D EF G H \n"
1396 + " I\n"
1397 + "third item\n"
1398 + "4. item\n"
1399 + "some text\n"
1400 + "last item")
1401 public void getNormalizedTextWhiteSpaceUnorderedListNowrap() throws Exception {
1402 getNormalizedTextWhiteSpaceUnorderedList("nowrap");
1403 }
1404
1405
1406
1407
1408
1409 @Test
1410 @Alerts("first item\n"
1411 + "A B C D EF G H \n"
1412 + " I\n"
1413 + "third item\n"
1414 + "4. item\n"
1415 + "some text\n"
1416 + "last item")
1417 public void getNormalizedTextWhiteSpaceUnorderedListPre() throws Exception {
1418 getNormalizedTextWhiteSpaceUnorderedList("pre");
1419 }
1420
1421
1422
1423
1424
1425 @Test
1426 @Alerts("first item\n"
1427 + "A B C D EF G H \n"
1428 + " I\n"
1429 + "third item\n"
1430 + "4. item\n"
1431 + "some text\n"
1432 + "last item")
1433 public void getNormalizedTextWhiteSpaceUnorderedListPreWrap() throws Exception {
1434 getNormalizedTextWhiteSpaceUnorderedList("pre-wrap");
1435 }
1436
1437
1438
1439
1440
1441 @Test
1442 @Alerts("first item\n"
1443 + "A B C D EF G H \n"
1444 + " I\n"
1445 + "third item\n"
1446 + "4. item\n"
1447 + "some text\n"
1448 + "last item")
1449 public void getNormalizedTextWhiteSpaceUnorderedListPreLine() throws Exception {
1450 getNormalizedTextWhiteSpaceUnorderedList("pre-line");
1451 }
1452
1453 private void getNormalizedTextWhiteSpaceUnorderedList(final String whiteSpace) throws Exception {
1454 final String htmlContent = DOCTYPE_HTML
1455 + "<html>\n"
1456 + "<head></head>\n"
1457 + "<body>\n"
1458 + " <ul id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">\n"
1459 + " <li>first item</li>\n"
1460 + " <li> A B C\t \t D \nEF\nG \n H <br> I </li>\n"
1461 + " <li>third item</li><li>4. item</li>\n"
1462 + " some text \n"
1463 + " <li>last item</li>\n"
1464 + " </ul>\n"
1465 + "</body></html>";
1466
1467 final HtmlPage page = loadPage(htmlContent);
1468
1469 final String text = page.getElementById("tester").asNormalizedText();
1470 assertEquals(getExpectedAlerts()[0], text);
1471 }
1472
1473
1474
1475
1476
1477 @Test
1478 @Alerts("The text to be tested")
1479 public void getNormalizedTextLabel() throws Exception {
1480 getNormalizedTextFormated("<label id='tester'>The text to be <span>tested</span></label>");
1481 }
1482
1483
1484
1485
1486
1487 @Test
1488 @Alerts("The text to be tested")
1489 public void getNormalizedTextLabelNormal() throws Exception {
1490 getNormalizedTextFormated("<label id='tester' style='white-space: normal'>"
1491 + "The text to be <span>tested</span></label>");
1492 }
1493
1494
1495
1496
1497
1498 @Test
1499 @Alerts("The text to be tested")
1500 public void getNormalizedTextLabelNowrap() throws Exception {
1501 getNormalizedTextFormated("<label id='tester' style='white-space: nowrap'>"
1502 + "The text to be <span>tested</span></label>");
1503 }
1504
1505
1506
1507
1508
1509 @Test
1510 @Alerts("The text to be tested")
1511 public void getNormalizedTextLabelPre() throws Exception {
1512 getNormalizedTextFormated("<label id='tester' style='white-space: pre'>"
1513 + "The text to be <span>tested</span></label>");
1514 }
1515
1516
1517
1518
1519
1520 @Test
1521 @Alerts("The text to be tested")
1522 public void getNormalizedTextLabelPreWrap() throws Exception {
1523 getNormalizedTextFormated("<label id='tester' style='white-space: pre-wrap'>"
1524 + "The text to be <span>tested</span></label>");
1525 }
1526
1527
1528
1529
1530
1531 @Test
1532 @Alerts("The text to be tested")
1533 public void getNormalizedTextLabelPreLine() throws Exception {
1534 getNormalizedTextFormated("<label id='tester' style='white-space: pre-line'>"
1535 + "The text to be <span>tested</span></label>");
1536 }
1537
1538
1539
1540
1541
1542 @Test
1543 @Alerts("A nbsp and spaces")
1544 public void getNormalizedTextParagraphNbsp() throws Exception {
1545 getNormalizedTextFormated("<p id='tester'>A nbsp and spaces</p>");
1546 }
1547
1548
1549
1550
1551
1552 @Test
1553 @Alerts("A nbsp and spaces")
1554 public void getNormalizedTextParagraphNbspNormal() throws Exception {
1555 getNormalizedTextFormated("<p id='tester' style='white-space: normal'>"
1556 + "A nbsp and spaces</p>");
1557 }
1558
1559
1560
1561
1562
1563 @Test
1564 @Alerts("A nbsp and spaces")
1565 public void getNormalizedTextParagraphNbspNowrap() throws Exception {
1566 getNormalizedTextFormated("<p id='tester' style='white-space: nowrap'>"
1567 + "A nbsp and spaces</p>");
1568 }
1569
1570
1571
1572
1573
1574 @Test
1575 @Alerts("A nbsp and spaces")
1576 public void getNormalizedTextParagraphNbspPre() throws Exception {
1577 getNormalizedTextFormated("<p id='tester' style='white-space: pre'>"
1578 + "A nbsp and spaces</p>");
1579 }
1580
1581
1582
1583
1584
1585 @Test
1586 @Alerts("A nbsp and spaces")
1587 public void getNormalizedTextParagraphNbspPreWrap() throws Exception {
1588 getNormalizedTextFormated("<p id='tester' style='white-space: pre-wrap'>"
1589 + "A nbsp and spaces</p>");
1590 }
1591
1592
1593
1594
1595
1596 @Test
1597 @Alerts("A nbsp and spaces")
1598 public void getNormalizedTextParagraphNbspPreLine() throws Exception {
1599 getNormalizedTextFormated("<p id='tester' style='white-space: pre-line'>"
1600 + "A nbsp and spaces</p>");
1601 }
1602
1603
1604
1605
1606
1607 @Test
1608 @Alerts("A \n"
1609 + " NBSPs ")
1610 public void getNormalizedTextParagraphMultilineNbsp() throws Exception {
1611 getNormalizedTextFormated("<p id='tester'>A  <br />  NBSPs </p>");
1612 }
1613
1614
1615
1616
1617
1618 @Test
1619 @Alerts("A \n"
1620 + " NBSPs ")
1621 public void getNormalizedTextParagraphMultilineNbspNormal() throws Exception {
1622 getNormalizedTextFormated("<p id='tester' style='white-space: normal'>"
1623 + "A  <br />  NBSPs </p>");
1624 }
1625
1626
1627
1628
1629
1630 @Test
1631 @Alerts("A \n"
1632 + " NBSPs ")
1633 public void getNormalizedTextParagraphMultilineNbspNowrap() throws Exception {
1634 getNormalizedTextFormated("<p id='tester' style='white-space: nowrap'>"
1635 + "A  <br />  NBSPs </p>");
1636 }
1637
1638
1639
1640
1641
1642 @Test
1643 @Alerts("A \n"
1644 + " NBSPs ")
1645 public void getNormalizedTextParagraphMultilineNbspPre() throws Exception {
1646 getNormalizedTextFormated("<p id='tester' style='white-space: pre'>"
1647 + "A  <br />  NBSPs </p>");
1648 }
1649
1650
1651
1652
1653
1654 @Test
1655 @Alerts("A \n"
1656 + " NBSPs ")
1657 public void getNormalizedTextParagraphMultilineNbspPreWrap() throws Exception {
1658 getNormalizedTextFormated("<p id='tester' style='white-space: pre-wrap'>"
1659 + "A  <br />  NBSPs </p>");
1660 }
1661
1662
1663
1664
1665
1666 @Test
1667 @Alerts("A \n"
1668 + " NBSPs ")
1669 public void getNormalizedTextParagraphMultilineNbspPreLine() throws Exception {
1670 getNormalizedTextFormated("<p id='tester' style='white-space: pre-line'>"
1671 + "A  <br />  NBSPs </p>");
1672 }
1673
1674
1675
1676
1677
1678
1679 @Test
1680 @Alerts("I have 2 out of 2 stamps")
1681 public void getNormalizedTextInputInsideP() throws Exception {
1682 getNormalizedTextFormated("<p id='tester'>"
1683 + " I have <input type='number' value='2'/> out of 2 stamps</p>");
1684 }
1685
1686
1687
1688
1689
1690 @Test
1691 @Alerts("Sum")
1692 public void getNormalizedTextDetails() throws Exception {
1693 getNormalizedTextFormated("<details id='tester'>"
1694 + "<summary>Sum</summary>"
1695 + "<p>detail</p>"
1696 + "</details>");
1697 }
1698
1699
1700
1701
1702 @Test
1703 @Alerts("Sum\nSum2")
1704 public void getNormalizedTextDetailsTwoSums() throws Exception {
1705 getNormalizedTextFormated("<details id='tester'>"
1706 + "<summary>Sum</summary>"
1707 + "<summary>Sum2</summary>"
1708 + "<p>detail</p>"
1709 + "</details>");
1710 }
1711
1712
1713
1714
1715 @Test
1716 @Alerts("Sum\ndetail")
1717 public void getNormalizedTextDetailsOpen() throws Exception {
1718 getNormalizedTextFormated("<details id='tester' open=true>"
1719 + "<summary>Sum</summary>"
1720 + "<p>detail</p>"
1721 + "</details>");
1722 }
1723
1724 private void getNormalizedTextFormated(final String htmlTesterSnipped) throws Exception {
1725 final String htmlContent = DOCTYPE_HTML
1726 + "<html>\n"
1727 + "<head></head>\n"
1728 + "<body>\n"
1729 + " " + htmlTesterSnipped + "\n"
1730 + "</body></html>";
1731
1732 final HtmlPage page = loadPage(htmlContent);
1733
1734 final String text = page.getBody().asNormalizedText();
1735 assertEquals(getExpectedAlerts()[0], text);
1736 }
1737
1738
1739
1740
1741 @Test
1742 @Alerts("01 Jan 2021")
1743 public void asTextInsideSpan() throws Exception {
1744 final String html = DOCTYPE_HTML
1745 + "<html><body><form>\n"
1746 + "<span id='test'>\n"
1747 + " <select name='day' size='1'>"
1748 + "<option value='1' selected>01</option>"
1749 + "<option value='2'>02</option></select>\n"
1750 + " <select name='month' size='1'>"
1751 + "<option value='1' selected>Jan</option>"
1752 + "<option value='2'>Feb</option></select>\n"
1753 + " <select name='year' size='1'>"
1754 + "<option value='1'>2022</option>"
1755 + "<option value='2' selected>2021</option></select>\n"
1756 + "</span>"
1757 + "</form></body></html>";
1758 final HtmlPage page = loadPage(html);
1759 final DomElement elem = page.getElementById("test");
1760 assertEquals(getExpectedAlerts()[0], elem.asNormalizedText());
1761 }
1762
1763
1764
1765
1766
1767 @Test
1768 public void getCellAt() throws Exception {
1769 final String htmlContent = DOCTYPE_HTML
1770 + "<html>"
1771 + "<body>\n"
1772 + "<table id='table1' summary='Test table'>\n"
1773 + "<tr>"
1774 + "<td><a>cell1a</a><div><span>cell1b</span></div></td>"
1775 + "<td>cell2</td><td rowspan='2'>cell4</td>"
1776 + "</tr>\n"
1777 + "<tr>"
1778 + "<td colspan='2'>cell3</td>"
1779 + "</tr>\n"
1780 + "</table>\n"
1781 + "</body></html>";
1782 final HtmlPage page = loadPage(htmlContent);
1783
1784 final HtmlTable table = page.getHtmlElementById("table1");
1785
1786 final HtmlTableCell cell1 = table.getCellAt(0, 0);
1787
1788 assertEquals("cell1 contents", "cell1a\ncell1b", cell1.asNormalizedText());
1789
1790 final HtmlTableCell cell2 = table.getCellAt(0, 1);
1791 assertEquals("cell2 contents", "cell2", cell2.asNormalizedText());
1792
1793 final HtmlTableCell cell3 = table.getCellAt(1, 0);
1794 assertEquals("cell3 contents", "cell3", cell3.asNormalizedText());
1795 assertSame("cells (1,0) and (1,1)", cell3, table.getCellAt(1, 1));
1796
1797 final HtmlTableCell cell4 = table.getCellAt(0, 2);
1798 assertEquals("cell4 contents", "cell4", cell4.asNormalizedText());
1799 assertSame("cells (0,2) and (1,2)", cell4, table.getCellAt(1, 2));
1800 }
1801
1802
1803
1804
1805
1806 @Test
1807 public void getCellAtWithBreaks() throws Exception {
1808 final String htmlContent = DOCTYPE_HTML
1809 + "<html>"
1810 + "<body>\n"
1811 + "<table id='table1' summary='Test table'>\n"
1812 + "<tr>"
1813 + "<td><a>cell1a</a><div><br><span>cell1b</span></div></td>"
1814 + "<td>cell2</td><td rowspan='2'>cell4</td>"
1815 + "</tr>\n"
1816 + "<tr>"
1817 + "<td colspan='2'>cell3</td>"
1818 + "</tr>\n"
1819 + "</table>\n"
1820 + "</body></html>";
1821 final HtmlPage page = loadPage(htmlContent);
1822
1823 final HtmlTable table = page.getHtmlElementById("table1");
1824
1825 final HtmlTableCell cell1 = table.getCellAt(0, 0);
1826
1827 assertEquals("cell1 contents", "cell1a\n\ncell1b", cell1.asNormalizedText());
1828
1829 final HtmlTableCell cell2 = table.getCellAt(0, 1);
1830 assertEquals("cell2 contents", "cell2", cell2.asNormalizedText());
1831
1832 final HtmlTableCell cell3 = table.getCellAt(1, 0);
1833 assertEquals("cell3 contents", "cell3", cell3.asNormalizedText());
1834 assertSame("cells (1,0) and (1,1)", cell3, table.getCellAt(1, 1));
1835
1836 final HtmlTableCell cell4 = table.getCellAt(0, 2);
1837 assertEquals("cell4 contents", "cell4", cell4.asNormalizedText());
1838 assertSame("cells (0,2) and (1,2)", cell4, table.getCellAt(1, 2));
1839 }
1840
1841
1842
1843
1844
1845 @Test
1846 @Alerts("x 12 y")
1847 public void getNormalizedNumberInputValidNumber() throws Exception {
1848 getNormalizedTextFormatedAfterTyping("<p id='tester'>x<input id='inpt' type='number' value=''/>y</p>", "12");
1849 }
1850
1851
1852
1853
1854 @Test
1855 @Alerts(DEFAULT = "x y",
1856 FF = "x ab y",
1857 FF_ESR = "x ab y")
1858 public void getNormalizedNumberInputInvalidNumber() throws Exception {
1859 getNormalizedTextFormatedAfterTyping("<p id='tester'>x<input id='inpt' type='number' value=''/>y</p>", "ab");
1860 }
1861
1862
1863
1864
1865 @Test
1866 @Alerts("x - y")
1867 public void getNormalizedNumberInputMinusOnly() throws Exception {
1868 getNormalizedTextFormatedAfterTyping("<p id='tester'>x<input id='inpt' type='number' value=''/>y</p>", "-");
1869 }
1870
1871
1872
1873
1874 @Test
1875 @Alerts("x + y")
1876 public void getNormalizedNumberInputPlusOnly() throws Exception {
1877 getNormalizedTextFormatedAfterTyping("<p id='tester'>x<input id='inpt' type='number' value=''/>y</p>", "+");
1878 }
1879
1880
1881
1882
1883 @Test
1884 @Alerts("demo")
1885 public void getVisibleEm() throws Exception {
1886 getNormalizedTextFormated("<em id='tester'>demo</em>");
1887 }
1888
1889 private void getNormalizedTextFormatedAfterTyping(final String htmlTesterSnipped,
1890 final String... typed) throws Exception {
1891 final String htmlContent = DOCTYPE_HTML
1892 + "<html>\n"
1893 + "<head></head>\n"
1894 + "<body>\n"
1895 + " " + htmlTesterSnipped + "\n"
1896 + "</body></html>";
1897
1898 final HtmlPage page = loadPage(htmlContent);
1899
1900 final HtmlNumberInput input = page.getHtmlElementById("inpt");
1901 for (final String string : typed) {
1902 input.type(string);
1903 }
1904
1905 final HtmlElement tester = page.getHtmlElementById("tester");
1906 assertEquals(getExpectedAlerts()[0], tester.asNormalizedText());
1907 }
1908 }