Skip to content

Commit 378e7da

Browse files
committed
Replace the deprecated WebElement.getAttribute(String) with getDomAttribute(String) and getDomProperty(String) at many places in the test suite
1 parent 8d49d46 commit 378e7da

File tree

6 files changed

+102
-124
lines changed

6 files changed

+102
-124
lines changed

src/test/java/org/htmlunit/html/HtmlResetInput2Test.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,19 @@ public void reset() throws Exception {
258258
final WebDriver webDriver = loadPage2(html);
259259

260260
final WebElement textfield = webDriver.findElement(By.id("textfield"));
261-
assertEquals(getExpectedAlerts()[0], textfield.getAttribute("value"));
261+
262+
assertEquals(getExpectedAlerts()[0], textfield.getDomAttribute("value"));
263+
assertEquals(getExpectedAlerts()[0], textfield.getDomProperty("value"));
264+
262265
textfield.sendKeys("newValue");
263-
assertEquals(getExpectedAlerts()[1], textfield.getAttribute("value"));
266+
assertEquals(getExpectedAlerts()[0], textfield.getDomAttribute("value"));
267+
assertEquals(getExpectedAlerts()[1], textfield.getDomProperty("value"));
264268

265269
final WebElement reset = webDriver.findElement(By.name("resetBtn"));
266270
reset.click();
267-
assertEquals(getExpectedAlerts()[2], textfield.getAttribute("value"));
271+
272+
assertEquals(getExpectedAlerts()[0], textfield.getDomAttribute("value"));
273+
assertEquals(getExpectedAlerts()[2], textfield.getDomProperty("value"));
268274
}
269275

270276
/**
@@ -291,13 +297,17 @@ public void onclickDisables() throws Exception {
291297
final WebDriver webDriver = loadPage2(html);
292298

293299
final WebElement textfield = webDriver.findElement(By.id("textfield"));
294-
assertEquals(getExpectedAlerts()[0], textfield.getAttribute("value"));
300+
assertEquals(getExpectedAlerts()[0], textfield.getDomAttribute("value"));
301+
assertEquals(getExpectedAlerts()[0], textfield.getDomProperty("value"));
302+
295303
textfield.sendKeys("newValue");
296-
assertEquals(getExpectedAlerts()[1], textfield.getAttribute("value"));
304+
assertEquals(getExpectedAlerts()[0], textfield.getDomAttribute("value"));
305+
assertEquals(getExpectedAlerts()[1], textfield.getDomProperty("value"));
297306

298307
final WebElement reset = webDriver.findElement(By.name("resetBtn"));
299308
reset.click();
300-
assertEquals(getExpectedAlerts()[2], textfield.getAttribute("value"));
309+
assertEquals(getExpectedAlerts()[0], textfield.getDomAttribute("value"));
310+
assertEquals(getExpectedAlerts()[2], textfield.getDomProperty("value"));
301311
}
302312

303313
/**

src/test/java/org/htmlunit/javascript/host/dom/DocumentTest.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,25 +2581,24 @@ public void createStyleSheet() throws Exception {
25812581
* @throws Exception if the test fails
25822582
*/
25832583
@Test
2584-
@Alerts("#document-fragment_null_11_null_0_")
2584+
@Alerts({"#document-fragment", "null", "11", "null", "0"})
25852585
public void createDocumentFragment() throws Exception {
2586-
final String html = "<html><head><title>foo</title><script>\n"
2586+
final String html = "<html><head>\n"
2587+
+ "<title>foo</title><script>\n"
2588+
+ LOG_TEXTAREA_FUNCTION
25872589
+ " function test() {\n"
25882590
+ " var fragment = document.createDocumentFragment();\n"
2589-
+ " var textarea = document.getElementById('myTextarea');\n"
2590-
+ " textarea.value += fragment.nodeName + '_';\n"
2591-
+ " textarea.value += fragment.nodeValue + '_';\n"
2592-
+ " textarea.value += fragment.nodeType + '_';\n"
2593-
+ " textarea.value += fragment.parentNode + '_';\n"
2594-
+ " textarea.value += fragment.childNodes.length + '_';\n"
2591+
+ " log(fragment.nodeName);\n"
2592+
+ " log(fragment.nodeValue);\n"
2593+
+ " log(fragment.nodeType);\n"
2594+
+ " log(fragment.parentNode);\n"
2595+
+ " log(fragment.childNodes.length);\n"
25952596
+ " }\n"
25962597
+ "</script></head><body onload='test()'>\n"
2597-
+ "<textarea id='myTextarea' cols='40'></textarea>\n"
2598+
+ LOG_TEXTAREA
25982599
+ "</body></html>";
25992600

2600-
final WebDriver driver = loadPage2(html);
2601-
final String expected = getExpectedAlerts()[0];
2602-
assertEquals(expected, driver.findElement(By.id("myTextarea")).getAttribute("value"));
2601+
loadPageVerifyTextArea2(html);
26032602
}
26042603

