|
| 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