Skip to content

Commit c222217

Browse files
fff
fff
1 parent 5bc51fe commit c222217

File tree

2 files changed

+174
-0
lines changed

2 files changed

+174
-0
lines changed

ApplicationFullTest.java

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.deque;
2+
3+
import com.deque.attest.AttestConfiguration;
4+
import com.deque.attest.AttestDriver;
5+
import com.deque.attest.reporter.AttestReportingOptions;
6+
import org.junit.After;
7+
import org.junit.Before;
8+
import org.junit.Test;
9+
import org.openqa.selenium.By;
10+
import org.openqa.selenium.WebDriver;
11+
import org.openqa.selenium.WebElement;
12+
import org.openqa.selenium.chrome.ChromeDriver;
13+
import org.openqa.selenium.chrome.ChromeOptions;
14+
import static com.deque.attest.matchers.IsAuditedForAccessibility.isAuditedForAccessibility;
15+
import static com.deque.attest.matchers.IsAccessible.isAccessible;
16+
import static org.hamcrest.MatcherAssert.assertThat;
17+
18+
/*
19+
* ~ ApplicationFullTest ~
20+
* ~~~~~ IN THIS TEST CASE ~~~~~~~~~~
21+
* << Shows selenium webdriver use with Attest, and basic setup >>
22+
* << Uses isAuditedForAccessibility() function >>
23+
* << Uses isAccessible() function >>
24+
* << Uses selenium webdriver page interaction, and run Attest at different page states >>
25+
*/
26+
public class ApplicationFullTest {
27+
28+
AttestDriver attestDriver;
29+
private WebDriver webDriver;
30+
private AttestReportingOptions _reportOptions = new AttestReportingOptions();
31+
32+
//Setup: Specific configuration used below:
33+
//withAxeScript() allows users to use custom axe script of their choosing
34+
@Before
35+
public void setUp() throws Exception {
36+
AttestConfiguration.configure()
37+
.testSuiteName("Deque") // << Default reporting suite name, results will be associated with this suite unless explicitly specified
38+
.withAxeScript(getClass().getResource("/axe.js"))
39+
.outputDirectory("target/attest-reports").forRuleset("wcag2");
40+
ChromeOptions options = new ChromeOptions();
41+
options.addArguments("headless"); //If not headless, comment out this line.
42+
options.addArguments("disable-gpu");
43+
webDriver = new ChromeDriver(options);
44+
attestDriver = new AttestDriver(webDriver);
45+
}
46+
47+
@After
48+
public void tearDown() throws Exception {
49+
webDriver.quit();
50+
}
51+
52+
// TestCase: uses isAuditedForAccessibility() >> will audit, and track all accessibility issues
53+
// if a violation exists it will NOT fail the test or break the build
54+
@Test
55+
public void auditTestPageForAccessibility() throws Exception {
56+
webDriver.get("https://dequeuniversity.com/demo/mars/");
57+
assertThat(attestDriver, isAuditedForAccessibility().logResults(_reportOptions.uiState("Mars Commuter")));
58+
}
59+
60+
@Test
61+
// TestCase: uses isAccessible() >> enforces the scanned page to have 0 violations,
62+
// if a violation exists the test will fail.
63+
public void DQUShouldBeAccessible() throws Exception {
64+
webDriver.get("https://www.dequeuniversity.com");
65+
assertThat(attestDriver, isAccessible().logResults(_reportOptions.uiState("Deque University")));
66+
}
67+
68+
//TestCase: uses seleniums webelement functionality to allow page interaction and run Attest before and after state change.
69+
@Test
70+
public void auditMarsCommuterAccessibility() throws Exception {
71+
//Scan the initial homepage of Mars Commuter before state change
72+
webDriver.get("https://dequeuniversity.com/demo/mars/");
73+
_reportOptions.testSuiteName("Mars Commuter State Change");
74+
assertThat(attestDriver, isAuditedForAccessibility().logResults(_reportOptions.uiState("Mars Commuter No Change")));
75+
76+
// Click a radio button to change form on page.
77+
WebElement planet = webDriver.findElement(By.id("route-type-multi-city"));
78+
planet.sendKeys("ChromeDriver");
79+
planet.click();
80+
assertThat(attestDriver, isAuditedForAccessibility().logResults(_reportOptions.uiState("Mars Commuter Changed State")));
81+
}
82+
83+
}

