Skip to content

Commit de0bb07

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

File tree

9 files changed

+97
-159
lines changed

9 files changed

+97
-159
lines changed

src/test/java/org/htmlunit/javascript/host/WebSocketTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ public void events() throws Exception {
469469
do {
470470
Thread.sleep(100);
471471

472-
text = logElement.getAttribute("value").trim().replaceAll("\r", "");
472+
text = logElement.getDomProperty("value").trim().replaceAll("\r", "");
473473
}
474474
while (text.length() <= expected.length() && System.currentTimeMillis() < maxWait);
475475

@@ -541,7 +541,7 @@ public void wasClean() throws Exception {
541541
do {
542542
Thread.sleep(100);
543543

544-
text = logElement.getAttribute("value").trim().replaceAll("\r", "");
544+
text = logElement.getDomProperty("value").trim().replaceAll("\r", "");
545545
}
546546
while (text.length() <= expected.length() && System.currentTimeMillis() < maxWait);
547547

@@ -571,7 +571,7 @@ public void eventsNoSocketServer() throws Exception {
571571
do {
572572
Thread.sleep(DEFAULT_WAIT_TIME);
573573

574-
text = logElement.getAttribute("value").trim().replaceAll("\r", "");
574+
text = logElement.getDomProperty("value").trim().replaceAll("\r", "");
575575
}
576576
while (text.length() > 0 && counter++ < 10);
577577

src/test/java/org/htmlunit/javascript/host/html/HTMLDocumentTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2674,7 +2674,7 @@ public void readyState() throws Exception {
26742674
Thread.sleep(200);
26752675

26762676
final List<String> actual = new LinkedList<>();
2677-
actual.add(driver.findElement(By.id("myTextarea")).getAttribute("value"));
2677+
actual.add(driver.findElement(By.id("myTextarea")).getDomProperty("value"));
26782678

26792679
assertEquals(getExpectedAlerts(), actual);
26802680
}
@@ -3171,7 +3171,7 @@ public void lastModified_format() throws Exception {
31713171
+ "<input id='i'></input></body></html>";
31723172

31733173
final WebDriver driver = loadPageWithAlerts2(html);
3174-
final String lastModified = driver.findElement(By.id("i")).getAttribute("value");
3174+
final String lastModified = driver.findElement(By.id("i")).getDomProperty("value");
31753175

31763176
try {
31773177
new SimpleDateFormat("MM/dd/yyyy HH:mm:ss", Locale.ROOT).parse(lastModified);

src/test/java/org/htmlunit/javascript/host/html/HTMLElement2Test.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,11 +1375,9 @@ private void events(final String type) throws Exception {
13751375
+ "<div id='div' on" + type + "='log(\"div handler\")'>\n"
13761376
+ "<input id='input' on" + type + "='log(\"input handler\")'>\n"
13771377
+ "</div>\n"
1378-
+ "<textarea id='log'></textarea>\n"
1378+
+ LOG_TEXTAREA
13791379
+ "<script>\n"
1380-
+ "function log(x) {\n"
1381-
+ " document.getElementById('log').value += x + '\\n';\n"
1382-
+ "}\n"
1380+
+ LOG_TEXTAREA_FUNCTION
13831381
+ "function addListener(id, event) {\n"
13841382
+ " var handler = function(e) { log(event + ' ' + id) };\n"
13851383
+ " var e = document.getElementById(id);\n"
@@ -1393,10 +1391,9 @@ private void events(final String type) throws Exception {
13931391

13941392
final WebDriver driver = loadPage2(html);
13951393
driver.findElement(By.id("input")).click();
1396-
final WebElement log = driver.findElement(By.id("log"));
1394+
final WebElement log = driver.findElement(By.id("myLog"));
13971395
log.click();
1398-
final String text = log.getAttribute("value").trim().replaceAll("\r", "");
1399-
assertEquals(String.join("\n", getExpectedAlerts()), text);
1396+
verifyTextArea2(driver, getExpectedAlerts());
14001397
}
14011398

14021399
/**
@@ -1645,9 +1642,7 @@ public void getSetInnerHTMLComplex() throws Exception {
16451642
final String html = "<html>\n"
16461643
+ "<head>\n"
16471644
+ " <script>\n"
1648-
+ " function log(x) {\n"
1649-
+ " document.getElementById('log').value += x + '\\n';\n"
1650-
+ " }\n"
1645+
+ LOG_TEXTAREA_FUNCTION
16511646
+ " function doTest() {\n"
16521647
+ " var myNode = document.getElementById('myNode');\n"
16531648
+ " log('Old = ' + myNode.innerHTML);\n"
@@ -1659,14 +1654,11 @@ public void getSetInnerHTMLComplex() throws Exception {
16591654
+ "</head>\n"
16601655
+ "<body onload='doTest()'>\n"
16611656
+ " <p id='myNode'><b>Old innerHTML</b><!-- old comment --></p>\n"
1662-
+ " <textarea id='log'></textarea>\n"
1657+
+ LOG_TEXTAREA
16631658
+ "</body>\n"
16641659
+ "</html>";
16651660

1666-
final WebDriver driver = loadPage2(html);
1667-
final WebElement log = driver.findElement(By.id("log"));
1668-
final String text = log.getAttribute("value").trim().replaceAll("\r", "");
1669-
assertEquals(String.join("\n", getExpectedAlerts()), text);
1661+
final WebDriver driver = loadPageVerifyTextArea2(html);
16701662

16711663
final WebElement pElt = driver.findElement(By.id("myNode"));
16721664
assertEquals("p", pElt.getTagName());

src/test/java/org/htmlunit/javascript/host/html/HTMLIFrameElement2Test.java

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -944,10 +944,7 @@ public void removeSourceAttribute() throws Exception {
944944
final String html =
945945
"<html>\n"
946946
+ "<head><script>\n"
947-
+ " function log(msg) {\n"
948-
+ " var ta = document.getElementById('myTextArea');\n"
949-
+ " ta.value += msg + '; ';\n"
950-
+ " }\n"
947+
+ LOG_TEXTAREA_FUNCTION
951948

952949
+ " function test() {\n"
953950
+ " var myFrame = document.getElementById('i');\n"
@@ -967,7 +964,7 @@ public void removeSourceAttribute() throws Exception {
967964
+ " <body>\n"
968965
+ " <iframe id='i' onload='log(\"loaded\");' src='" + URL_SECOND + "'></iframe>\n"
969966

970-
+ " <textarea id='myTextArea' cols='80' rows='30'></textarea>\n"
967+
+ LOG_TEXTAREA
971968
+ " <button id='clickMe' onclick='test()'>Click Me</button>\n"
972969
+ " <button id='clickMe2' onclick='test2()'>Click Me</button>\n"
973970
+ " </body>\n"
@@ -981,8 +978,7 @@ public void removeSourceAttribute() throws Exception {
981978
driver.findElement(By.id("clickMe2")).click();
982979

983980
expandExpectedAlertsVariables(URL_SECOND);
984-
final WebElement textArea = driver.findElement(By.id("myTextArea"));
985-
assertEquals(String.join("; ", getExpectedAlerts()) + "; ", textArea.getAttribute("value"));
981+
verifyTextArea2(driver, getExpectedAlerts());
986982
}
987983

988984
/**
@@ -996,10 +992,7 @@ public void detach() throws Exception {
996992
final String html =
997993
"<html>\n"
998994
+ "<head><script>\n"
999-
+ " function log(msg) {\n"
1000-
+ " var ta = document.getElementById('myTextArea');\n"
1001-
+ " ta.value += msg + '; ';\n"
1002-
+ " }\n"
995+
+ LOG_TEXTAREA_FUNCTION
1003996

1004997
+ " function test() {\n"
1005998
+ " var myFrame = document.getElementById('i');\n"
@@ -1023,7 +1016,7 @@ public void detach() throws Exception {
10231016
+ " <body>\n"
10241017
+ " <iframe id='i' onload='log(\"loaded\");' src='" + URL_SECOND + "'></iframe>\n"
10251018

1026-
+ " <textarea id='myTextArea' cols='80' rows='30'></textarea>\n"
1019+
+ LOG_TEXTAREA
10271020
+ " <button id='clickMe' onclick='test()'>Click Me</button>\n"
10281021
+ " </body>\n"
10291022
+ "</html>";
@@ -1036,8 +1029,7 @@ public void detach() throws Exception {
10361029
Thread.sleep(200);
10371030

10381031
expandExpectedAlertsVariables(URL_SECOND);
1039-
final WebElement textArea = driver.findElement(By.id("myTextArea"));
1040-
assertEquals(String.join("; ", getExpectedAlerts()) + "; ", textArea.getAttribute("value"));
1032+
verifyTextArea2(driver, getExpectedAlerts());
10411033
}
10421034

10431035
/**
@@ -1058,10 +1050,7 @@ public void detachAppend() throws Exception {
10581050
final String html =
10591051
"<html>\n"
10601052
+ "<head><script>\n"
1061-
+ " function log(msg) {\n"
1062-
+ " var ta = document.getElementById('myTextArea');\n"
1063-
+ " ta.value += msg + '; ';\n"
1064-
+ " }\n"
1053+
+ LOG_TEXTAREA_FUNCTION
10651054

10661055
+ " function test() {\n"
10671056
+ " var myFrame = document.getElementById('i');\n"
@@ -1079,7 +1068,7 @@ public void detachAppend() throws Exception {
10791068
+ " <body>\n"
10801069
+ " <iframe id='i' onload='log(\"loaded\");' src='" + URL_SECOND + "'></iframe>\n"
10811070

1082-
+ " <textarea id='myTextArea' cols='80' rows='30'></textarea>\n"
1071+
+ LOG_TEXTAREA
10831072
+ " <button id='clickMe' onclick='test()'>Click Me</button>\n"
10841073
+ " </body>\n"
10851074
+ "</html>";
@@ -1097,8 +1086,7 @@ public void detachAppend() throws Exception {
10971086
assertEquals(1, getMockWebConnection().getRequestCount() - start);
10981087

10991088
expandExpectedAlertsVariables(URL_SECOND);
1100-
final WebElement textArea = driver.findElement(By.id("myTextArea"));
1101-
assertEquals(String.join("; ", getExpectedAlerts()) + "; ", textArea.getAttribute("value"));
1089+
verifyTextArea2(driver, getExpectedAlerts());
11021090
}
11031091

11041092
/**
@@ -1119,10 +1107,7 @@ public void detachAppendExternalScript() throws Exception {
11191107
final String html =
11201108
"<html>\n"
11211109
+ "<head><script>\n"
1122-
+ " function log(msg) {\n"
1123-
+ " var ta = document.getElementById('myTextArea');\n"
1124-
+ " ta.value += msg + '; ';\n"
1125-
+ " }\n"
1110+
+ LOG_TEXTAREA_FUNCTION
11261111

11271112
+ " function test() {\n"
11281113
+ " var myFrame = document.getElementById('i');\n"
@@ -1140,7 +1125,7 @@ public void detachAppendExternalScript() throws Exception {
11401125
+ " <body>\n"
11411126
+ " <iframe id='i' onload='log(\"loaded\");' src='" + URL_SECOND + "'></iframe>\n"
11421127

1143-
+ " <textarea id='myTextArea' cols='80' rows='30'></textarea>\n"
1128+
+ LOG_TEXTAREA
11441129
+ " <button id='clickMe' onclick='test()'>Click Me</button>\n"
11451130
+ " </body>\n"
11461131
+ "</html>";
@@ -1161,7 +1146,6 @@ public void detachAppendExternalScript() throws Exception {
11611146
assertEquals(2, getMockWebConnection().getRequestCount() - start);
11621147

11631148
expandExpectedAlertsVariables(URL_SECOND);
1164-
final WebElement textArea = driver.findElement(By.id("myTextArea"));
1165-
assertEquals(String.join("; ", getExpectedAlerts()) + "; ", textArea.getAttribute("value"));
1149+
verifyTextArea2(driver, getExpectedAlerts());
11661150
}
11671151
}

src/test/java/org/htmlunit/javascript/host/html/HTMLInputElementTest.java

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,13 +1034,9 @@ public void thisDotFormInOnClick() throws Exception {
10341034
+ "</body></html>";
10351035

10361036
final WebDriver driver = loadPageVerifyTitle2(html);
1037-
1038-
// HtmlUnitDriver is buggy, it returns null here
1039-
// assertEquals("", driver.findElement(By.name("form1")).getAttribute("target"));
1040-
10411037
driver.findElement(By.id("clickMe")).click();
10421038

1043-
assertEquals("_blank", driver.findElement(By.name("form1")).getAttribute("target"));
1039+
assertEquals("_blank", driver.findElement(By.name("form1")).getDomProperty("target"));
10441040
}
10451041

10461042
/**
@@ -1129,7 +1125,7 @@ public void onChange() throws Exception {
11291125
button.click();
11301126
assertTitle(driver, getExpectedAlerts()[0]);
11311127
Thread.sleep(100);
1132-
assertEquals(getExpectedAlerts()[1], textinput.getAttribute("value"));
1128+
assertEquals(getExpectedAlerts()[1], textinput.getDomProperty("value"));
11331129
}
11341130

11351131
/**
@@ -1161,7 +1157,7 @@ public void onChangeSetByJavaScript() throws Exception {
11611157
assertTitle(driver, getExpectedAlerts()[0]);
11621158

11631159
Thread.sleep(100);
1164-
assertEquals(getExpectedAlerts()[1], textinput.getAttribute("value"));
1160+
assertEquals(getExpectedAlerts()[1], textinput.getDomProperty("value"));
11651161
}
11661162

11671163
/**
@@ -1477,17 +1473,17 @@ public void typeMaxLength() throws Exception {
14771473
final WebDriver webDriver = loadPage2(html);
14781474
final WebElement textField = webDriver.findElement(By.id("text1"));
14791475
textField.sendKeys("123456789");
1480-
assertEquals("12345", textField.getAttribute("value"));
1476+
assertEquals("12345", textField.getDomProperty("value"));
14811477
textField.sendKeys(Keys.BACK_SPACE);
14821478
textField.sendKeys("7");
1483-
assertEquals("12347", textField.getAttribute("value"));
1479+
assertEquals("12347", textField.getDomProperty("value"));
14841480

14851481
final WebElement passwordField = webDriver.findElement(By.id("password1"));
14861482
passwordField.sendKeys("123456789");
1487-
assertEquals("123456", passwordField.getAttribute("value"));
1483+
assertEquals("123456", passwordField.getDomProperty("value"));
14881484
passwordField.sendKeys(Keys.BACK_SPACE);
14891485
passwordField.sendKeys("7");
1490-
assertEquals("123457", passwordField.getAttribute("value"));
1486+
assertEquals("123457", passwordField.getDomProperty("value"));
14911487
}
14921488

14931489
/**
@@ -1506,15 +1502,15 @@ public void typeMaxLengthZero() throws Exception {
15061502
final WebDriver webDriver = loadPage2(html);
15071503
final WebElement textField = webDriver.findElement(By.id("text1"));
15081504
textField.sendKeys("123456789");
1509-
assertEquals("", textField.getAttribute("value"));
1505+
assertEquals("", textField.getDomProperty("value"));
15101506
textField.sendKeys("\b7");
1511-
assertEquals("", textField.getAttribute("value"));
1507+
assertEquals("", textField.getDomProperty("value"));
15121508

15131509
final WebElement passwordField = webDriver.findElement(By.id("password1"));
15141510
passwordField.sendKeys("123456789");
1515-
assertEquals("", passwordField.getAttribute("value"));
1511+
assertEquals("", passwordField.getDomProperty("value"));
15161512
passwordField.sendKeys("\b7");
1517-
assertEquals("", passwordField.getAttribute("value"));
1513+
assertEquals("", passwordField.getDomProperty("value"));
15181514
}
15191515

15201516
/**
@@ -1533,17 +1529,17 @@ public void typeMaxLengthAndBlanks() throws Exception {
15331529
final WebDriver webDriver = loadPage2(html);
15341530
final WebElement textField = webDriver.findElement(By.id("text1"));
15351531
textField.sendKeys("123456789");
1536-
assertEquals("12", textField.getAttribute("value"));
1532+
assertEquals("12", textField.getDomProperty("value"));
15371533
textField.sendKeys(Keys.BACK_SPACE);
15381534
textField.sendKeys("7");
1539-
assertEquals("17", textField.getAttribute("value"));
1535+
assertEquals("17", textField.getDomProperty("value"));
15401536

15411537
final WebElement passwordField = webDriver.findElement(By.id("password1"));
15421538
passwordField.sendKeys("123456789");
1543-
assertEquals("1234", passwordField.getAttribute("value"));
1539+
assertEquals("1234", passwordField.getDomProperty("value"));
15441540
passwordField.sendKeys(Keys.BACK_SPACE);
15451541
passwordField.sendKeys("7");
1546-
assertEquals("1237", passwordField.getAttribute("value"));
1542+
assertEquals("1237", passwordField.getDomProperty("value"));
15471543
}
15481544

15491545
/**
@@ -2001,7 +1997,7 @@ public void maxLengthJavaScript() throws Exception {
20011997

20021998
final WebDriver driver = loadPage2(html);
20031999
driver.findElement(By.id("myButton")).click();
2004-
assertEquals("abcdefg", driver.findElement(By.id("myInput")).getAttribute("value"));
2000+
assertEquals("abcdefg", driver.findElement(By.id("myInput")).getDomProperty("value"));
20052001
driver.findElement(By.id("mySubmit")).click();
20062002

20072003
expandExpectedAlertsVariables(URL_FIRST);
@@ -2027,7 +2023,7 @@ public void maxLength2() throws Exception {
20272023

20282024
final WebDriver driver = loadPage2(html);
20292025
driver.findElement(By.id("myInput")).sendKeys("abcdefg");
2030-
assertEquals("ab", driver.findElement(By.id("myInput")).getAttribute("value"));
2026+
assertEquals("ab", driver.findElement(By.id("myInput")).getDomProperty("value"));
20312027

20322028
driver.findElement(By.id("mySubmit")).click();
20332029

0 commit comments

Comments
 (0)