1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.html;
16
17 import java.io.InputStream;
18 import java.net.URL;
19 import java.util.Collections;
20
21 import org.apache.commons.io.IOUtils;
22 import org.htmlunit.WebDriverTestCase;
23 import org.htmlunit.junit.annotation.Alerts;
24 import org.htmlunit.junit.annotation.HtmlUnitNYI;
25 import org.htmlunit.util.MimeType;
26 import org.junit.jupiter.api.Test;
27 import org.openqa.selenium.By;
28 import org.openqa.selenium.Keys;
29 import org.openqa.selenium.WebDriver;
30 import org.openqa.selenium.WebElement;
31 import org.openqa.selenium.interactions.Actions;
32
33
34
35
36
37
38
39
40
41
42
43
44 public class HTMLInputElementTest extends WebDriverTestCase {
45
46
47
48
49 @Test
50 @Alerts({"foo", "text", "textfield1", "form1", "cat"})
51 public void standardProperties_Text() throws Exception {
52 final String html = DOCTYPE_HTML
53 + "<html><head><script>\n"
54 + LOG_TITLE_FUNCTION
55 + "function doTest() {\n"
56 + " log(document.form1.textfield1.value);\n"
57 + " log(document.form1.textfield1.type);\n"
58 + " log(document.form1.textfield1.name);\n"
59 + " log(document.form1.textfield1.form.name);\n"
60 + " document.form1.textfield1.value = 'cat';\n"
61 + " log(document.form1.textfield1.value);\n"
62 + "}\n"
63 + "</script></head><body onload='doTest()'>\n"
64 + "<p>hello world</p>\n"
65 + "<form name='form1'>\n"
66 + " <input type='text' name='textfield1' value='foo' />\n"
67 + "</form>\n"
68 + "</body></html>";
69
70 loadPageVerifyTitle2(html);
71 }
72
73
74
75
76 @Alerts(DEFAULT = {"error.fileupload1", "abc", "abc", "abc", "", "abc", "", "", "abc", "abc",
77 "abc", "abc", "abc", "abc", "abc", "abc", "#000000", "", "abc", "", "", "",
78 "", "", "50", "abc", "abc", "abc", "abc"},
79 FF = {"error.fileupload1", "abc", "abc", "abc", "", "abc", "", "", "abc", "abc",
80 "abc", "abc", "abc", "abc", "abc", "abc", "#000000", "", "abc", "", "", "abc",
81 "abc", "", "50", "abc", "abc", "abc", "abc"},
82 FF_ESR = {"error.fileupload1", "abc", "abc", "abc", "", "abc", "", "", "abc", "abc",
83 "abc", "abc", "abc", "abc", "abc", "abc", "#000000", "", "abc", "", "", "abc",
84 "abc", "", "50", "abc", "abc", "abc", "abc"})
85 @Test
86 public void setValueString() throws Exception {
87 testValue("'abc'");
88 }
89
90
91
92
93 @Alerts({"", "", "", "", "", "", "", "", "",
94 "", "", "", "", "", "", "#000000", "", "", "", "", "",
95 "", "", "50", "", "", "", ""})
96 @Test
97 public void setValueEmptyString() throws Exception {
98 testValue("''");
99 }
100
101
102
103
104 @Alerts(CHROME = {"error.fileupload1", ". ", ". ", ". ", "", ". ", "", "", ". ", ". ",
105 ". ", ". ", ". ", ". ", ". ", ". ", "#000000", "", ". ", "", "", "",
106 "", "", "50", ". ", "", ". ", ""},
107 EDGE = {"error.fileupload1", ". ", ". ", ". ", "", ". ", "", "", ". ", ". ",
108 ". ", ". ", ". ", ". ", ". ", ". ", "#000000", "", ". ", "", "", "",
109 "", "", "50", ". ", "", ". ", ""},
110 FF = {"error.fileupload1", ". ", ". ", ". ", "", ". ", "", "", ". ", ". ",
111 ". ", ". ", ". ", ". ", ". ", ". ", "#000000", "", ". ", "", "", ". ",
112 ". ", "", "50", ". ", "", ". ", ""},
113 FF_ESR = {"error.fileupload1", ". ", ". ", ". ", "", ". ", "", "", ". ", ". ",
114 ". ", ". ", ". ", ". ", ". ", ". ", "#000000", "", ". ", "", "", ". ",
115 ". ", "", "50", ". ", "", ". ", ""})
116 @Test
117 public void setValueBlankString() throws Exception {
118 testValue("' '");
119 }
120
121
122
123
124 @Alerts(DEFAULT = {"error.fileupload1", "12", "12", "12", "", "12", "", "", "12", "12",
125 "12", "12", "12", "12", "12", "12", "#000000", "", "12", "", "", "",
126 "", "12", "12", "12", "12", "12", "12"},
127 FF = {"error.fileupload1", "12", "12", "12", "", "12", "", "", "12", "12",
128 "12", "12", "12", "12", "12", "12", "#000000", "", "12", "", "", "12",
129 "12", "12", "12", "12", "12", "12", "12"},
130 FF_ESR = {"error.fileupload1", "12", "12", "12", "", "12", "", "", "12", "12",
131 "12", "12", "12", "12", "12", "12", "#000000", "", "12", "", "", "12",
132 "12", "12", "12", "12", "12", "12", "12"})
133 @Test
134 public void setValueNumber() throws Exception {
135 testValue("12");
136 }
137
138
139
140
141 @Alerts({"", "null", "", "", "", "", "", "", "",
142 "", "null", "", "null", "", "", "#000000", "", "", "", "", "",
143 "", "", "50", "", "", "", ""})
144 @Test
145 public void setValueNull() throws Exception {
146 testValue("null");
147 }
148
149 private void testValue(final String value) throws Exception {
150 final String html = DOCTYPE_HTML
151 + "<html><head><script>\n"
152 + "function log(msg) { window.document.title += msg.replace(' ', '.') + '§';}\n"
153 + "function doTest() {\n"
154
155 + " document.form1.button1.value = " + value + ";\n"
156 + " document.form1.button2.value = " + value + ";\n"
157 + " document.form1.checkbox1.value = " + value + ";\n"
158 + " try { document.form1.fileupload1.value = " + value + " } catch(e) { log('error fileupload1') }\n"
159 + " document.form1.hidden1.value = " + value + ";\n"
160 + " document.form1.select1.value = " + value + ";\n"
161 + " document.form1.select2.value = " + value + ";\n"
162 + " document.form1.password1.value = " + value + ";\n"
163 + " document.form1.radio1.value = " + value + ";\n"
164 + " document.form1.reset1.value = " + value + ";\n"
165 + " document.form1.reset2.value = " + value + ";\n"
166 + " document.form1.submit1.value = " + value + ";\n"
167 + " document.form1.submit2.value = " + value + ";\n"
168 + " document.form1.textInput1.value = " + value + ";\n"
169 + " document.form1.textarea1.value = " + value + ";\n"
170 + " document.form1.color1.value = " + value + ";\n"
171 + " document.form1.date1.value = " + value + ";\n"
172 + " document.form1.datetime1.value = " + value + ";\n"
173 + " document.form1.datetimeLocal1.value = " + value + ";\n"
174 + " document.form1.time1.value = " + value + ";\n"
175 + " document.form1.week1.value = " + value + ";\n"
176 + " document.form1.month1.value = " + value + ";\n"
177 + " document.form1.number1.value = " + value + ";\n"
178 + " document.form1.range1.value = " + value + ";\n"
179 + " document.form1.search1.value = " + value + ";\n"
180 + " document.form1.email1.value = " + value + ";\n"
181 + " document.form1.tel1.value = " + value + ";\n"
182 + " document.form1.url1.value = " + value + ";\n"
183
184 + " log(document.form1.button1.value);\n"
185 + " log(document.form1.button2.value);\n"
186 + " log(document.form1.checkbox1.value);\n"
187 + " log(document.form1.fileupload1.value);\n"
188 + " log(document.form1.hidden1.value);\n"
189 + " log(document.form1.select1.value);\n"
190 + " log(document.form1.select2.value);\n"
191 + " log(document.form1.password1.value);\n"
192 + " log(document.form1.radio1.value);\n"
193 + " log(document.form1.reset1.value);\n"
194 + " log(document.form1.reset2.value);\n"
195 + " log(document.form1.submit1.value);\n"
196 + " log(document.form1.submit2.value);\n"
197 + " log(document.form1.textInput1.value);\n"
198 + " log(document.form1.textarea1.value);\n"
199 + " log(document.form1.color1.value);\n"
200 + " log(document.form1.date1.value);\n"
201 + " log(document.form1.datetime1.value);\n"
202 + " log(document.form1.datetimeLocal1.value);\n"
203 + " log(document.form1.time1.value);\n"
204 + " log(document.form1.week1.value);\n"
205 + " log(document.form1.month1.value);\n"
206 + " log(document.form1.number1.value);\n"
207 + " log(document.form1.range1.value);\n"
208 + " log(document.form1.search1.value);\n"
209 + " log(document.form1.email1.value);\n"
210 + " log(document.form1.tel1.value);\n"
211 + " log(document.form1.url1.value);\n"
212 + "}\n"
213 + "</script></head><body onload='doTest()'>\n"
214 + "<p>hello world</p>\n"
215 + "<form name='form1'>\n"
216 + " <input type='button' name='button1'></button>\n"
217 + " <button type='button' name='button2'></button>\n"
218 + " <input type='checkbox' name='checkbox1'/>\n"
219 + " <input type='file' name='fileupload1'/>\n"
220 + " <input type='hidden' name='hidden1'/>\n"
221 + " <select name='select1'>\n"
222 + " <option>foo</option>\n"
223 + " </select>\n"
224 + " <select multiple='multiple' name='select2'>\n"
225 + " <option>boo</option>\n"
226 + " </select>\n"
227 + " <input type='password' name='password1'/>\n"
228 + " <input type='radio' name='radio1'/>\n"
229 + " <input type='reset' name='reset1'/>\n"
230 + " <button type='reset' name='reset2'></button>\n"
231 + " <input type='submit' name='submit1'/>\n"
232 + " <button type='submit' name='submit2'></button>\n"
233 + " <input type='text' name='textInput1'/>\n"
234 + " <textarea name='textarea1'>foo</textarea>\n"
235 + " <input type='color' name='color1'/>\n"
236 + " <input type='date' name='date1'/>\n"
237 + " <input type='datetime' name='datetime1'/>\n"
238 + " <input type='datetime-local' name='datetimeLocal1'/>\n"
239 + " <input type='time' name='time1'/>\n"
240 + " <input type='week' name='week1'/>\n"
241 + " <input type='month' name='month1'/>\n"
242 + " <input type='number' name='number1'/>\n"
243 + " <input type='range' name='range1'/>\n"
244 + " <input type='search' name='search1'/>\n"
245 + " <input type='email' name='email1'/>\n"
246 + " <input type='tel' name='tel1'/>\n"
247 + " <input type='url' name='url1'/>\n"
248 + "</form>\n"
249 + "</body></html>";
250
251 loadPageVerifyTitle2(html);
252 }
253
254
255
256
257 @Test
258 @Alerts(DEFAULT = {"button", "button", "checkbox", "file", "hidden", "select-one", "select-multiple",
259 "password", "radio", "reset", "reset",
260 "submit", "submit", "text", "textarea", "color", "date", "text",
261 "datetime-local", "time", "week", "month", "number",
262 "range", "search", "email", "tel", "url"},
263 FF = {"button", "button", "checkbox", "file", "hidden", "select-one", "select-multiple",
264 "password", "radio", "reset", "reset",
265 "submit", "submit", "text", "textarea", "color", "date", "text",
266 "datetime-local", "time", "text", "text", "number", "range",
267 "search", "email", "tel", "url"},
268 FF_ESR = {"button", "button", "checkbox", "file", "hidden", "select-one", "select-multiple",
269 "password", "radio", "reset", "reset",
270 "submit", "submit", "text", "textarea", "color", "date", "text",
271 "datetime-local", "time", "text", "text", "number", "range",
272 "search", "email", "tel", "url"})
273 public void type() throws Exception {
274 testAttribute("type", "", null);
275 }
276
277
278
279
280 @Alerts({"null", "undefined", "null", "[object FileList]", "null", "undefined", "undefined", "null",
281 "null", "null", "undefined", "null", "undefined", "null", "undefined", "null", "null", "null",
282 "null", "null", "null", "null", "null", "null", "null", "null", "null", "null"})
283 @Test
284 public void files() throws Exception {
285 testAttribute("files", "", null);
286 }
287
288
289
290
291 @Alerts({"false", "undefined", "false", "false", "false", "undefined", "undefined",
292 "false", "false", "false", "undefined", "false", "undefined", "false",
293 "undefined", "false", "false", "false", "false", "false", "false",
294 "false", "false", "false", "false", "false", "false", "false"})
295 @Test
296 public void checked() throws Exception {
297 testAttribute("checked", "", null);
298 }
299
300
301
302
303 @Alerts({"true", "undefined", "true", "true", "true", "undefined", "undefined",
304 "true", "true", "true", "undefined", "true", "undefined", "true",
305 "undefined", "true", "true", "true", "true", "true", "true",
306 "true", "true", "true", "true", "true", "true", "true"})
307 @Test
308 public void checkedWithAttribute() throws Exception {
309 testAttribute("checked", "checked", null);
310 }
311
312
313
314
315 @Alerts({"true", "undefined", "true", "true", "true", "undefined", "undefined",
316 "true", "true", "true", "undefined", "true", "undefined", "true",
317 "undefined", "true", "true", "true", "true", "true", "true",
318 "true", "true", "true", "true", "true", "true", "true"})
319 @Test
320 public void setCheckedTrue() throws Exception {
321 testAttribute("checked", "", "true");
322 }
323
324
325
326
327 @Alerts({"true", "undefined", "true", "true", "true", "undefined", "undefined",
328 "true", "true", "true", "undefined", "true", "undefined", "true",
329 "undefined", "true", "true", "true", "true", "true", "true",
330 "true", "true", "true", "true", "true", "true", "true"})
331 @Test
332 public void setCheckedBlank() throws Exception {
333 testAttribute("checked", "", "");
334 }
335
336 private void testAttribute(final String property, final String attrib, final String value) throws Exception {
337 String html = DOCTYPE_HTML
338 + "<html><head><script>\n"
339 + LOG_TITLE_FUNCTION
340 + "function doTest() {\n";
341
342 if (value != null) {
343 html = html
344 + " document.form1.button1.setAttribute('" + property + "', '" + value + "');\n"
345 + " document.form1.button2.setAttribute('" + property + "', '" + value + "');\n"
346 + " document.form1.checkbox1.setAttribute('" + property + "', '" + value + "');\n"
347 + " document.form1.fileupload1.setAttribute('" + property + "', '" + value + "');\n"
348 + " document.form1.hidden1.setAttribute('" + property + "', '" + value + "');\n"
349 + " document.form1.select1.setAttribute('" + property + "', '" + value + "');\n"
350 + " document.form1.select2.setAttribute('" + property + "', '" + value + "');\n"
351 + " document.form1.password1.setAttribute('" + property + "', '" + value + "');\n"
352 + " document.form1.radio1.setAttribute('" + property + "', '" + value + "');\n"
353 + " document.form1.reset1.setAttribute('" + property + "', '" + value + "');\n"
354 + " document.form1.reset2.setAttribute('" + property + "', '" + value + "');\n"
355 + " document.form1.submit1.setAttribute('" + property + "', '" + value + "');\n"
356 + " document.form1.submit2.setAttribute('" + property + "', '" + value + "');\n"
357 + " document.form1.textInput1.setAttribute('" + property + "', '" + value + "');\n"
358 + " document.form1.textarea1.setAttribute('" + property + "', '" + value + "');\n"
359 + " document.form1.color1.setAttribute('" + property + "', '" + value + "');\n"
360 + " document.form1.date1.setAttribute('" + property + "', '" + value + "');\n"
361 + " document.form1.datetime1.setAttribute('" + property + "', '" + value + "');\n"
362 + " document.form1.datetimeLocal1.setAttribute('" + property + "', '" + value + "');\n"
363 + " document.form1.time1.setAttribute('" + property + "', '" + value + "');\n"
364 + " document.form1.week1.setAttribute('" + property + "', '" + value + "');\n"
365 + " document.form1.month1.setAttribute('" + property + "', '" + value + "');\n"
366 + " document.form1.number1.setAttribute('" + property + "', '" + value + "');\n"
367 + " document.form1.range1.setAttribute('" + property + "', '" + value + "');\n"
368 + " document.form1.search1.setAttribute('" + property + "', '" + value + "');\n"
369 + " document.form1.email1.setAttribute('" + property + "', '" + value + "');\n"
370 + " document.form1.tel1.setAttribute('" + property + "', '" + value + "');\n"
371 + " document.form1.url1.setAttribute('" + property + "', '" + value + "');\n";
372 }
373
374 html = html
375 + " log(document.form1.button1." + property + ");\n"
376 + " log(document.form1.button2." + property + ");\n"
377 + " log(document.form1.checkbox1." + property + ");\n"
378 + " log(document.form1.fileupload1." + property + ");\n"
379 + " log(document.form1.hidden1." + property + ");\n"
380 + " log(document.form1.select1." + property + ");\n"
381 + " log(document.form1.select2." + property + ");\n"
382 + " log(document.form1.password1." + property + ");\n"
383 + " log(document.form1.radio1." + property + ");\n"
384 + " log(document.form1.reset1." + property + ");\n"
385 + " log(document.form1.reset2." + property + ");\n"
386 + " log(document.form1.submit1." + property + ");\n"
387 + " log(document.form1.submit2." + property + ");\n"
388 + " log(document.form1.textInput1." + property + ");\n"
389 + " log(document.form1.textarea1." + property + ");\n"
390 + " log(document.form1.color1." + property + ");\n"
391 + " log(document.form1.date1." + property + ");\n"
392 + " log(document.form1.datetime1." + property + ");\n"
393 + " log(document.form1.datetimeLocal1." + property + ");\n"
394 + " log(document.form1.time1." + property + ");\n"
395 + " log(document.form1.week1." + property + ");\n"
396 + " log(document.form1.month1." + property + ");\n"
397 + " log(document.form1.number1." + property + ");\n"
398 + " log(document.form1.range1." + property + ");\n"
399 + " log(document.form1.search1." + property + ");\n"
400 + " log(document.form1.email1." + property + ");\n"
401 + " log(document.form1.tel1." + property + ");\n"
402 + " log(document.form1.url1." + property + ");\n"
403 + "}\n"
404 + "</script></head><body onload='doTest()'>\n"
405 + "<p>hello world</p>\n"
406 + "<form name='form1'>\n"
407 + " <input type='button' name='button1' " + attrib + "></button>\n"
408 + " <button type='button' name='button2' " + attrib + "></button>\n"
409 + " <input type='checkbox' name='checkbox1' " + attrib + "/>\n"
410 + " <input type='file' name='fileupload1' " + attrib + "/>\n"
411 + " <input type='hidden' name='hidden1' " + attrib + "/>\n"
412 + " <select name='select1' " + attrib + ">\n"
413 + " <option>foo</option>\n"
414 + " </select>\n"
415 + " <select multiple='multiple' name='select2' " + attrib + ">\n"
416 + " <option>foo</option>\n"
417 + " </select>\n"
418 + " <input type='password' name='password1' " + attrib + "/>\n"
419 + " <input type='radio' name='radio1' " + attrib + "/>\n"
420 + " <input type='reset' name='reset1' " + attrib + "/>\n"
421 + " <button type='reset' name='reset2' " + attrib + "></button>\n"
422 + " <input type='submit' name='submit1' " + attrib + "/>\n"
423 + " <button type='submit' name='submit2' " + attrib + "></button>\n"
424 + " <input type='text' name='textInput1' " + attrib + "/>\n"
425 + " <textarea name='textarea1' " + attrib + ">foo</textarea>\n"
426 + " <input type='color' name='color1' " + attrib + "/>\n"
427 + " <input type='date' name='date1' " + attrib + "/>\n"
428 + " <input type='datetime' name='datetime1' " + attrib + "/>\n"
429 + " <input type='datetime-local' name='datetimeLocal1' " + attrib + "/>\n"
430 + " <input type='time' name='time1' " + attrib + "/>\n"
431 + " <input type='week' name='week1' " + attrib + "/>\n"
432 + " <input type='month' name='month1' " + attrib + "/>\n"
433 + " <input type='number' name='number1' " + attrib + "/>\n"
434 + " <input type='range' name='range1' " + attrib + "/>\n"
435 + " <input type='search' name='search1' " + attrib + "/>\n"
436 + " <input type='email' name='email1' " + attrib + "/>\n"
437 + " <input type='tel' name='tel1' " + attrib + "/>\n"
438 + " <input type='url' name='url1' " + attrib + "/>\n"
439 + "</form>\n"
440 + "</body></html>";
441
442 loadPageVerifyTitle2(html);
443 }
444
445
446
447
448 @Alerts("abc")
449 @Test
450 public void setValueAttributeInputButton() throws Exception {
451 testAttribute("button1", "value", "", "abc");
452 }
453
454
455
456
457 @Alerts("abc")
458 @Test
459 public void setValueAttributeButton() throws Exception {
460 testAttribute("button2", "value", "", "abc");
461 }
462
463
464
465
466 @Alerts("abc")
467 @Test
468 public void setValueAttributeCheckbox() throws Exception {
469 testAttribute("checkbox1", "value", "", "abc");
470 }
471
472
473
474
475 @Alerts("")
476 @Test
477 public void setValueAttributeFile() throws Exception {
478 testAttribute("fileupload1", "value", "", "abc");
479 }
480
481
482
483
484 @Alerts("abc")
485 @Test
486 public void setValueAttributeHidden() throws Exception {
487 testAttribute("hidden1", "value", "", "abc");
488 }
489
490
491
492
493 @Alerts("foo")
494 @Test
495 public void setValueAttributeSelect() throws Exception {
496 testAttribute("select1", "value", "", "abc");
497 }
498
499
500
501
502 @Alerts("")
503 @Test
504 public void setValueAttributeSelectMultiple() throws Exception {
505 testAttribute("select2", "value", "", "abc");
506 }
507
508
509
510
511 @Alerts("abc")
512 @Test
513 public void setValueAttributePassword() throws Exception {
514 testAttribute("password1", "value", "", "abc");
515 }
516
517
518
519
520 @Alerts("abc")
521 @Test
522 public void setValueAttributeRadio() throws Exception {
523 testAttribute("radio1", "value", "", "abc");
524 }
525
526
527
528
529 @Alerts("abc")
530 @Test
531 public void setValueAttributeReset() throws Exception {
532 testAttribute("reset1", "value", "", "abc");
533 }
534
535
536
537
538 @Alerts("abc")
539 @Test
540 public void setValueAttributeResetButton() throws Exception {
541 testAttribute("reset2", "value", "", "abc");
542 }
543
544
545
546
547 @Alerts("abc")
548 @Test
549 public void setValueAttributeSubmit() throws Exception {
550 testAttribute("submit1", "value", "", "abc");
551 }
552
553
554
555
556 @Alerts("abc")
557 @Test
558 public void setValueAttributeSubmitButton() throws Exception {
559 testAttribute("submit2", "value", "", "abc");
560 }
561
562
563
564
565 @Alerts("abc")
566 @Test
567 public void setValueAttributeText() throws Exception {
568 testAttribute("textInput1", "value", "", "abc");
569 }
570
571
572
573
574 @Alerts("foo")
575 @Test
576 public void setValueAttributeTextArea() throws Exception {
577 testAttribute("textarea1", "value", "", "abc");
578 }
579
580
581
582
583 @Alerts("#000000")
584 @Test
585 public void setValueAttributeColor() throws Exception {
586 testAttribute("color1", "value", "", "abc");
587 }
588
589
590
591
592 @Alerts("")
593 @HtmlUnitNYI(CHROME = "abc",
594 EDGE = "abc",
595 FF = "abc",
596 FF_ESR = "abc")
597 @Test
598 public void setValueAttributeDate() throws Exception {
599 testAttribute("date1", "value", "", "abc");
600 }
601
602
603
604
605 @Alerts("abc")
606 @Test
607 public void setValueAttributeDateTime() throws Exception {
608 testAttribute("datetime1", "value", "", "abc");
609 }
610
611
612
613
614 @Alerts("")
615 @HtmlUnitNYI(CHROME = "abc",
616 EDGE = "abc",
617 FF = "abc",
618 FF_ESR = "abc")
619 @Test
620 public void setValueAttributeDateTimeLocal() throws Exception {
621 testAttribute("datetimeLocal1", "value", "", "abc");
622 }
623
624
625
626
627 @Alerts("")
628 @Test
629 public void setValueAttributeTime() throws Exception {
630 testAttribute("time1", "value", "", "abc");
631 }
632
633
634
635
636 @Alerts(DEFAULT = "",
637 FF = "abc",
638 FF_ESR = "abc")
639 @HtmlUnitNYI(CHROME = "abc",
640 EDGE = "abc")
641 @Test
642 public void setValueAttributeWeek() throws Exception {
643 testAttribute("week1", "value", "", "abc");
644 }
645
646
647
648
649 @Alerts(DEFAULT = "",
650 FF = "abc",
651 FF_ESR = "abc")
652 @HtmlUnitNYI(CHROME = "abc",
653 EDGE = "abc")
654 @Test
655 public void setValueAttributeMonth() throws Exception {
656 testAttribute("month1", "value", "", "abc");
657 }
658
659
660
661
662 @Alerts("")
663 @Test
664 public void setValueAttributeNumber() throws Exception {
665 testAttribute("number1", "value", "", "abc");
666 }
667
668
669
670
671 @Alerts("50")
672 @Test
673 public void setValueAttributeRange() throws Exception {
674 testAttribute("range1", "value", "", "abc");
675 }
676
677
678
679
680 @Alerts("abc")
681 @Test
682 public void setValueAttributeSearch() throws Exception {
683 testAttribute("search1", "value", "", "abc");
684 }
685
686
687
688
689 @Alerts("abc")
690 @Test
691 public void setValueAttributeEmail() throws Exception {
692 testAttribute("email1", "value", "", "abc");
693 }
694
695
696
697
698 @Alerts("abc")
699 @Test
700 public void setValueAttributeTel() throws Exception {
701 testAttribute("tel1", "value", "", "abc");
702 }
703
704
705
706
707 @Alerts("abc")
708 @Test
709 public void setValueAttributeUrl() throws Exception {
710 testAttribute("url1", "value", "", "abc");
711 }
712
713 private void testAttribute(final String itemId, final String property,
714 final String attrib, final String value) throws Exception {
715 String html = DOCTYPE_HTML
716 + "<html><head><script>\n"
717 + LOG_TITLE_FUNCTION
718 + "function doTest() {\n";
719
720 if (value != null) {
721 html = html
722 + " document.form1." + itemId + ".setAttribute('" + property + "', '" + value + "');\n";
723 }
724
725 html = html
726 + " log(document.form1." + itemId + "." + property + ");\n"
727 + "}\n"
728 + "</script></head><body onload='doTest()'>\n"
729 + "<p>hello world</p>\n"
730 + "<form name='form1'>\n"
731 + " <input type='button' name='button1' " + attrib + "></button>\n"
732 + " <button type='button' name='button2' " + attrib + "></button>\n"
733 + " <input type='checkbox' name='checkbox1' " + attrib + "/>\n"
734 + " <input type='file' name='fileupload1' " + attrib + "/>\n"
735 + " <input type='hidden' name='hidden1' " + attrib + "/>\n"
736 + " <select name='select1' " + attrib + ">\n"
737 + " <option>foo</option>\n"
738 + " </select>\n"
739 + " <select multiple='multiple' name='select2' " + attrib + ">\n"
740 + " <option>foo</option>\n"
741 + " </select>\n"
742 + " <input type='password' name='password1' " + attrib + "/>\n"
743 + " <input type='radio' name='radio1' " + attrib + "/>\n"
744 + " <input type='reset' name='reset1' " + attrib + "/>\n"
745 + " <button type='reset' name='reset2' " + attrib + "></button>\n"
746 + " <input type='submit' name='submit1' " + attrib + "/>\n"
747 + " <button type='submit' name='submit2' " + attrib + "></button>\n"
748 + " <input type='text' name='textInput1' " + attrib + "/>\n"
749 + " <textarea name='textarea1' " + attrib + ">foo</textarea>\n"
750 + " <input type='color' name='color1' " + attrib + "/>\n"
751 + " <input type='date' name='date1' " + attrib + "/>\n"
752 + " <input type='datetime' name='datetime1' " + attrib + "/>\n"
753 + " <input type='datetime-local' name='datetimeLocal1' " + attrib + "/>\n"
754 + " <input type='time' name='time1' " + attrib + "/>\n"
755 + " <input type='week' name='week1' " + attrib + "/>\n"
756 + " <input type='month' name='month1' " + attrib + "/>\n"
757 + " <input type='number' name='number1' " + attrib + "/>\n"
758 + " <input type='range' name='range1' " + attrib + "/>\n"
759 + " <input type='search' name='search1' " + attrib + "/>\n"
760 + " <input type='email' name='email1' " + attrib + "/>\n"
761 + " <input type='tel' name='tel1' " + attrib + "/>\n"
762 + " <input type='url' name='url1' " + attrib + "/>\n"
763 + "</form>\n"
764 + "</body></html>";
765
766 loadPageVerifyTitle2(html);
767 }
768
769
770
771
772 @Alerts({"abc-abc", "abc-abc", "jkl-abc"})
773 @Test
774 public void typeChangeNotDirty() throws Exception {
775 final String html = DOCTYPE_HTML
776 + "<html><head><script>\n"
777 + LOG_TITLE_FUNCTION
778 + "function doTest() {\n"
779 + " var inpt = document.form1.textInput1;\n"
780 + " log(inpt.value + '-' + inpt.defaultValue);\n"
781
782 + " inpt.type = 'password';\n"
783 + " log(inpt.value + '-' + inpt.defaultValue);\n"
784
785 + " inpt.value = 'jkl';\n"
786 + " log(inpt.value + '-' + inpt.defaultValue);\n"
787 + "}\n"
788 + "</script></head><body onload='doTest()'>\n"
789 + "<p>hello world</p>\n"
790 + "<form name='form1'>\n"
791 + " <input type='text' name='textInput1' value='abc'/>\n"
792 + "</form>\n"
793 + "</body></html>";
794
795 loadPageVerifyTitle2(html);
796 }
797
798
799
800
801 @Alerts({"abc-abc", "def-abc", "ghi-abc", "ghi-abc", "jkl-abc"})
802 @Test
803 public void typeChangeDirty() throws Exception {
804 final String html = DOCTYPE_HTML
805 + "<html><head><script>\n"
806 + LOG_TITLE_FUNCTION
807 + "function doTest() {\n"
808 + " var inpt = document.form1.textInput1;\n"
809 + " log(inpt.value + '-' + inpt.defaultValue);\n"
810
811 + " inpt.value = 'def';\n"
812 + " log(inpt.value + '-' + inpt.defaultValue);\n"
813
814 + " inpt.value = 'ghi';\n"
815 + " log(inpt.value + '-' + inpt.defaultValue);\n"
816
817 + " inpt.type = 'password';\n"
818 + " log(inpt.value + '-' + inpt.defaultValue);\n"
819
820 + " inpt.value = 'jkl';\n"
821 + " log(inpt.value + '-' + inpt.defaultValue);\n"
822 + "}\n"
823 + "</script></head><body onload='doTest()'>\n"
824 + "<p>hello world</p>\n"
825 + "<form name='form1'>\n"
826 + " <input type='text' name='textInput1' value='abc'/>\n"
827 + "</form>\n"
828 + "</body></html>";
829
830 loadPageVerifyTitle2(html);
831 }
832
833
834
835
836 @Test
837 @Alerts({"false", "true"})
838 public void checkedAttribute_Checkbox() throws Exception {
839 final String html = DOCTYPE_HTML
840 + "<html><head><script>\n"
841 + LOG_TITLE_FUNCTION
842 + "function test() {\n"
843 + " log(document.form1.checkbox1.checked);\n"
844 + " document.form1.checkbox1.checked = true;\n"
845 + " log(document.form1.checkbox1.checked);\n"
846 + "}\n"
847 + "</script></head><body>\n"
848 + "<p>hello world</p>\n"
849 + "<form name='form1'>\n"
850 + " <input type='cheCKbox' name='checkbox1' id='checkbox1' value='foo' />\n"
851 + "</form>\n"
852 + "<a href='javascript:test()' id='clickme'>click me</a>\n"
853 + "</body></html>";
854
855 final WebDriver driver = loadPage2(html);
856 final WebElement checkBox = driver.findElement(By.id("checkbox1"));
857 assertFalse(checkBox.isSelected());
858
859 driver.findElement(By.id("clickme")).click();
860 verifyTitle2(driver, getExpectedAlerts());
861 assertTrue(checkBox.isSelected());
862 }
863
864
865
866
867 @Test
868 @Alerts({"true", "false", "false", "false", "true", "false"})
869 public void checkedAttribute_Radio() throws Exception {
870 final String html = DOCTYPE_HTML
871 + "<html><head><script>\n"
872 + LOG_TITLE_FUNCTION
873 + "function test() {\n"
874 + " log(document.form1.radio1[0].checked);\n"
875 + " log(document.form1.radio1[1].checked);\n"
876 + " log(document.form1.radio1[2].checked);\n"
877 + " document.form1.radio1[1].checked = true;\n"
878 + " log(document.form1.radio1[0].checked);\n"
879 + " log(document.form1.radio1[1].checked);\n"
880 + " log(document.form1.radio1[2].checked);\n"
881 + "}\n"
882 + "</script></head><body>\n"
883 + "<p>hello world</p>\n"
884 + "<form name='form1'>\n"
885 + " <input type='radio' name='radio1' id='radioA' value='a' checked='checked'/>\n"
886 + " <input type='RADIO' name='radio1' id='radioB' value='b' />\n"
887 + " <input type='radio' name='radio1' id='radioC' value='c' />\n"
888 + "</form>\n"
889 + "<a href='javascript:test()' id='clickme'>click me</a>\n"
890 + "</body></html>";
891
892 final WebDriver driver = loadPage2(html);
893 final WebElement radioA = driver.findElement(By.id("radioA"));
894 final WebElement radioB = driver.findElement(By.id("radioB"));
895 final WebElement radioC = driver.findElement(By.id("radioC"));
896 assertTrue(radioA.isSelected());
897 assertFalse(radioB.isSelected());
898 assertFalse(radioC.isSelected());
899
900 driver.findElement(By.id("clickme")).click();
901 verifyTitle2(driver, getExpectedAlerts());
902 assertFalse(radioA.isSelected());
903 assertTrue(radioB.isSelected());
904 assertFalse(radioC.isSelected());
905 }
906
907
908
909
910 @Test
911 @Alerts({"false", "true", "false", "true", "false", "true"})
912 public void disabledAttribute() throws Exception {
913 final String html = DOCTYPE_HTML
914 + "<html><head><script>\n"
915 + LOG_TITLE_FUNCTION
916 + "function test() {\n"
917 + " log(document.form1.button1.disabled);\n"
918 + " log(document.form1.button2.disabled);\n"
919 + " log(document.form1.button3.disabled);\n"
920 + " document.form1.button1.disabled = true;\n"
921 + " document.form1.button2.disabled = false;\n"
922 + " document.form1.button3.disabled = true;\n"
923 + " log(document.form1.button1.disabled);\n"
924 + " log(document.form1.button2.disabled);\n"
925 + " log(document.form1.button3.disabled);\n"
926 + "}\n"
927 + "</script></head><body>\n"
928 + "<p>hello world</p>\n"
929 + "<form name='form1'>\n"
930 + " <input type='submit' name='button1' value='1'/>\n"
931 + " <input type='submit' name='button2' value='2' disabled/>\n"
932 + " <input type='submit' name='button3' value='3'/>\n"
933 + "</form>\n"
934 + "<a href='javascript:test()' id='clickme'>click me</a>\n"
935 + "</body></html>";
936
937 final WebDriver driver = loadPage2(html);
938
939 final WebElement button1 = driver.findElement(By.name("button1"));
940 final WebElement button2 = driver.findElement(By.name("button2"));
941 final WebElement button3 = driver.findElement(By.name("button3"));
942 assertTrue(button1.isEnabled());
943 assertFalse(button2.isEnabled());
944 assertTrue(button3.isEnabled());
945
946 driver.findElement(By.id("clickme")).click();
947 verifyTitle2(driver, getExpectedAlerts());
948 assertFalse(button1.isEnabled());
949 assertTrue(button2.isEnabled());
950 assertFalse(button3.isEnabled());
951 }
952
953
954
955
956 @Test
957 public void inputValue() throws Exception {
958 final String html = DOCTYPE_HTML
959 + "<html><head><title>foo</title><script>\n"
960 + "function doTest() {\n"
961 + " document.form1.textfield1.value = 'blue';\n"
962 + "}\n"
963 + "</script></head>\n"
964 + "<body>\n"
965 + "<p>hello world</p>\n"
966 + "<form name='form1' onsubmit='doTest()'>\n"
967 + " <input type='text' name='textfield1' id='textfield1' value='foo' />\n"
968 + " <input type='submit' id='clickMe'/>\n"
969 + "</form>\n"
970 + "</body></html>";
971
972 getMockWebConnection().setDefaultResponse("");
973 final WebDriver driver = loadPage2(html);
974 driver.findElement(By.id("clickMe")).click();
975 assertEquals(URL_FIRST + "?textfield1=blue", driver.getCurrentUrl());
976 }
977
978
979
980
981 @Test
982 public void inputSelect_NotDefinedAsPropertyAndFunction() throws Exception {
983 final String html = DOCTYPE_HTML
984 + "<html><head><title>foo</title><script>\n"
985 + "function doTest() {\n"
986 + " document.form1.textfield1.select();\n"
987 + "}\n"
988 + "</script></head>\n"
989 + "<body>\n"
990 + "<p>hello world</p>\n"
991 + "<form name='form1' onsubmit='doTest()'>\n"
992 + " <input type='text' name='textfield1' id='textfield1' value='foo' />\n"
993 + " <input type='submit' id='clickMe'/>\n"
994 + "</form>\n"
995 + "</body></html>";
996
997 getMockWebConnection().setDefaultResponse("");
998 final WebDriver driver = loadPage2(html);
999 driver.findElement(By.id("clickMe")).click();
1000 assertEquals(URL_FIRST + "?textfield1=foo", driver.getCurrentUrl());
1001 }
1002
1003
1004
1005
1006 @Test
1007 @Alerts("true")
1008 public void thisDotFormInOnClick() throws Exception {
1009 final String html = DOCTYPE_HTML
1010 + "<html>\n"
1011 + "<body>\n"
1012 + "<form name='form1'>\n"
1013 + "<input type='submit' id='clickMe' onClick=\"this.form.target='_blank'; return false;\">\n"
1014 + "</form>\n"
1015 + "<script>\n"
1016 + LOG_TITLE_FUNCTION
1017 + "log(document.forms[0].target == '');\n"
1018 + "</script>\n"
1019 + "</body></html>";
1020
1021 final WebDriver driver = loadPageVerifyTitle2(html);
1022 driver.findElement(By.id("clickMe")).click();
1023
1024 assertEquals("_blank", driver.findElement(By.name("form1")).getDomProperty("target"));
1025 }
1026
1027
1028
1029
1030 @Test
1031 @Alerts({"true", "true", "true", "true", "true"})
1032 public void fieldDotForm() throws Exception {
1033 final String html = DOCTYPE_HTML
1034 + "<html>\n"
1035 + "<head><script>\n"
1036 + LOG_TITLE_FUNCTION
1037 + "function test() {\n"
1038 + " var f = document.form1;\n"
1039 + " log(f == f.mySubmit.form);\n"
1040 + " log(f == f.myText.form);\n"
1041 + " log(f == f.myPassword.form);\n"
1042 + " log(f == document.getElementById('myImage').form);\n"
1043 + " log(f == f.myButton.form);\n"
1044 + "}\n"
1045 + "</script></head>\n"
1046 + "<body onload='test()'>\n"
1047 + "<form name='form1'>\n"
1048 + "<input type='submit' name='mySubmit'>\n"
1049 + "<input type='text' name='myText'>\n"
1050 + "<input type='password' name='myPassword'>\n"
1051 + "<input type='button' name='myButton'>\n"
1052 + "<input type='image' src='foo' name='myImage' id='myImage'>\n"
1053 + "</form>\n"
1054 + "</body></html>";
1055
1056 getMockWebConnection().setDefaultResponse("Error: not found", 404, "Not Found", MimeType.TEXT_HTML);
1057
1058 loadPageVerifyTitle2(html);
1059 }
1060
1061
1062
1063
1064 @Test
1065 public void inputNameChange() throws Exception {
1066 final String html = DOCTYPE_HTML
1067 + "<html><head><title>foo</title><script>\n"
1068 + "function doTest() {\n"
1069 + " document.form1.textfield1.name = 'changed';\n"
1070 + "}\n"
1071 + "</script></head><body>\n"
1072 + "<p>hello world</p>\n"
1073 + "<form name='form1' onsubmit='doTest()'>\n"
1074 + " <input type='text' name='textfield1' id='textfield1' value='foo' />\n"
1075 + " <input type='submit' name='button1' id='clickMe' value='pushme' />\n"
1076 + "</form>\n"
1077 + "</body></html>";
1078
1079 getMockWebConnection().setDefaultResponse("");
1080 final WebDriver driver = loadPage2(html);
1081 driver.findElement(By.id("clickMe")).click();
1082
1083 assertEquals(URL_FIRST + "?changed=foo&button1=pushme", driver.getCurrentUrl());
1084 }
1085
1086
1087
1088
1089 @Test
1090 @Alerts({"foo", "from button"})
1091 public void onChange() throws Exception {
1092 final String html = DOCTYPE_HTML
1093 + "<html><head><title></title>\n"
1094 + "</head><body>\n"
1095 + "<p>hello world</p>\n"
1096 + "<form name='form1'>\n"
1097 + " <input type='text' name='text1' onchange='document.title += this.value'>\n"
1098 + " <input name='myButton' type='button' onclick='document.form1.text1.value=\"from button\"'>\n"
1099 + "</form>\n"
1100 + "</body></html>";
1101
1102 final WebDriver driver = loadPage2(html);
1103
1104 final WebElement textinput = driver.findElement(By.name("text1"));
1105 textinput.sendKeys("foo");
1106 final WebElement button = driver.findElement(By.name("myButton"));
1107 button.click();
1108 assertTitle(driver, getExpectedAlerts()[0]);
1109 Thread.sleep(100);
1110 assertEquals(getExpectedAlerts()[1], textinput.getDomProperty("value"));
1111 }
1112
1113
1114
1115
1116 @Test
1117 @Alerts({"foo", "from button"})
1118 public void onChangeSetByJavaScript() throws Exception {
1119 final String html = DOCTYPE_HTML
1120 + "<html><head>\n"
1121 + "</head><body>\n"
1122 + "<p>hello world</p>\n"
1123 + "<form name='form1'>\n"
1124 + " <input type='text' name='text1' id='text1'>\n"
1125 + " <input name='myButton' type='button' onclick='document.form1.text1.value=\"from button\"'>\n"
1126 + "</form>\n"
1127 + "<script>\n"
1128 + " document.getElementById('text1').onchange = function(event) { document.title += this.value; };\n"
1129 + "</script>\n"
1130 + "</body></html>";
1131
1132 final WebDriver driver = loadPage2(html);
1133
1134 final WebElement textinput = driver.findElement(By.name("text1"));
1135 textinput.sendKeys("foo");
1136 final WebElement button = driver.findElement(By.name("myButton"));
1137 button.click();
1138 assertTitle(driver, getExpectedAlerts()[0]);
1139
1140 Thread.sleep(100);
1141 assertEquals(getExpectedAlerts()[1], textinput.getDomProperty("value"));
1142 }
1143
1144
1145
1146
1147
1148 @Test
1149 @Alerts({"on", "on"})
1150 public void defautValue() throws Exception {
1151 final String html = DOCTYPE_HTML
1152 + "<html><head><script>\n"
1153 + LOG_TITLE_FUNCTION
1154 + "function doTest() {\n"
1155 + " log(document.myForm.myRadio.value);\n"
1156 + " log(document.myForm.myCheckbox.value);\n"
1157 + "}\n</script></head>\n"
1158 + "<body onload='doTest()'>\n"
1159 + "<form name='myForm' action='foo'>\n"
1160 + "<input type='radio' name='myRadio'/>\n"
1161 + "<input type='checkbox' name='myCheckbox'/>\n"
1162 + "</form></body></html>";
1163
1164 loadPageVerifyTitle2(html);
1165 }
1166
1167
1168
1169
1170
1171 @Test
1172 @Alerts(DEFAULT = {"text, checkbox, date, datetime-local, month, time, week, color, email, text, submit, "
1173 + "radio, hidden, password, image, reset, button, file, number,"
1174 + " range, search, tel, url, text, text",
1175 "text, checkbox, date, datetime-local, month, time, week, color, email, text, submit, radio, "
1176 + "hidden, password, image, reset, button, file, number, range, search, tel, url, text, text" },
1177 FF = {"text, checkbox, date, datetime-local, text, time, text, color, email, text, submit, radio, hidden, "
1178 + "password, image, reset, button, file, number, range, search, tel, url, text, text",
1179 "text, checkbox, date, datetime-local, text, time, text, color, "
1180 + "email, text, submit, radio, hidden, password, "
1181 + "image, reset, button, file, number, range, search, tel, url, text, text"},
1182 FF_ESR = {"text, checkbox, date, datetime-local, text, time, "
1183 + "text, color, email, text, submit, radio, hidden, "
1184 + "password, image, reset, button, file, number, range, search, tel, url, text, text",
1185 "text, checkbox, date, datetime-local, text, time, text, color, "
1186 + "email, text, submit, radio, hidden, password, "
1187 + "image, reset, button, file, number, range, search, tel, url, text, text"})
1188 public void changeType() throws Exception {
1189 final String html = DOCTYPE_HTML
1190 + "<html><head><script>\n"
1191 + LOG_TITLE_FUNCTION
1192 + "function doTest() {\n"
1193 + " var input = document.myForm.myInput;\n"
1194 + " var types = ['checkbox', 'date', 'datetime-local', 'month', 'time', 'week', 'color'"
1195 + ", 'email', 'text', 'submit', 'radio', 'hidden', 'password', 'image', 'reset'"
1196 + ", 'button', 'file', 'number', 'range', 'search', 'tel', 'url', 'unknown', 'text'];"
1197 + " var result = input.type;\n"
1198 + " for(i = 0; i < types.length; i++) {\n"
1199 + " try {\n"
1200 + " input.type = types[i];\n"
1201 + " result = result + ', ' + input.type;\n"
1202 + " } catch(e) { result = result + ', error';}\n"
1203 + " }\n"
1204 + " log(result);\n"
1205 + " result = input.type;\n"
1206 + " for(i = 0; i < types.length; i++) {\n"
1207 + " try {\n"
1208 + " input.setAttribute('type', types[i]);\n"
1209 + " result = result + ', ' + input.type;\n"
1210 + " } catch(e) { result = result + ', error';}\n"
1211 + " }\n"
1212 + " log(result);\n"
1213 + "}\n"
1214 + "</script></head>\n"
1215 + "<body onload='doTest()'>\n"
1216 + " <form name='myForm' action='foo'>\n"
1217 + " <input type='text' name='myInput'/>\n"
1218 + " </form>\n"
1219 + "</body></html>";
1220
1221 loadPageVerifyTitle2(html);
1222 }
1223
1224
1225
1226
1227
1228 @Test
1229 @Alerts({"button: false, false, function, function, , ",
1230 "submit: false, false, function, function, submit it!, submit it!",
1231 "file: false, false, function, function, , ",
1232 "checkbox: true, true, function, function, , on",
1233 "radio: true, true, function, function, , on",
1234 "text: false, false, function, function, , ",
1235 "password: false, false, function, function, , "})
1236 public void defaultValues() throws Exception {
1237 final String html = DOCTYPE_HTML
1238 + "<html><head></head><body>\n"
1239 + "<form name='myForm'>\n"
1240 + "<input type='button' name='myButton'/>\n"
1241 + "<input type='submit' name='mySubmit' value='submit it!'/>\n"
1242 + "<input type='file' name='myFile'/>\n"
1243 + "<input type='checkbox' name='myCheckbox' checked='true'/>\n"
1244 + "<input type='radio' name='myRadio' checked='true'/>\n"
1245 + "<input type='text' name='myText'/>\n"
1246 + "<input type='password' name='myPwd'/>\n"
1247 + "</form>\n"
1248 + "<script>\n"
1249 + LOG_TITLE_FUNCTION
1250 + "function details(_oInput) {\n"
1251 + " log(_oInput.type + ': '\n"
1252 + " + _oInput.checked + ', '\n"
1253 + " + _oInput.defaultChecked + ', '\n"
1254 + " + ((String(_oInput.click).indexOf('function') != -1) ? 'function' : 'unknown') + ', '\n"
1255 + " + ((String(_oInput.select).indexOf('function') != -1) ? 'function' : 'unknown') + ', '\n"
1256 + " + _oInput.defaultValue + ', '\n"
1257 + " + _oInput.value\n"
1258 + " );\n"
1259 + "}\n"
1260 + "var oForm = document.myForm;\n"
1261 + "details(oForm.myButton);\n"
1262 + "details(oForm.mySubmit);\n"
1263 + "details(oForm.myFile);\n"
1264 + "details(oForm.myCheckbox);\n"
1265 + "details(oForm.myRadio);\n"
1266 + "details(oForm.myText);\n"
1267 + "details(oForm.myPwd);\n"
1268 + "</script>\n"
1269 + "</body></html>";
1270
1271 loadPageVerifyTitle2(html);
1272 }
1273
1274
1275
1276
1277 @Test
1278 @Alerts({"text", "null", "hidden", "hidden"})
1279 public void createInputAndChangeType() throws Exception {
1280 final String html = DOCTYPE_HTML
1281 + "<html><head><script>\n"
1282 + LOG_TITLE_FUNCTION
1283 + "function doTest() {\n"
1284 + " var input = document.createElement('INPUT');\n"
1285 + " log(input.type);\n"
1286 + " log(input.getAttribute('type'));\n"
1287 + " input.type = 'hidden';\n"
1288 + " log(input.type);\n"
1289 + " log(input.getAttribute('type'));\n"
1290 + "}\n</script></head>\n"
1291 + "<body onload='doTest()'>\n"
1292 + "<form name='myForm' action='foo'>\n"
1293 + "</form></body></html>";
1294
1295 loadPageVerifyTitle2(html);
1296 }
1297
1298
1299
1300
1301 @Test
1302 @Alerts({"text", "null", "text", "text"})
1303 public void createInputAndChangeTypeToText() throws Exception {
1304 final String html = DOCTYPE_HTML
1305 + "<html><head><script>\n"
1306 + LOG_TITLE_FUNCTION
1307 + "function doTest() {\n"
1308 + " var input = document.createElement('INPUT');\n"
1309 + " log(input.type);\n"
1310 + " log(input.getAttribute('type'));\n"
1311 + " input.type = 'text';\n"
1312 + " log(input.type);\n"
1313 + " log(input.getAttribute('type'));\n"
1314 + "}\n</script></head>\n"
1315 + "<body onload='doTest()'>\n"
1316 + "<form name='myForm' action='foo'>\n"
1317 + "</form></body></html>";
1318
1319 loadPageVerifyTitle2(html);
1320 }
1321
1322
1323
1324
1325 @Test
1326 @Alerts("123")
1327 public void buttonOutsideForm() throws Exception {
1328 final String html = DOCTYPE_HTML
1329 + "<html><head></head><body>\n"
1330 + "<button id='clickme' onclick='alert(123)'>click me</button>\n"
1331 + "</body></html>";
1332
1333 final WebDriver driver = loadPage2(html);
1334 driver.findElement(By.id("clickme")).click();
1335
1336 verifyAlerts(driver, getExpectedAlerts());
1337 }
1338
1339
1340
1341
1342
1343 @Test
1344 public void onChangeCallsFormSubmit() throws Exception {
1345 final URL urlImage = new URL(URL_SECOND, "img.jpg");
1346 try (InputStream is = getClass().getClassLoader().getResourceAsStream("testfiles/tiny-jpg.img")) {
1347 final byte[] directBytes = IOUtils.toByteArray(is);
1348
1349 getMockWebConnection().setResponse(urlImage, directBytes, 200, "ok", "image/jpg", Collections.emptyList());
1350 }
1351
1352 final String html = DOCTYPE_HTML
1353 + "<html><head>\n"
1354 + "</head>\n"
1355 + "<body>\n"
1356 + " <form name='test' action='foo'>\n"
1357 + " <input name='field1' onchange='submit()'>\n"
1358 + " <img src='" + urlImage + "' width='4' height='4'>\n"
1359 + " </form>\n"
1360 + "</body></html>";
1361
1362 getMockWebConnection().setDefaultResponse(DOCTYPE_HTML + "<html><title>page 2</title><body></body></html>");
1363
1364 final WebDriver driver = loadPage2(html);
1365 driver.findElement(By.name("field1")).sendKeys("bla");
1366 driver.findElement(By.tagName("img")).click();
1367 assertTitle(driver, "page 2");
1368 }
1369
1370
1371
1372
1373 @Test
1374 @Alerts({"undefined", "30", "undefined", "30", "30", "30", "40", "50", "string", "number"})
1375 public void maxLength() throws Exception {
1376 final String html = DOCTYPE_HTML
1377 + "<html><head><script>\n"
1378 + LOG_TITLE_FUNCTION
1379 + "function doTest() {\n"
1380 + " var input = document.getElementById('text1');\n"
1381 + " log(input.maxlength);\n"
1382 + " log(input.maxLength);\n"
1383 + " log(input.MaxLength);\n"
1384 + " log(input.getAttribute('maxlength'));\n"
1385 + " log(input.getAttribute('maxLength'));\n"
1386 + " log(input.getAttribute('MaxLength'));\n"
1387 + " input.setAttribute('MaXlenGth', 40);\n"
1388 + " log(input.maxLength);\n"
1389 + " input.maxLength = 50;\n"
1390 + " log(input.getAttribute('maxlength'));\n"
1391 + " log(typeof input.getAttribute('maxLength'));\n"
1392 + " log(typeof input.maxLength);\n"
1393 + "}\n</script></head>\n"
1394 + "<body onload='doTest()'>\n"
1395 + "<form name='myForm' action='foo'>\n"
1396 + "<input type='text' id='text1' maxlength='30'/>\n"
1397 + "</form></body></html>";
1398
1399 loadPageVerifyTitle2(html);
1400 }
1401
1402
1403
1404
1405 @Test
1406 @Alerts({"undefined", "30", "undefined", "30", "30", "30", "40", "50", "string", "number"})
1407 public void minLength() throws Exception {
1408 final String html = DOCTYPE_HTML
1409 + "<html><head><script>\n"
1410 + LOG_TITLE_FUNCTION
1411 + "function doTest() {\n"
1412 + " var input = document.getElementById('text1');\n"
1413 + " log(input.minlength);\n"
1414 + " log(input.minLength);\n"
1415 + " log(input.MinLength);\n"
1416 + " log(input.getAttribute('minlength'));\n"
1417 + " log(input.getAttribute('minLength'));\n"
1418 + " log(input.getAttribute('MinLength'));\n"
1419 + " input.setAttribute('MiNlenGth', 40);\n"
1420 + " log(input.minLength);\n"
1421 + " input.minLength = 50;\n"
1422 + " log(input.getAttribute('minlength'));\n"
1423 + " log(typeof input.getAttribute('minLength'));\n"
1424 + " log(typeof input.minLength);\n"
1425 + "}\n</script></head>\n"
1426 + "<body onload='doTest()'>\n"
1427 + "<form name='myForm' action='foo'>\n"
1428 + "<input type='text' id='text1' minlength='30'/>\n"
1429 + "</form></body></html>";
1430
1431 loadPageVerifyTitle2(html);
1432 }
1433
1434
1435
1436
1437 @Test
1438 public void typeMaxLength() throws Exception {
1439 final String html = DOCTYPE_HTML
1440 + "<html><body>\n"
1441 + "<form>\n"
1442 + "<input type='text' id='text1' maxlength='5'/>\n"
1443 + "<input type='password' id='password1' maxlength='6'/>\n"
1444 + "</form></body></html>";
1445
1446 final WebDriver webDriver = loadPage2(html);
1447 final WebElement textField = webDriver.findElement(By.id("text1"));
1448 textField.sendKeys("123456789");
1449 assertEquals("12345", textField.getDomProperty("value"));
1450 textField.sendKeys(Keys.BACK_SPACE);
1451 textField.sendKeys("7");
1452 assertEquals("12347", textField.getDomProperty("value"));
1453
1454 final WebElement passwordField = webDriver.findElement(By.id("password1"));
1455 passwordField.sendKeys("123456789");
1456 assertEquals("123456", passwordField.getDomProperty("value"));
1457 passwordField.sendKeys(Keys.BACK_SPACE);
1458 passwordField.sendKeys("7");
1459 assertEquals("123457", passwordField.getDomProperty("value"));
1460 }
1461
1462
1463
1464
1465 @Test
1466 public void typeMaxLengthZero() throws Exception {
1467 final String html = DOCTYPE_HTML
1468 + "<html><body>\n"
1469 + "<form>\n"
1470 + "<input type='text' id='text1' maxlength='0'/>\n"
1471 + "<input type='password' id='password1' maxlength='0'/>\n"
1472 + "</form></body></html>";
1473
1474 final WebDriver webDriver = loadPage2(html);
1475 final WebElement textField = webDriver.findElement(By.id("text1"));
1476 textField.sendKeys("123456789");
1477 assertEquals("", textField.getDomProperty("value"));
1478 textField.sendKeys("\b7");
1479 assertEquals("", textField.getDomProperty("value"));
1480
1481 final WebElement passwordField = webDriver.findElement(By.id("password1"));
1482 passwordField.sendKeys("123456789");
1483 assertEquals("", passwordField.getDomProperty("value"));
1484 passwordField.sendKeys("\b7");
1485 assertEquals("", passwordField.getDomProperty("value"));
1486 }
1487
1488
1489
1490
1491 @Test
1492 public void typeMaxLengthAndBlanks() throws Exception {
1493 final String html = DOCTYPE_HTML
1494 + "<html><body>\n"
1495 + "<form>\n"
1496 + "<input type='text' id='text1' maxlength=' 2 '/>\n"
1497 + "<input type='password' id='password1' maxlength=' 4 '/>\n"
1498 + "</form></body></html>";
1499
1500 final WebDriver webDriver = loadPage2(html);
1501 final WebElement textField = webDriver.findElement(By.id("text1"));
1502 textField.sendKeys("123456789");
1503 assertEquals("12", textField.getDomProperty("value"));
1504 textField.sendKeys(Keys.BACK_SPACE);
1505 textField.sendKeys("7");
1506 assertEquals("17", textField.getDomProperty("value"));
1507
1508 final WebElement passwordField = webDriver.findElement(By.id("password1"));
1509 passwordField.sendKeys("123456789");
1510 assertEquals("1234", passwordField.getDomProperty("value"));
1511 passwordField.sendKeys(Keys.BACK_SPACE);
1512 passwordField.sendKeys("7");
1513 assertEquals("1237", passwordField.getDomProperty("value"));
1514 }
1515
1516
1517
1518
1519 @Test
1520 @Alerts({"text TeXt", "password PassWord", "hidden Hidden",
1521 "checkbox CheckBox", "radio rAdiO", "file FILE", "checkbox CHECKBOX"})
1522 public void typeCase() throws Exception {
1523 final String html = DOCTYPE_HTML
1524 + "<html><head><script>\n"
1525 + LOG_TITLE_FUNCTION
1526 + "function test() {\n"
1527 + " var t = document.getElementById('aText');\n"
1528 + " log(t.type + ' ' + t.getAttribute('type'));\n"
1529 + " var p = document.getElementById('aPassword');\n"
1530 + " log(p.type + ' ' + p.getAttribute('type'));\n"
1531 + " var h = document.getElementById('aHidden');\n"
1532 + " log(h.type + ' ' + h.getAttribute('type'));\n"
1533 + " var cb = document.getElementById('aCb');\n"
1534 + " log(cb.type + ' ' + cb.getAttribute('type'));\n"
1535 + " var r = document.getElementById('aRadio');\n"
1536 + " log(r.type + ' ' + r.getAttribute('type'));\n"
1537 + " var f = document.getElementById('aFile');\n"
1538 + " log(f.type + ' ' + f.getAttribute('type'));\n"
1539
1540 + " try {\n"
1541 + " f.type = 'CHECKBOX';\n"
1542 + " log(f.type + ' ' + f.getAttribute('type'));\n"
1543 + " } catch(e) { logEx(e); }\n"
1544 + "}\n"
1545 + "</script></head>\n"
1546 + "<body onload='test()'>\n"
1547 + " <form action='foo'>\n"
1548 + " <input Type='TeXt' id='aText' value='some test'>\n"
1549 + " <input tYpe='PassWord' id='aPassword' value='some test'>\n"
1550 + " <input tyPe='Hidden' id='aHidden' value='some test'>\n"
1551 + " <input typE='CheckBox' id='aCb'>\n"
1552 + " <input TYPE='rAdiO' id='aRadio'>\n"
1553 + " <input type='FILE' id='aFile'>\n"
1554 + " </form>\n"
1555 + "</body></html>";
1556
1557 loadPageVerifyTitle2(html);
1558 }
1559
1560
1561
1562
1563 @Test
1564 @Alerts({"text-text", "text- password", "text-hidden ", "text-checkbox ", "text-\\tradio"})
1565 public void typeTrim() throws Exception {
1566 final String html = DOCTYPE_HTML
1567 + "<html><head>\n"
1568 + "<script>\n"
1569 + "function log(msg) { window.document.title += msg.replace('\t', '\\\\t') + '§';}\n"
1570 + "function test() {\n"
1571 + " var t = document.getElementById('aText');\n"
1572 + " log(t.type + '-' + t.getAttribute('type'));\n"
1573 + " var p = document.getElementById('aPassword');\n"
1574 + " log(p.type + '-' + p.getAttribute('type'));\n"
1575 + " var h = document.getElementById('aHidden');\n"
1576 + " log(h.type + '-' + h.getAttribute('type'));\n"
1577 + " var cb = document.getElementById('aCb');\n"
1578 + " log(cb.type + '-' + cb.getAttribute('type'));\n"
1579 + " var r = document.getElementById('aRadio');\n"
1580 + " log(r.type + '-' + r.getAttribute('type'));\n"
1581 + "}\n"
1582 + "</script>\n"
1583 + "</head>\n"
1584 + "<body onLoad='test()'>\n"
1585 + " <form action='foo'>\n"
1586 + " <input type='text' id='aText' value='some test'>\n"
1587 + " <input type=' password' id='aPassword' value='some test'>\n"
1588 + " <input type='hidden ' id='aHidden' value='some test'>\n"
1589 + " <input type='checkbox ' id='aCb'>\n"
1590 + " <input type='\tradio' id='aRadio'>\n"
1591 + " </form>\n"
1592 + "</body></html>";
1593
1594 loadPageVerifyTitle2(html);
1595 }
1596
1597
1598
1599
1600 @Test
1601 @Alerts("true")
1602 public void readOnly() throws Exception {
1603 final String html = DOCTYPE_HTML
1604 + "<html>\n"
1605 + "<head>\n"
1606 + "<script>\n"
1607 + LOG_TITLE_FUNCTION
1608 + " function test() {\n"
1609 + " var input = document.getElementById('myInput');\n"
1610 + " log(input.readOnly);\n"
1611 + " }\n"
1612 + " </script>\n"
1613 + "</head>\n"
1614 + "<body onload='test()'>\n"
1615 + " <input id='myInput' value='some test' readonly='false'>\n"
1616 + "</body></html>";
1617
1618 loadPageVerifyTitle2(html);
1619 }
1620
1621
1622
1623
1624 @Test
1625 @Alerts({"false", "true"})
1626 public void readOnlyInputFile() throws Exception {
1627 final String html = DOCTYPE_HTML
1628 + "<html>\n"
1629 + "<head>\n"
1630 + "<script>\n"
1631 + LOG_TITLE_FUNCTION
1632 + " function test() {\n"
1633 + " var input = document.getElementById('myInput');\n"
1634 + " log(input.readOnly);\n"
1635 + " input = document.getElementById('myReadonlyInput');\n"
1636 + " log(input.readOnly);\n"
1637 + " }\n"
1638 + " </script>\n"
1639 + "</head>\n"
1640 + "<body onload='test()'>\n"
1641 + " <input id='myInput' type='file' value='some test'>\n"
1642 + " <input id='myReadonlyInput' type='file' value='some test' readonly='false'>\n"
1643 + "</body></html>";
1644
1645 loadPageVerifyTitle2(html);
1646 }
1647
1648
1649
1650
1651 @Test
1652 @Alerts({"left", "right", "bottom", "middle", "top", "wrong", ""})
1653 public void getAlign() throws Exception {
1654 final String html = DOCTYPE_HTML
1655 + "<html><body>\n"
1656 + " <form>\n"
1657 + " <input id='i1' align='left' />\n"
1658 + " <input id='i2' align='right' />\n"
1659 + " <input id='i3' align='bottom' />\n"
1660 + " <input id='i4' align='middle' />\n"
1661 + " <input id='i5' align='top' />\n"
1662 + " <input id='i6' align='wrong' />\n"
1663 + " <input id='i7' />\n"
1664 + " </form>\n"
1665
1666 + "<script>\n"
1667 + LOG_TITLE_FUNCTION
1668 + " for (var i = 1; i <= 7; i++) {\n"
1669 + " log(document.getElementById('i' + i).align);\n"
1670 + " }\n"
1671 + "</script>\n"
1672 + "</body></html>";
1673 loadPageVerifyTitle2(html);
1674 }
1675
1676
1677
1678
1679 @Test
1680 @Alerts({"CenTer", "8", "foo", "left", "right", "bottom", "middle", "top"})
1681 public void setAlign() throws Exception {
1682 final String html = DOCTYPE_HTML
1683 + "<html><body>\n"
1684 + " <form>\n"
1685 + " <input id='i1' type='text' align='left' value=''/>\n"
1686 + " </form>\n"
1687
1688 + "<script>\n"
1689 + LOG_TITLE_FUNCTION
1690 + " function setAlign(elem, value) {\n"
1691 + " try {\n"
1692 + " elem.align = value;\n"
1693 + " } catch(e) { logEx(e); }\n"
1694 + " log(elem.align);\n"
1695 + " }\n"
1696
1697 + " var elem = document.getElementById('i1');\n"
1698 + " setAlign(elem, 'CenTer');\n"
1699
1700 + " setAlign(elem, '8');\n"
1701 + " setAlign(elem, 'foo');\n"
1702
1703 + " setAlign(elem, 'left');\n"
1704 + " setAlign(elem, 'right');\n"
1705 + " setAlign(elem, 'bottom');\n"
1706 + " setAlign(elem, 'middle');\n"
1707 + " setAlign(elem, 'top');\n"
1708 + "</script>\n"
1709 + "</body></html>";
1710 loadPageVerifyTitle2(html);
1711 }
1712
1713
1714
1715
1716 @Test
1717 @Alerts({"", "A", "a", "A", "a8", "8Afoo", "8", "@"})
1718 public void accessKey() throws Exception {
1719 final String html = DOCTYPE_HTML
1720 + "<html><body>\n"
1721 + " <input id='a1'>\n"
1722 + " <input id='a2' accesskey='A'>\n"
1723 + " <script>\n"
1724 + LOG_TITLE_FUNCTION
1725 + " var a1 = document.getElementById('a1');\n"
1726 + " var a2 = document.getElementById('a2');\n"
1727 + " log(a1.accessKey);\n"
1728 + " log(a2.accessKey);\n"
1729
1730 + " a1.accessKey = 'a';\n"
1731 + " log(a1.accessKey);\n"
1732
1733 + " a1.accessKey = 'A';\n"
1734 + " log(a1.accessKey);\n"
1735
1736 + " a1.accessKey = 'a8';\n"
1737 + " log(a1.accessKey);\n"
1738
1739 + " a1.accessKey = '8Afoo';\n"
1740 + " log(a1.accessKey);\n"
1741
1742 + " a1.accessKey = '8';\n"
1743 + " log(a1.accessKey);\n"
1744
1745 + " a1.accessKey = '@';\n"
1746 + " log(a1.accessKey);\n"
1747 + "</script></body></html>";
1748 loadPageVerifyTitle2(html);
1749 }
1750
1751
1752
1753
1754 @Test
1755 @Alerts({"test", "4", "42", "2", "[object HTMLInputElement]", "25"})
1756 public void getAttributeAndSetValue() throws Exception {
1757 final String html = DOCTYPE_HTML
1758 + "<html>\n"
1759 + " <head>\n"
1760 + " <script>\n"
1761 + LOG_TITLE_FUNCTION
1762 + " function test() {\n"
1763 + " var t = document.getElementById('t');\n"
1764 + " t.value = 'test';\n"
1765 + " log(t.value);\n"
1766 + " if (t.value != null)\n"
1767 + " log(t.value.length);\n"
1768
1769 + " t.value = 42;\n"
1770 + " log(t.value);\n"
1771 + " if (t.value != null)\n"
1772 + " log(t.value.length);\n"
1773
1774 + " t.value = document.getElementById('t');\n"
1775 + " log(t.value);\n"
1776 + " if (t.value != null)\n"
1777 + " log(t.value.length);\n"
1778 + " }\n"
1779 + " </script>\n"
1780 + " </head>\n"
1781 + " <body onload='test()'>\n"
1782 + " <input id='t'>\n"
1783 + " </body>\n"
1784 + "</html>";
1785
1786 loadPageVerifyTitle2(html);
1787 }
1788
1789
1790
1791
1792 @Test
1793 @Alerts({"null", "4", "", "0"})
1794 public void getAttributeAndSetValueNull() throws Exception {
1795 final String html = DOCTYPE_HTML
1796 + "<html>\n"
1797 + " <head>\n"
1798 + " <script>\n"
1799 + LOG_TITLE_FUNCTION
1800 + " function test() {\n"
1801 + " var t = document.getElementById('t');\n"
1802 + " t.value = 'null';\n"
1803 + " log(t.value);\n"
1804 + " if (t.value != null)\n"
1805 + " log(t.value.length);\n"
1806
1807 + " t.value = null;\n"
1808 + " log(t.value);\n"
1809 + " if (t.value != null)\n"
1810 + " log(t.value.length);\n"
1811 + " }\n"
1812 + " </script>\n"
1813 + " </head>\n"
1814 + " <body onload='test()'>\n"
1815 + " <input id='t'>\n"
1816 + " </body>\n"
1817 + "</html>";
1818
1819 loadPageVerifyTitle2(html);
1820 }
1821
1822
1823
1824
1825 @Test
1826 @Alerts({"0", "0", "2", "7"})
1827 public void selectionRange() throws Exception {
1828 final String html = DOCTYPE_HTML
1829 + "<html><head><script>\n"
1830 + LOG_TITLE_FUNCTION
1831 + "function test() {\n"
1832 + " var input = document.getElementById('myInput');\n"
1833 + " log(input.selectionStart);\n"
1834 + " log(input.selectionEnd);\n"
1835
1836 + " input.setSelectionRange(2, 7);\n"
1837 + " log(input.selectionStart);\n"
1838 + " log(input.selectionEnd);\n"
1839 + "}\n"
1840 + "</script></head>\n"
1841 + "<body onload='test()'>\n"
1842 + " <input id='myInput' value='some test'>\n"
1843 + "</body></html>";
1844
1845 loadPageVerifyTitle2(html);
1846 }
1847
1848
1849
1850
1851 @Test
1852 @Alerts("onsubmit")
1853 public void submitNonRequired() throws Exception {
1854 final String html = DOCTYPE_HTML
1855 + "<html><head><script>\n"
1856 + "function submitMe() {\n"
1857 + " alert('onsubmit');\n"
1858 + "}\n"
1859 + "</script></head>\n"
1860 + "<body>\n"
1861 + " <form onsubmit='submitMe()'>\n"
1862 + " <input id='myInput' name='myName' value=''>\n"
1863 + " <input id='mySubmit' type='submit'>\n"
1864 + " </form>\n"
1865 + "</body></html>";
1866
1867 final WebDriver driver = loadPage2(html);
1868 driver.findElement(By.id("mySubmit")).click();
1869 verifyAlerts(driver, getExpectedAlerts());
1870 Thread.sleep(DEFAULT_WAIT_TIME.toMillis() / 10);
1871 assertTrue("Url '" + driver.getCurrentUrl() + "' does not contain 'myName'",
1872 driver.getCurrentUrl().contains("myName"));
1873
1874
1875 assertTrue(getCollectedAlerts(driver, 1).isEmpty());
1876 }
1877
1878
1879
1880
1881 @Test
1882 @Alerts({"1", "§§URL§§"})
1883 public void submitRequired() throws Exception {
1884 final String html = DOCTYPE_HTML
1885 + "<html><head><script>\n"
1886 + "function submitMe() {\n"
1887 + " alert('onsubmit');\n"
1888 + "}\n"
1889 + "</script></head>\n"
1890 + "<body>\n"
1891 + " <form onsubmit='submitMe()'>\n"
1892 + " <input id='myInput' name='myName' value='' required>\n"
1893 + " <input id='mySubmit' type='submit'>\n"
1894 + " </form>\n"
1895 + "</body></html>";
1896
1897 final WebDriver driver = loadPage2(html);
1898 driver.findElement(By.id("mySubmit")).click();
1899
1900 expandExpectedAlertsVariables(URL_FIRST);
1901 assertEquals(getExpectedAlerts()[0], Integer.toString(getMockWebConnection().getRequestCount()));
1902 assertEquals(getExpectedAlerts()[1], driver.getCurrentUrl());
1903 assertTrue(getCollectedAlerts(driver).isEmpty());
1904 }
1905
1906
1907
1908
1909 @Test
1910 @Alerts({"false", "true"})
1911 public void checkValidity() throws Exception {
1912 final String html = DOCTYPE_HTML
1913 + "<html><head><script>\n"
1914 + "function checkStatus() {\n"
1915 + " var elem = document.getElementById('myInput');\n"
1916 + " alert(elem.checkValidity());\n"
1917 + "}\n"
1918 + "</script></head>\n"
1919 + "<body>\n"
1920 + " <form>\n"
1921 + " <input id='myInput' name='myName' required>\n"
1922 + " <input id='mySubmit' type='submit'>\n"
1923 + " </form>\n"
1924 + " <button id='myButton' onclick='checkStatus()'>Check Status</button>\n"
1925 + "</body></html>";
1926
1927 final WebDriver driver = loadPage2(html);
1928 driver.findElement(By.id("myButton")).click();
1929 verifyAlerts(driver, getExpectedAlerts()[0]);
1930
1931 driver.findElement(By.id("myInput")).sendKeys("something");
1932 driver.findElement(By.id("myButton")).click();
1933 verifyAlerts(driver, getExpectedAlerts()[1]);
1934 }
1935
1936
1937
1938
1939 @Test
1940 @Alerts("§§URL§§?myName=abcdefg")
1941 public void maxLengthJavaScript() throws Exception {
1942 final String html = DOCTYPE_HTML
1943 + "<html><head><script>\n"
1944 + "function updateValue() {\n"
1945 + " document.getElementById('myInput').value = 'abcdefg';\n"
1946 + "}\n"
1947 + "</script></head>\n"
1948 + "<body>\n"
1949 + " <form>\n"
1950 + " <input id='myInput' name='myName' maxlength='2'>\n"
1951 + " <input id='mySubmit' type='submit'>\n"
1952 + " </form>\n"
1953 + " <button id='myButton' onclick='updateValue()'>Update Value</button>\n"
1954 + "</body></html>";
1955
1956 final WebDriver driver = loadPage2(html);
1957 driver.findElement(By.id("myButton")).click();
1958 assertEquals("abcdefg", driver.findElement(By.id("myInput")).getDomProperty("value"));
1959 driver.findElement(By.id("mySubmit")).click();
1960
1961 expandExpectedAlertsVariables(URL_FIRST);
1962 assertEquals(getExpectedAlerts()[0], driver.getCurrentUrl());
1963 }
1964
1965
1966
1967
1968 @Test
1969 @Alerts("§§URL§§?myName=ab")
1970 public void maxLength2() throws Exception {
1971 final String html = DOCTYPE_HTML
1972 + "<html><head><script>\n"
1973 + "</script></head>\n"
1974 + "<body>\n"
1975 + " <form>\n"
1976 + " <input id='myInput' name='myName' maxlength='2'>\n"
1977 + " <input id='mySubmit' type='submit'>\n"
1978 + " </form>\n"
1979 + "</body></html>";
1980
1981 final WebDriver driver = loadPage2(html);
1982 driver.findElement(By.id("myInput")).sendKeys("abcdefg");
1983 assertEquals("ab", driver.findElement(By.id("myInput")).getDomProperty("value"));
1984
1985 driver.findElement(By.id("mySubmit")).click();
1986
1987 expandExpectedAlertsVariables(URL_FIRST);
1988 assertEquals(getExpectedAlerts()[0], driver.getCurrentUrl());
1989 }
1990
1991
1992
1993
1994 @Test
1995 @Alerts({"30", "undefined", "30", "30", "40", "50", "string", "string"})
1996 public void min() throws Exception {
1997 final String html = DOCTYPE_HTML
1998 + "<html><head><script>\n"
1999 + LOG_TITLE_FUNCTION
2000 + "function doTest() {\n"
2001 + " var input = document.getElementById('text1');\n"
2002 + " log(input.min);\n"
2003 + " log(input.Min);\n"
2004 + " log(input.getAttribute('min'));\n"
2005 + " log(input.getAttribute('Min'));\n"
2006 + " input.setAttribute('MiN', 40);\n"
2007 + " log(input.min);\n"
2008 + " input.min = 50;\n"
2009 + " log(input.getAttribute('min'));\n"
2010 + " log(typeof input.getAttribute('min'));\n"
2011 + " log(typeof input.min);\n"
2012 + "}\n</script></head>\n"
2013 + "<body onload='doTest()'>\n"
2014 + "<form name='myForm' action='foo'>\n"
2015 + "<input type='text' id='text1' min='30'/>\n"
2016 + "</form></body></html>";
2017
2018 loadPageVerifyTitle2(html);
2019 }
2020
2021
2022
2023
2024 @Test
2025 @Alerts({"30", "undefined", "30", "30", "40", "50", "string", "string"})
2026 public void max() throws Exception {
2027 final String html = DOCTYPE_HTML
2028 + "<html><head><script>\n"
2029 + LOG_TITLE_FUNCTION
2030 + "function doTest() {\n"
2031 + " var input = document.getElementById('text1');\n"
2032 + " log(input.max);\n"
2033 + " log(input.Max);\n"
2034 + " log(input.getAttribute('max'));\n"
2035 + " log(input.getAttribute('Max'));\n"
2036 + " input.setAttribute('MaX', 40);\n"
2037 + " log(input.max);\n"
2038 + " input.max = 50;\n"
2039 + " log(input.getAttribute('max'));\n"
2040 + " log(typeof input.getAttribute('max'));\n"
2041 + " log(typeof input.max);\n"
2042 + "}\n</script></head>\n"
2043 + "<body onload='doTest()'>\n"
2044 + "<form name='myForm' action='foo'>\n"
2045 + "<input type='text' id='text1' max='30'/>\n"
2046 + "</form></body></html>";
2047
2048 loadPageVerifyTitle2(html);
2049 }
2050
2051
2052
2053
2054 @Test
2055 @Alerts({"0", "2", "1", "2", "1", "1"})
2056 public void labels() throws Exception {
2057 final String html = DOCTYPE_HTML
2058 + "<html><head>\n"
2059 + " <script>\n"
2060 + LOG_TITLE_FUNCTION
2061 + " function test() {\n"
2062 + " debug(document.getElementById('e1'));\n"
2063 + " debug(document.getElementById('e2'));\n"
2064 + " debug(document.getElementById('e3'));\n"
2065 + " debug(document.getElementById('e4'));\n"
2066 + " var labels = document.getElementById('e4').labels;\n"
2067 + " document.body.removeChild(document.getElementById('l4'));\n"
2068 + " debug(document.getElementById('e4'));\n"
2069 + " log(labels ? labels.length : labels);\n"
2070 + " }\n"
2071 + " function debug(e) {\n"
2072 + " log(e.labels ? e.labels.length : e.labels);\n"
2073 + " }\n"
2074 + " </script>\n"
2075 + "</head>\n"
2076 + "<body onload='test()'>\n"
2077 + " <input id='e1'><br>\n"
2078 + " <label>something <label> click here <input id='e2'></label></label><br>\n"
2079 + " <label for='e3'> and here</label>\n"
2080 + " <input id='e3'><br>\n"
2081 + " <label id='l4' for='e4'> what about</label>\n"
2082 + " <label> this<input id='e4'></label><br>\n"
2083 + "</body></html>";
2084
2085 loadPageVerifyTitle2(html);
2086 }
2087
2088
2089
2090
2091 @Test
2092 @Alerts(DEFAULT = {"173", "17", "173", "17", "13", "13", "13", "13"},
2093 FF = {"161", "18", "161", "18", "14", "14", "14", "14"},
2094 FF_ESR = {"154", "18", "154", "18", "10", "10", "10", "10"})
2095 public void defaultClientWidthHeight() throws Exception {
2096 final String html = DOCTYPE_HTML
2097 + "<html><head>\n"
2098 + "<script>\n"
2099 + LOG_TITLE_FUNCTION
2100 + " function test() {\n"
2101 + " var elem = document.getElementById('txt');\n"
2102 + " log(elem.clientWidth);\n"
2103 + " log(elem.clientHeight);\n"
2104 + " elem = document.getElementById('pw');\n"
2105 + " log(elem.clientWidth);\n"
2106 + " log(elem.clientHeight);\n"
2107 + " elem = document.getElementById('chkbx');\n"
2108 + " log(elem.clientWidth);\n"
2109 + " log(elem.clientHeight);\n"
2110 + " elem = document.getElementById('radio');\n"
2111 + " log(elem.clientWidth);\n"
2112 + " log(elem.clientHeight);\n"
2113 + " }\n"
2114 + "</script>\n"
2115 + "</head><body onload='test()'>\n"
2116 + "<form>\n"
2117 + " <input type='text' id='txt'>\n"
2118 + " <input type='password' id='pw'>\n"
2119 + " <input type='checkbox' id='chkbx'/>\n"
2120 + " <input type='radio' id='radio'/>\n"
2121 + "</form>\n"
2122 + "</body></html>";
2123 loadPageVerifyTitle2(html);
2124 }
2125
2126
2127
2128
2129 @Test
2130 @Alerts("[object HTMLFormElement]")
2131 public void form() throws Exception {
2132 final String html = DOCTYPE_HTML
2133 + "<html>\n"
2134 + "<body>\n"
2135 + " <form>\n"
2136 + " <input type='text' id='a'>\n"
2137 + " </form>"
2138 + " <script>\n"
2139 + LOG_TITLE_FUNCTION
2140 + " log(document.getElementById('a').form);\n"
2141 + " </script>"
2142 + "</body>"
2143 + "</html>";
2144 loadPageVerifyTitle2(html);
2145 }
2146
2147
2148
2149
2150 @Test
2151 @Alerts("mouse over [tester]")
2152 public void mouseOverButton() throws Exception {
2153 mouseOver("<input id='tester' type='button' onmouseover='dumpEvent(event);' value='HtmlUnit'>");
2154 }
2155
2156
2157
2158
2159 @Test
2160 @Alerts("mouse over [tester]")
2161 public void mouseOverButtonDisabled() throws Exception {
2162 mouseOver("<input id='tester' type='button' onmouseover='dumpEvent(event);' value='HtmlUnit' disabled >");
2163 }
2164
2165
2166
2167
2168 @Test
2169 @Alerts("mouse over [tester]")
2170 public void mouseOverSubmit() throws Exception {
2171 mouseOver("<input id='tester' type='submit' onmouseover='dumpEvent(event);' >");
2172 }
2173
2174
2175
2176
2177 @Test
2178 @Alerts("mouse over [tester]")
2179 public void mouseOverSubmitDisabled() throws Exception {
2180 mouseOver("<input id='tester' type='submit' onmouseover='dumpEvent(event);' disabled >");
2181 }
2182
2183
2184
2185
2186 @Test
2187 @Alerts("mouse over [tester]")
2188 public void mouseOverReset() throws Exception {
2189 mouseOver("<input id='tester' type='reset' onmouseover='dumpEvent(event);' >");
2190 }
2191
2192
2193
2194
2195 @Test
2196 @Alerts("mouse over [tester]")
2197 public void mouseOverResetDisabled() throws Exception {
2198 mouseOver("<input id='tester' type='reset' onmouseover='dumpEvent(event);' disabled >");
2199 }
2200
2201
2202
2203
2204 @Test
2205 @Alerts("mouse over [tester]")
2206 public void mouseOverText() throws Exception {
2207 mouseOver("<input id='tester' type='text' onmouseover='dumpEvent(event);' value='HtmlUnit'>");
2208 }
2209
2210
2211
2212
2213 @Test
2214 @Alerts("mouse over [tester]")
2215 public void mouseOverTextDisabled() throws Exception {
2216 mouseOver("<input id='tester' type='text' onmouseover='dumpEvent(event);' value='HtmlUnit' disabled >");
2217 }
2218
2219
2220
2221
2222 @Test
2223 @Alerts("mouse over [tester]")
2224 public void mouseOverPassword() throws Exception {
2225 mouseOver("<input id='tester' type='password' onmouseover='dumpEvent(event);' value='HtmlUnit'>");
2226 }
2227
2228
2229
2230
2231 @Test
2232 @Alerts("mouse over [tester]")
2233 public void mouseOverPasswordDisabled() throws Exception {
2234 mouseOver("<input id='tester' type='password' onmouseover='dumpEvent(event);' value='HtmlUnit' disabled >");
2235 }
2236
2237
2238
2239
2240 @Test
2241 @Alerts("mouse over [tester]")
2242 public void mouseOverFile() throws Exception {
2243 mouseOver("<input id='tester' type='file' onmouseover='dumpEvent(event);'>");
2244 }
2245
2246
2247
2248
2249 @Test
2250 @Alerts("mouse over [tester]")
2251 public void mouseOverFileDisabled() throws Exception {
2252 mouseOver("<input id='tester' type='file' onmouseover='dumpEvent(event);' disabled >");
2253 }
2254
2255
2256
2257
2258 @Test
2259 @Alerts("mouse over [tester]")
2260 public void mouseOverCheckbox() throws Exception {
2261 mouseOver("<input id='tester' type='checkbox' onmouseover='dumpEvent(event);' value='HtmlUnit'>");
2262 }
2263
2264
2265
2266
2267 @Test
2268 @Alerts("mouse over [tester]")
2269 public void mouseOverCheckboxDisabled() throws Exception {
2270 mouseOver("<input id='tester' type='checkbox' onmouseover='dumpEvent(event);' value='HtmlUnit' disabled >");
2271 }
2272
2273
2274
2275
2276 @Test
2277 @Alerts("mouse over [tester]")
2278 public void mouseOverRadio() throws Exception {
2279 mouseOver("<input id='tester' type='radio' onmouseover='dumpEvent(event);' value='HtmlUnit'>");
2280 }
2281
2282
2283
2284
2285 @Test
2286 @Alerts("mouse over [tester]")
2287 public void mouseOverRadioDisabled() throws Exception {
2288 mouseOver("<input id='tester' type='radio' onmouseover='dumpEvent(event);' value='HtmlUnit' disabled >");
2289 }
2290
2291 private void mouseOver(final String element) throws Exception {
2292 final String html = DOCTYPE_HTML
2293 + "<html>\n"
2294 + " <head>\n"
2295 + " <script>\n"
2296 + " function dumpEvent(event) {\n"
2297 + " // target\n"
2298 + " var eTarget;\n"
2299 + " if (event.target) {\n"
2300 + " eTarget = event.target;\n"
2301 + " } else if (event.srcElement) {\n"
2302 + " eTarget = event.srcElement;\n"
2303 + " }\n"
2304 + " // defeat Safari bug\n"
2305 + " if (eTarget.nodeType == 3) {\n"
2306 + " eTarget = eTarget.parentNode;\n"
2307 + " }\n"
2308 + " var msg = 'mouse over';\n"
2309 + " if (eTarget.name) {\n"
2310 + " msg = msg + ' [' + eTarget.name + ']';\n"
2311 + " } else {\n"
2312 + " msg = msg + ' [' + eTarget.id + ']';\n"
2313 + " }\n"
2314 + " document.title+= msg;\n"
2315 + " }\n"
2316 + " </script>\n"
2317 + " </head>\n"
2318 + "<body>\n"
2319 + " <form id='form1'>\n"
2320 + " " + element + "\n"
2321 + " </form>\n"
2322 + "</body></html>";
2323
2324 final WebDriver driver = loadPage2(html);
2325
2326 final Actions actions = new Actions(driver);
2327 actions.moveToElement(driver.findElement(By.id("tester")));
2328 actions.perform();
2329
2330 assertTitle(driver, getExpectedAlerts()[0]);
2331 }
2332
2333
2334
2335
2336 @Test
2337 @Alerts({"Test-Test-Test", "text1-text1-text1"})
2338 public void getAttribute() throws Exception {
2339 final String html = DOCTYPE_HTML
2340 + "<html><head><script>\n"
2341 + LOG_TITLE_FUNCTION
2342 + "function test() {\n"
2343 + " var input = document.getElementById('myInput');\n"
2344 + " log(input.value + '-' + input.defaultValue + '-' + input.getAttribute('value'));\n"
2345 + " input.setAttribute('value', 'text1');\n"
2346 + " log(input.value + '-' + input.defaultValue + '-' + input.getAttribute('value'));\n"
2347 + "}\n"
2348 + "</script></head>\n"
2349 + "<body onload='test()'>\n"
2350 + " <input id='myInput' value='Test'>\n"
2351 + "</body></html>";
2352
2353 loadPageVerifyTitle2(html);
2354 }
2355
2356
2357
2358
2359 @Test
2360 @Alerts({"Test-Test-Test", "text1-text1-text1"})
2361 public void getAttributeCase() throws Exception {
2362 final String html = DOCTYPE_HTML
2363 + "<html><head><script>\n"
2364 + LOG_TITLE_FUNCTION
2365 + "function test() {\n"
2366 + " var input = document.getElementById('myInput');\n"
2367 + " log(input.value + '-' + input.defaultValue + '-' + input.getAttribute('value'));\n"
2368 + " input.setAttribute('vALue', 'text1');\n"
2369 + " log(input.value + '-' + input.defaultValue + '-' + input.getAttribute('value'));\n"
2370 + "}\n"
2371 + "</script></head>\n"
2372 + "<body onload='test()'>\n"
2373 + " <input id='myInput' value='Test'>\n"
2374 + "</body></html>";
2375
2376 loadPageVerifyTitle2(html);
2377 }
2378
2379
2380
2381
2382 @Test
2383 @Alerts({"Test-Test-Test", "Test-Test-Test"})
2384 public void setAttribute() throws Exception {
2385 final String html = DOCTYPE_HTML
2386 + "<html><head><script>\n"
2387 + LOG_TITLE_FUNCTION
2388 + "function test() {\n"
2389 + " var input = document.getElementById('myInput');\n"
2390 + " log(input.value + '-' + input.defaultValue + '-' + input.getAttribute('value'));\n"
2391 + " input.setAttribute('autocomplete', 'text1');\n"
2392 + " log(input.value + '-' + input.defaultValue + '-' + input.getAttribute('value'));\n"
2393 + "}\n"
2394 + "</script></head>\n"
2395 + "<body onload='test()'>\n"
2396 + " <input id='myInput' value='Test'>\n"
2397 + "</body></html>";
2398
2399 loadPageVerifyTitle2(html);
2400 }
2401
2402
2403
2404
2405 @Test
2406 @Alerts("finish")
2407 public void setAttributeFromJavaScript() throws Exception {
2408 final String html = DOCTYPE_HTML
2409 + "<html><head><script>\n"
2410 + LOG_TITLE_FUNCTION
2411 + "function test() {\n"
2412 + " var input = document.getElementById('myInput');\n"
2413 + " input.setAttribute('value', 'text1');\n"
2414 + " log('finish');\n"
2415 + "}\n"
2416 + "</script></head>\n"
2417 + "<body onload='test()'>\n"
2418 + " <input id='myInput' value='Test' onchange=\"log('changed')\">\n"
2419 + "</body></html>";
2420
2421 loadPageVerifyTitle2(html);
2422 }
2423
2424
2425
2426
2427 @Test
2428 public void sendKeys() throws Exception {
2429 final String html = DOCTYPE_HTML
2430 + "<html><head></head>\n"
2431 + "<body>\n"
2432 + " <input id='myInput' value='Test' onchange=\"alert('changed')\">\n"
2433 + "</body></html>";
2434
2435 final WebDriver driver = loadPage2(html);
2436 final WebElement element = driver.findElement(By.id("myInput"));
2437 element.sendKeys("abc");
2438 verifyAlerts(driver);
2439 }
2440
2441
2442
2443
2444 @Test
2445 public void clear() throws Exception {
2446 final String html = DOCTYPE_HTML
2447 + "<html><head><script>\n"
2448 + LOG_TITLE_FUNCTION
2449 + "</script></head>\n"
2450 + "<body>\n"
2451 + " <input id='myInput' value='Test' onchange=\"log('changed')\">\n"
2452 + "</body></html>";
2453
2454 final WebDriver driver = loadPage2(html);
2455 final WebElement element = driver.findElement(By.id("myInput"));
2456 element.clear();
2457 verifyTitle2(driver, "changed");
2458 }
2459
2460
2461
2462
2463 @Test
2464 @Alerts({"true", "false", "true", "false", "true"})
2465 public void willValidate() throws Exception {
2466 final String html = DOCTYPE_HTML
2467 + "<html><head>\n"
2468 + " <script>\n"
2469 + LOG_TITLE_FUNCTION
2470 + " function test() {\n"
2471 + " log(document.getElementById('i1').willValidate);\n"
2472 + " log(document.getElementById('i2').willValidate);\n"
2473 + " log(document.getElementById('i3').willValidate);\n"
2474 + " log(document.getElementById('i4').willValidate);\n"
2475 + " log(document.getElementById('i5').willValidate);\n"
2476 + " }\n"
2477 + " </script>\n"
2478 + "</head>\n"
2479 + "<body onload='test()'>\n"
2480 + " <form>\n"
2481 + " <input id='i1'>\n"
2482 + " <input id='i2' disabled>\n"
2483 + " <input id='i3' hidden>\n"
2484 + " <input id='i4' readonly>\n"
2485 + " <input id='i5' style='display: none'>\n"
2486 + " </form>\n"
2487 + "</body></html>";
2488
2489 loadPageVerifyTitle2(html);
2490 }
2491
2492
2493
2494
2495 @Test
2496 @Alerts("true")
2497 public void willValidateFormNoValidate() throws Exception {
2498 final String html = DOCTYPE_HTML
2499 + "<html><head>\n"
2500 + " <script>\n"
2501 + LOG_TITLE_FUNCTION
2502 + " function test() {\n"
2503 + " log(document.getElementById('i1').willValidate);\n"
2504 + " }\n"
2505 + " </script>\n"
2506 + "</head>\n"
2507 + "<body onload='test()'>\n"
2508 + " <form novalidate>\n"
2509 + " <input id='i1'>\n"
2510 + " </form>\n"
2511 + "</body></html>";
2512
2513 loadPageVerifyTitle2(html);
2514 }
2515
2516
2517
2518
2519 @Test
2520 @Alerts({"false", "false", "true", "false"})
2521 public void formNoValidate() throws Exception {
2522 final String html = DOCTYPE_HTML
2523 + "<html><head>\n"
2524 + "<script>\n"
2525 + LOG_TITLE_FUNCTION
2526 + " function test() {\n"
2527 + " var i = document.createElement('input');\n"
2528 + " log(i.formNoValidate);\n"
2529
2530 + " i.formNoValidate = '';\n"
2531 + " log(i.formNoValidate);\n"
2532
2533 + " i.formNoValidate = 'yes';\n"
2534 + " log(i.formNoValidate);\n"
2535
2536 + " i.removeAttribute('formNoValidate');\n"
2537 + " log(i.formNoValidate);\n"
2538 + " }\n"
2539 + "</script></head><body onload='test()'>\n"
2540 + "</body></html>";
2541
2542 loadPageVerifyTitle2(html);
2543 }
2544 }