26052604
/**

src/test/java/org/htmlunit/javascript/host/dom/EventNodeTest.java

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,15 @@ public void fireEvent_initFromTemplate() throws Exception {
8787
* @throws Exception if the test fails
8888
*/
8989
@Test
90-
@Alerts("mousedown span,mouseup span,click span,mousedown text,focus text,mouseup text,"
91-
+ "click text,mousedown image,focus image,mouseup image,click image,mousedown textarea,focus textarea,"
92-
+ "mouseup textarea,click textarea,")
90+
@Alerts({"mousedown span", "mouseup span", "click span",
91+
"mousedown text", "focus text", "mouseup text", "click text",
92+
"mousedown image", "focus image", "mouseup image", "click image",
93+
"mousedown textarea", "focus textarea", "mouseup textarea", "click textarea"})
9394
public void clickEvents() throws Exception {
9495
final String html = "<html>\n"
9596
+ "<head>\n"
9697
+ " <script>\n"
97-
+ " function log(text) {\n"
98-
+ " var textarea = document.getElementById('myTextarea');\n"
99-
+ " textarea.value += text + ',';\n"
100-
+ " }\n"
98+
+ LOG_TEXTAREA_FUNCTION
10199
+ " </script>\n"
102100
+ "</head><body>\n"
103101
+ " <span id='testSpan' onfocus=\"log('will not be triggered')\" onmousedown=\"log('mousedown span')\""
@@ -112,31 +110,28 @@ public void clickEvents() throws Exception {
112110
+ " onmousedown=\"log('mousedown textarea')\" onclick=\"log('click textarea')\""
113111
+ " onmouseup=\"log('mouseup textarea')\" onfocus=\"log('focus textarea')\"></textarea>\n"
114112
+ " </form>\n"
115-
+ " <textarea id='myTextarea' cols='80' rows='10'></textarea>\n"
113+
+ LOG_TEXTAREA
116114
+ "</body></html>";
117115

118116
final WebDriver driver = loadPage2(html);
119117
driver.findElement(By.id("testSpan")).click();
120118
driver.findElement(By.id("testInput")).click();
121119
driver.findElement(By.id("testImage")).click();
122120
driver.findElement(By.id("testTextarea")).click();
123-
final String expected = getExpectedAlerts()[0];
124-
assertEquals(expected, driver.findElement(By.id("myTextarea")).getAttribute("value"));
121+
122+
verifyTextArea2(driver, getExpectedAlerts());
125123
}
126124

127125
/**
128126
* @throws Exception if the test fails
129127
*/
130128
@Test
131-
@Alerts("mousedown label,mouseup label,click label,focus text,click text,")
129+
@Alerts({"mousedown label", "mouseup label", "click label", "focus text", "click text"})
132130
public void clickEventsLabel() throws Exception {
133131
final String html = "<html>\n"
134132
+ "<head>\n"
135133
+ " <script>\n"
136-
+ " function log(text) {\n"
137-
+ " var textarea = document.getElementById('myTextarea');\n"
138-
+ " textarea.value += text + ',';\n"
139-
+ " }\n"
134+
+ LOG_TEXTAREA_FUNCTION
140135
+ " </script>\n"
141136
+ "</head><body>\n"
142137
+ " <label id='testLabel' for='testInput'"
@@ -146,37 +141,34 @@ public void clickEventsLabel() throws Exception {
146141
+ " <input type='text' id='testInput' onmousedown=\"log('mousedown text')\""
147142
+ " onclick=\"log('click text')\" onmouseup=\"log('mouseup text')\" onfocus=\"log('focus text')\">\n"
148143
+ " </form>\n"
149-
+ " <textarea id='myTextarea' cols='80' rows='10'></textarea>\n"
144+
+ LOG_TEXTAREA
150145
+ "</body></html>";
151146

152147
final WebDriver driver = loadPage2(html);
153148
driver.findElement(By.id("testLabel")).click();
154149

155-
final String expected = getExpectedAlerts()[0];
156-
assertEquals(expected, driver.findElement(By.id("myTextarea")).getAttribute("value"));
150+
verifyTextArea2(driver, getExpectedAlerts());
157151
}
158152

159153
/**
160154
* Test event order.
161155
* @throws Exception if the test fails
162156
*/
163157
@Test
158+
@Alerts({"focus", "keydown", "keypress", "keyup", "change", "blur"})
164159
public void eventOrder() throws Exception {
165160
final String html = "<html>\n"
166161
+ "<head>\n"
167162
+ " <script>\n"
168-
+ " function log(text) {\n"
169-
+ " var textarea = document.getElementById('myTextarea');\n"
170-
+ " textarea.value += text + ',';\n"
171-
+ " }\n"
163+
+ LOG_TEXTAREA_FUNCTION
172164
+ " </script>\n"
173165
+ "</head><body>\n"
174166
+ "<form>\n"
175167
+ " <input name='foo' id='foo' onfocus=\"log('focus')\" onblur=\"log('blur')\" onchange=\"log('change')\""
176168
+ " onkeydown=\"log('keydown')\" onkeypress=\"log('keypress')\" onkeyup=\"log('keyup')\">\n"
177169
+ " <input name='other' id='other'>\n"
178170
+ "</form>\n"
179-
+ " <textarea id='myTextarea' cols='80'></textarea>\n"
171+
+ LOG_TEXTAREA
180172
+ "</body></html>";
181173

182174
final WebDriver webDriver = loadPage2(html);
@@ -185,7 +177,6 @@ public void eventOrder() throws Exception {
185177
textField.sendKeys("a");
186178
webDriver.findElement(By.id("other")).click();
187179

188-
final String expected = "focus,keydown,keypress,keyup,change,blur,";
189-
assertEquals(expected, webDriver.findElement(By.id("myTextarea")).getAttribute("value"));
180+
verifyTextArea2(webDriver, getExpectedAlerts());
190181
}
191182
}

src/test/java/org/htmlunit/javascript/host/dom/MutationObserverTest.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -394,18 +394,20 @@ public void attributeValueAddRemove() throws Exception {
394394
*/
395395
@Test
396396
@Alerts("[object HTMLHeadingElement]-attributes")
397-
@BuggyWebDriver(FF = "[object HTMLInputElement]-attributes\n"
398-
+ "[object HTMLInputElement]-attributes\n"
399-
+ "[object HTMLInputElement]-attributes\n"
400-
+ "[object HTMLInputElement]-attributes\n"
401-
+ "[object HTMLHeadingElement]-attributes",
402-
FF_ESR = "[object HTMLInputElement]-attributes\n"
403-
+ "[object HTMLInputElement]-attributes\n"
404-
+ "[object HTMLInputElement]-attributes\n"
405-
+ "[object HTMLInputElement]-attributes\n"
406-
+ "[object HTMLHeadingElement]-attributes")
397+
@BuggyWebDriver(
398+
FF = {"[object HTMLInputElement]-attributesn",
399+
"[object HTMLInputElement]-attributes",
400+
"[object HTMLInputElement]-attributes",
401+
"[object HTMLInputElement]-attributes",
402+
"[object HTMLHeadingElement]-attributes"},
403+
FF_ESR = {"[object HTMLInputElement]-attributes",
404+
"[object HTMLInputElement]-attributes",
405+
"[object HTMLInputElement]-attributes",
406+
"[object HTMLInputElement]-attributes",
407+
"[object HTMLHeadingElement]-attributes"})
407408
public void attributeValue2() throws Exception {
408409
final String html = "<html><head><script>\n"
410+
+ LOG_TEXTAREA_FUNCTION
409411
+ " function makeRed() {\n"
410412
+ " document.getElementById('headline').setAttribute('style', 'color: red');\n"
411413
+ " }\n"
@@ -414,10 +416,6 @@ public void attributeValue2() throws Exception {
414416
+ " log(mutation.target + '-' + mutation.type);\n"
415417
+ " }\n"
416418

417-
+ " function log(x) {\n"
418-
+ " document.getElementById('log').value += x + '\\n';\n"
419-
+ " }\n"
420-
421419
+ " function test() {\n"
422420
+ " var mobs = new MutationObserver(function(mutations) {\n"
423421
+ " mutations.forEach(print)\n"
@@ -439,13 +437,12 @@ public void attributeValue2() throws Exception {
439437
+ " <h1 id='headline' style='font-style: italic'>Some headline</h1>\n"
440438
+ " <input id='id1' type='button' onclick='makeRed()' value='Make Red'>\n"
441439
+ " </div>\n"
442-
+ " <textarea id='log' cols='80' rows='40'></textarea>\n"
440+
+ LOG_TEXTAREA
443441
+ "</body></html>\n";
444442
final WebDriver driver = loadPage2(html);
445443
driver.findElement(By.id("id1")).click();
446444

447-
final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", "");
448-
assertEquals(String.join("\n", getExpectedAlerts()), text);
445+
verifyTextArea2(driver, getExpectedAlerts());
449446
}
450447

451448
/**

0 commit comments

Comments
 (0)