Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Oct 14, 2023
1 parent 7701b70 commit c127a44
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions src/test/java/org/htmlunit/html/HtmlElementTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;

import org.htmlunit.SimpleWebTestCase;
import org.htmlunit.WebClient;
import org.htmlunit.junit.BrowserRunner;
import org.htmlunit.junit.BrowserRunner.Alerts;
import org.junit.Test;
Expand Down Expand Up @@ -1185,18 +1186,42 @@ public void asXml() throws Exception {
* @throws Exception if the test fails
*/
@Test
@Alerts("false")
public void isDisplayed() throws Exception {
@Alerts({"true", "false", "false"})
public void isDisplayedJsDisabled() throws Exception {
final String html = "<html><head>\n"
+ "</head>\n"
+ "</body>\n"
+ "<div id='d1'>hello</div>\n"
+ "<div id='d2' hidden>world</div>\n"
+ "<div id='d3' style='display:none;'>world</div>\n"
+ "</body></html>";

getWebClient().getOptions().setJavaScriptEnabled(false);
final HtmlPage page = loadPage(html);
assertTrue(page.getElementById("d1").isDisplayed());
assertEquals(Boolean.parseBoolean(getExpectedAlerts()[0]), page.getElementById("d2").isDisplayed());
assertEquals(Boolean.parseBoolean(getExpectedAlerts()[0]), page.getElementById("d1").isDisplayed());
assertEquals(Boolean.parseBoolean(getExpectedAlerts()[1]), page.getElementById("d2").isDisplayed());
assertEquals(Boolean.parseBoolean(getExpectedAlerts()[2]), page.getElementById("d3").isDisplayed());
}

/**
* @throws Exception if the test fails
*/
@Test
@Alerts({"true", "false", "false"})
public void isDisplayedJsEngineDisabled() throws Exception {
final String html = "<html><head>\n"
+ "</head>\n"
+ "</body>\n"
+ "<div id='d1'>hello</div>\n"
+ "<div id='d2' hidden>world</div>\n"
+ "<div id='d3' style='display:none;'>world</div>\n"
+ "</body></html>";

try (WebClient webClient = new WebClient(getBrowserVersion(), false, null, -1)) {
final HtmlPage page = loadPage(html);
assertEquals(Boolean.parseBoolean(getExpectedAlerts()[0]), page.getElementById("d1").isDisplayed());
assertEquals(Boolean.parseBoolean(getExpectedAlerts()[1]), page.getElementById("d2").isDisplayed());
assertEquals(Boolean.parseBoolean(getExpectedAlerts()[2]), page.getElementById("d3").isDisplayed());
}
}
}

0 comments on commit c127a44

Please sign in to comment.