AttestCustomConfigTest.java

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package com.deque;
2+
3+
import com.deque.attest.AttestConfiguration;
4+
import com.deque.attest.AttestDriver;
5+
import com.deque.attest.reporter.AttestReportingOptions;
6+
import org.junit.After;
7+
import org.junit.AfterClass;
8+
import org.junit.Before;
9+
import org.junit.Test;
10+
import org.openqa.selenium.WebDriver;
11+
import org.openqa.selenium.chrome.ChromeDriver;
12+
import org.openqa.selenium.chrome.ChromeOptions;
13+
import static com.deque.attest.matchers.IsAuditedForAccessibility.isAuditedForAccessibility;
14+
import static org.hamcrest.MatcherAssert.assertThat;
15+
import java.io.File;
16+
import java.io.IOException;
17+
18+
/*
19+
* ~ AttestCustomConfigTest~
20+
* ~~~~~ IN THIS TEST CASE ~~~~~~~~~~
21+
* << Shows local testing of HTML page in project >>
22+
* << Uses specific identifier and rule set in single test case >>
23+
* << Uses specific Axe script and rule set for all test cases (shown in configuration) >>
24+
* << Use of different
25+
*/
26+
public class AttestCustomConfigTest {
27+
//In this case we point to specific LOCAL page within our project
28+
String absolutePath = new File("src/main/webapp/index.html").getAbsolutePath();
29+
static String macOSReporter = new File("src/test/resources/attest-reporter-macos").getAbsolutePath();
30+
AttestDriver attestDriver;
31+
private WebDriver webDriver;
32+
private AttestReportingOptions _reportOptions = new AttestReportingOptions();
33+
34+
35+
//Setup: Specific configuration used below:
36+
//withAxeScript() allows users to use custom axe script of their choosing
37+
@Before
38+
public void setUp() throws Exception {
39+
AttestConfiguration.configure()
40+
.withAxeScript(getClass().getResource("/axe.js"))
41+
.testSuiteName("Homepage") // Default reporting suite name, results will be associated
42+
.outputDirectory("target/attest-reports/attest-customization");
43+
ChromeOptions options = new ChromeOptions();
44+
//options.addArguments("headless");
45+
webDriver = new ChromeDriver(options);
46+
attestDriver = new AttestDriver(webDriver);
47+
webDriver.get("file:///"+absolutePath);
48+
}
49+
50+
@After
51+
public void tearDown() throws Exception {
52+
webDriver.quit();
53+
}
54+
55+
//Reporting function that calls the executable after all the tests have been run and creates HTML and XML report off of it.
56+
//Requires the attest reporter executable to be within the project.
57+
@AfterClass
58+
public static void createHtmlXmlReports() throws IOException{
59+
Runtime rt = Runtime.getRuntime();
60+
String command = macOSReporter +" target/attest-reports/attest-customization --dest target/attest-reports/attest-customization/a11y-html-report --format html+junit";
61+
rt.exec(command);
62+
}
63+
64+
65+
//TestCase: Using local page in the project and running Attest against it
66+
@Test
67+
public void auditHomePageForAccessibility() throws Exception {
68+
assertThat(attestDriver, isAuditedForAccessibility().logResults(_reportOptions.uiState("Homepage All")));
69+
}
70+
71+
//TestCase: Using local page, but running it on one single section of the page using wcag AA rules.
72+
//Notice the ability to chain functionality, such as within and according to to specify what you want to run.
73+
@Test
74+
public void auditHomePageWithOptions() throws Exception {
75+
assertThat(attestDriver, isAuditedForAccessibility().within(".jumbotron").skipping("color-contrast").accordingTo("wcag2a").logResults(_reportOptions.uiState("Homepage section")));
76+
}
77+
78+
//TestCase: Using local page, but running it against content we want excluded from the page.
79+
@Test
80+
public void auditHomePageWithExclusions() throws Exception {
81+
assertThat(attestDriver, isAuditedForAccessibility().excluding(".jumbotron").logResults(_reportOptions.uiState("Homepage excluding section")));
82+
}
83+
84+
85+
//TestCase: Using local page, but checking for 3 accessibility rules anyways.
86+
@Test
87+
public void auditHomePageWithCertainChecks() throws Exception {
88+
assertThat(attestDriver, isAuditedForAccessibility().checkingOnly("label", "aria-roles", "html-has-lang").logResults(_reportOptions.uiState("Homepage with certain checks")));
89+
}
90+
91+
}

0 commit comments

Comments
 (0)