Skip to content

Commit

Permalink
Replace the deprecated WebElement.getAttribute(String) with getDomAtt…
Browse files Browse the repository at this point in the history
…ribute(String) and getDomProperty(String) at many places in the test suite
  • Loading branch information
rbri committed Feb 9, 2025
1 parent f9f5850 commit 8d49d46
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 44 deletions.
4 changes: 3 additions & 1 deletion src/test/java/org/htmlunit/html/HtmlMonthInputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,10 @@ public void typing() throws Exception {
final WebDriver driver = loadPage2(htmlContent);

final WebElement input = driver.findElement(By.id("foo"));

input.sendKeys("8");
assertEquals(getExpectedAlerts()[0], input.getAttribute("value"));
assertNull(input.getDomAttribute("value"));
assertEquals(getExpectedAlerts()[0], input.getDomProperty("value"));
}

/**
Expand Down
32 changes: 14 additions & 18 deletions src/test/java/org/htmlunit/html/HtmlOption2Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
package org.htmlunit.html;

import java.util.Arrays;
import java.util.List;

import org.htmlunit.WebDriverTestCase;
Expand Down Expand Up @@ -117,47 +116,44 @@ public void simpleScriptable() throws Exception {
* @throws Exception if the test fails
*/
@Test
@Alerts("oDown,sDown,dDown,oUp,sUp,dUp,")
@Alerts({"oDown", "sDown", "dDown", "oUp", "sUp", "dUp"})
// there seems to be a bug in selenium; for FF >= 10 this triggers
// "sDown,dDown,sUp,dUp,oDown,sDown,dDown,oUp,sUp,dUp," but a
// manual test shows, that this is wrong.
// for Chrome selenium shows only "sUp,dUp," but again
// manual test are showing something different
@BuggyWebDriver(CHROME = "sUp,dUp,",
EDGE = "sUp,dUp,",
FF = "sDown,dDown,sUp,dUp,",
FF_ESR = "sDown,dDown,sUp,dUp,")
@BuggyWebDriver(CHROME = {"sUp", "dUp"},
EDGE = {"sUp", "dUp"},
FF = {"sDown", "dDown", "sUp", "dUp"},
FF_ESR = {"sDown", "dDown", "sUp", "dUp"})
public void onMouse() throws Exception {
final String html = "<html><head><title>foo</title>\n"
+ "<script>\n"
+ " function debug(string) {\n"
+ " document.getElementById('myTextarea').value += string + ',';\n"
+ " }\n"
+ LOG_TEXTAREA_FUNCTION
+ "</script>\n"
+ "</head><body>\n"
+ " <form>\n"
+ " <div"
+ " onMouseDown='debug(\"dDown\");'"
+ " onMouseUp='debug(\"dUp\");'>\n"
+ " onMouseDown='log(\"dDown\");'"
+ " onMouseUp='log(\"dUp\");'>\n"
+ " <select name='select1' size='4'"
+ " onMouseDown='debug(\"sDown\");'"
+ " onMouseUp='debug(\"sUp\");'>\n"
+ " onMouseDown='log(\"sDown\");'"
+ " onMouseUp='log(\"sUp\");'>\n"
+ " <option id='opt1' value='option1'>Option1</option>\n"
+ " <option id='opt2' value='option2' selected='selected'>Option2</option>\n"
+ " <option id='opt3' value='option3'"
+ " onMouseDown='debug(\"oDown\");'"
+ " onMouseUp='debug(\"oUp\");'>Option3</option>\n"
+ " onMouseDown='log(\"oDown\");'"
+ " onMouseUp='log(\"oUp\");'>Option3</option>\n"
+ " </select>\n"
+ " </div>\n"
+ " </form>\n"
+ " <textarea id='myTextarea'></textarea>\n"
+ LOG_TEXTAREA
+ "</body></html>";

final WebDriver driver = loadPage2(html);
driver.findElement(By.id("opt3")).click();

assertEquals(Arrays.asList(getExpectedAlerts()).toString(),
'[' + driver.findElement(By.id("myTextarea")).getAttribute("value") + ']');
verifyTextArea2(driver, getExpectedAlerts());
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/htmlunit/html/HtmlPage3Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ public void getInputByName() throws Exception {

final WebElement form = driver.findElement(By.id("form1"));
final WebElement input = form.findElement(By.name("textInput1"));
assertEquals("name", "textInput1", input.getAttribute("name"));
assertEquals("name", "textInput1", input.getDomAttribute("name"));

assertEquals("value", "textInput1", input.getAttribute("value"));
assertEquals("type", "text", input.getAttribute("type"));
assertEquals("value", "textInput1", input.getDomAttribute("value"));
assertEquals("type", "text", input.getDomAttribute("type"));
}

/**
Expand Down
30 changes: 11 additions & 19 deletions src/test/java/org/htmlunit/html/HtmlRadioButtonInput2Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
*/
package org.htmlunit.html;

import java.util.Arrays;

import org.htmlunit.WebDriverTestCase;
import org.htmlunit.junit.BrowserRunner;
import org.htmlunit.junit.annotation.Alerts;
Expand Down Expand Up @@ -542,62 +540,56 @@ public void checkedOnXmlResponse() throws Exception {
* @throws Exception if the test fails
*/
@Test
@Alerts("foo,change,")
@Alerts({"foo", "change"})
public void onchangeFires() throws Exception {
final String html =
HtmlPageTest.STANDARDS_MODE_PREFIX_
+ "<html><head><title>foo</title>\n"
+ "<script>\n"
+ " function debug(string) {\n"
+ " document.getElementById('myTextarea').value += string + ',';\n"
+ " }\n"
+ LOG_TEXTAREA_FUNCTION
+ "</script>\n"
+ "</head><body>\n"
+ "<form>\n"
+ "<input type='radio' name='radioGroup' id='radio'"
+ " onchange='debug(\"foo\");debug(event.type);'>Check me</input>\n"
+ " onchange='log(\"foo\");log(event.type);'>Check me</input>\n"
+ "</form>\n"
+ "<textarea id='myTextarea'></textarea>\n"
+ LOG_TEXTAREA
+ "</body></html>";

final WebDriver driver = loadPage2(html);
driver.findElement(By.id("radio")).click();

assertEquals(Arrays.asList(getExpectedAlerts()).toString(),
'[' + driver.findElement(By.id("myTextarea")).getAttribute("value") + ']');
verifyTextArea2(driver, getExpectedAlerts());
}

/**
* @throws Exception if the test fails
*/
@Test
@Alerts("foo,change,boo,blur,")
@Alerts({"foo", "change", "boo", "blur"})
public void onchangeFires2() throws Exception {
final String html =
HtmlPageTest.STANDARDS_MODE_PREFIX_
+ "<html><head><title>foo</title>\n"
+ "<script>\n"
+ " function debug(string) {\n"
+ " document.getElementById('myTextarea').value += string + ',';\n"
+ " }\n"
+ LOG_TEXTAREA_FUNCTION
+ "</script>\n"
+ "</head><body>\n"
+ "<form>\n"
+ "<input type='radio' name='radioGroup' id='radio1'"
+ " onChange='debug(\"foo\");debug(event.type);'"
+ " onBlur='debug(\"boo\");debug(event.type);'"
+ " onChange='log(\"foo\");log(event.type);'"
+ " onBlur='log(\"boo\");log(event.type);'"
+ ">Check Me</input>\n"
+ "<input type='radio' name='radioGroup' id='radio2'>Or Check Me</input>\n"
+ "</form>\n"
+ "<textarea id='myTextarea'></textarea>\n"
+ LOG_TEXTAREA
+ "</body></html>";

final WebDriver driver = loadPage2(html);
driver.findElement(By.id("radio1")).click();
driver.findElement(By.id("radio2")).click();

assertEquals(Arrays.asList(getExpectedAlerts()).toString(),
'[' + driver.findElement(By.id("myTextarea")).getAttribute("value") + ']');
verifyTextArea2(driver, getExpectedAlerts());
}

/**
Expand Down
10 changes: 7 additions & 3 deletions src/test/java/org/htmlunit/html/HtmlRangeInputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public void properties() throws Exception {
* @throws Exception if the test fails
*/
@Test
@Alerts("50")
@Alerts({"42", "50"})
public void clearInput() throws Exception {
final String html = "<html>\n"
+ "<body>\n"
Expand All @@ -336,9 +336,13 @@ public void clearInput() throws Exception {

final WebDriver driver = loadPage2(html);
final WebElement element = driver.findElement(By.id("tester"));
element.clear();

assertEquals(getExpectedAlerts()[0], element.getAttribute("value"));
assertEquals(getExpectedAlerts()[0], element.getDomAttribute("value"));
assertEquals(getExpectedAlerts()[0], element.getDomProperty("value"));

element.clear();
assertEquals(getExpectedAlerts()[0], element.getDomAttribute("value"));
assertEquals(getExpectedAlerts()[1], element.getDomProperty("value"));
}

/**
Expand Down

0 comments on commit 8d49d46

Please sign in to comment.