Skip to content

Commit

Permalink
test: add test for setOptions (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-siek authored May 5, 2021
1 parent 61447b8 commit 046d8c3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class AxeExampleUnitTest {
private static final String normalPage = "src/test/resources/html/normal.html";
private static final String nestedIframePage = "src/test/resources/html/nested-iframes.html";
private static final String nestedFramePage = "src/test/resources/html/nested-frames.html";
private static final String violationPage = "src/test/resources/html/violation.html";

/**
* Instantiate the WebDriver and navigate to the test site
Expand Down Expand Up @@ -156,14 +157,27 @@ public void testInjectsIntoNestedFrames() throws IOException, OperationNotSuppor
Assert.assertTrue("Txt file was not deleted.", txtFile.delete());
}

/**
* Test with options
*/
@Test
public void testAccessibilityWithOptionsAndViolations() throws IOException, OperationNotSupportedException {
this.webDriver.get("file:///" + new File(violationPage).getAbsolutePath());
AxeBuilder builder = new AxeBuilder();
builder.setOptions("{ \"rules\": { \"object-alt\": { \"enabled\": false } } }");
Results result = builder.analyze(webDriver);
List<Rule> violations = result.getViolations();
Assert.assertEquals("violations found", 1, violations.size());
}

/**
* Test with options
*/
@Test
public void testAccessibilityWithOptions() throws IOException, OperationNotSupportedException {
this.webDriver.get("file:///" + new File(normalPage).getAbsolutePath());
this.webDriver.get("file:///" + new File(violationPage).getAbsolutePath());
AxeBuilder builder = new AxeBuilder();
builder.setOptions("{ \"rules\": { \"accesskeys\": { \"enabled\": false } } }");
builder.setOptions("{ \"rules\": { \"image-alt\": { \"enabled\": false } } }");
Results result = builder.analyze(webDriver);
List<Rule> violations = result.getViolations();
Assert.assertEquals("No violations found", 0, violations.size());
Expand Down
17 changes: 17 additions & 0 deletions src/test/resources/html/violation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<html lang="en">
<head>
<title>Test Page</title>
</head>
<body>
<div role="main" id="host">
<h1>This is a test</h1>
<img src='' />
</div>
<div role="contentinfo" id="upside-down"></div>
<script>
var shadow = document.getElementById("upside-down").attachShadow({mode: "open"});
shadow.innerHTML = '<h2 id="shadow">SHADOW DOM</h2><ul><li>Shadow Item 1</li></ul>'
</script>
</body>
</html>

0 comments on commit 046d8c3

Please sign in to comment.