Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding axe tests #76

Merged
merged 6 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 42 additions & 8 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up ChromeDriver
uses: nanasess/[email protected].1
uses: nanasess/[email protected].2
- name: Set up JDK
uses: actions/[email protected]
with:
Expand All @@ -37,21 +37,55 @@ jobs:
id: test
run: ./gradlew clean test --stacktrace
- name: Cache Gradle packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Announce failures on Slack
if: ${{ steps.test.conclusion == 'failure' }}
uses: ravsamhq/notify-slack-action@v2
with:
status: ${{ job.status }}
- name: Cleanup Gradle Cache
run: |
rm -f ~/.gradle/caches/modules-2/modules-2.lock
rm -f ~/.gradle/caches/modules-2/gc.properties
accessibility-test:
name: Run accessibility tests
runs-on: ubuntu-latest
permissions:
actions: read
services:
postgres:
image: postgres
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
POSTGRES_USER: il-gcc-test
POSTGRES_PASSWORD: postgres
POSTGRES_DB: il-gcc-test
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v4
- name: Set up ChromeDriver
uses: nanasess/[email protected]
- name: Set up JDK
uses: actions/[email protected]
with:
distribution: 'adopt'
java-version: '17'
- name: Cache Gradle packages
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Test with Gradle
run: ./gradlew accessibilityTest
- name: Cleanup Gradle Cache
run: |
rm -f ~/.gradle/caches/modules-2/modules-2.lock
Expand Down
12 changes: 12 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ dependencies {
testImplementation 'org.apache.httpcomponents.client5:httpclient5:5.3'
testImplementation 'io.github.bonigarcia:webdrivermanager:5.6.4'
testImplementation 'com.h2database:h2:2.1.214'
testImplementation 'com.deque.html.axe-core:selenium:4.8.2'
testImplementation 'org.projectlombok:lombok:1.18.30'

testAnnotationProcessor 'org.projectlombok:lombok'
testCompileOnly 'org.projectlombok:lombok'

runtimeOnly 'org.postgresql:postgresql:42.6.0'
}
Expand Down Expand Up @@ -159,6 +164,13 @@ test {
}
}

tasks.register("accessibilityTest", Test) {
Test task ->
task.useJUnitPlatform {
JUnitPlatformOptions options ->
options.includeTags 'a11y'
}
}

tasks.withType(Test).configureEach {
environment("SENTRY_DSN", "")
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ general.eligibility-table.row-4.income=$6,008
general.eligibility-table.row-5.family=6 people
general.eligibility-table.row-5.income=$6,973
general.button.continue=Continue
general.to=to

general.week.Monday=Monday
general.week.Tuesday=Tuesday
Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/templates/fragments/inputError.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<p th:if="${null != errorMessages}" th:fragment="validationError(inputName)" class="text--error"
th:assert="${!#strings.isEmpty(inputName)}"
th:title="#{error.error}"
th:id="${inputName} + '-error-p'">
<th:block th:each="error, iter: ${errorMessages.get(inputName)}">
<i class="icon-warning" th:id="${inputName + '-error-icon'} + ${iter.index + 1}"></i>
<span th:id="${inputName} + '-error-message-' + ${iter.index + 1}"
th:class="${inputName + '-error'}" th:text="${error}"></span>
<br>
</th:block>
</p>
12 changes: 4 additions & 8 deletions src/main/resources/templates/fragments/inputs/timeRange.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@
(#arrays.length(errorMessages.get(inputName)) > 0) }"
th:assert="${!#strings.isEmpty(startInputName)},${!#strings.isEmpty(endInputName)}, ${hasLabel || hasAriaLabel}">
<div th:class="'form-group' + ${(hasError ? ' form-group--error' : '')}">
<legend class="form-question"
<legend class="form-question spacing-below-15"
th:id="${startInputName + '-legend'}"
th:inline="text">
[[${label}]]
</legend>
<div class="form-width--long">
<div class="form-width--short">
<p class="spacing-below-5"
th:id="${startInputName + '-help-text'}"
th:text="#{general.inputs.time.range.start}"></p>
<label th:for="${startInputName}" th:text="#{general.inputs.time.range.start}" class="text--help spacing-above-15 spacing-below-5"/>
<input type="time" class="time-input form-width--short"
th:id="${startInputName}"
th:name="${startInputName}"
Expand All @@ -29,11 +27,9 @@
aria-invalid=${hasError}"
th:value="${fieldData.getOrDefault(startInputName, '')}">
</div>
<label th:for="${inputName}" th:text="to" class="form-question spacing-above-35"/>
<strong th:text="#{general.to}"></strong>
<div class="form-width--short">
<p class="spacing-below-5"
th:id="${startInputName + '-help-text'}"
th:text="#{general.inputs.time.range.end}"></p>
<label th:for="${endInputName}" th:text="#{general.inputs.time.range.end}" class="text--help spacing-above-15 spacing-below-5"/>
<input type="time" class="time-input form-width--short"
th:id="${endInputName}"
th:name="${endInputName}"
Expand Down
62 changes: 62 additions & 0 deletions src/test/java/org/ilgcc/app/journeys/AccessibilityJourneyTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.ilgcc.app.journeys;

import com.deque.html.axecore.results.Results;
import com.deque.html.axecore.results.Rule;
import com.deque.html.axecore.selenium.AxeBuilder;
import lombok.extern.slf4j.Slf4j;
import org.ilgcc.app.utils.AccessibilityPage;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

@Slf4j
@Tag("a11y")
public class AccessibilityJourneyTest extends GccFlowJourneyTest {
protected static List<Rule> resultsList = new ArrayList<>();
protected static Results results;

@Override
@BeforeEach
public void setUp() throws IOException {
super.setUp();
testPage = new AccessibilityPage(driver);
}

@AfterEach
void afterEach() {
AxeBuilder builder = new AxeBuilder();
results = builder.analyze(driver);
resultsList.addAll(((AccessibilityPage) testPage).resultsList);
}

@AfterAll
static void tearDownAll() {
generateAccessibilityReport(results);
}

private static void generateAccessibilityReport(Results results) {
results.setViolations(resultsList);
List<Rule> violations = results.getViolations();
log.info("Found " + violations.size() + " accessibility related issues.");
if (results.getViolations().size() > 0) {
violations.forEach(violation -> {
log.info("-----------------------");
log.info("Rule at issue: " + violation.getId());
log.info("Rule description: " + violation.getDescription());
log.info("Rule help text: " + violation.getHelp());
log.info("Rule help page: " + violation.getHelpUrl());
log.info("Accessibility impact: " + violation.getImpact());
log.info("Page at issue: " + violation.getUrl());
log.info("HTML with issue: " + violation.getNodes().get(0).getHtml());
});
}
assertThat(violations.size()).isEqualTo(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,6 @@ void fullGccFlow() {

//activities-ed-program-dates
assertThat(testPage.getTitle()).isEqualTo("Time of Program");
testPage.clickContinue();
// testPage.clickContinue();
}
}
56 changes: 56 additions & 0 deletions src/test/java/org/ilgcc/app/utils/AccessibilityPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.ilgcc.app.utils;
import com.deque.html.axecore.results.Results;
import com.deque.html.axecore.results.Rule;
import com.deque.html.axecore.selenium.AxeBuilder;

import lombok.extern.slf4j.Slf4j;
import org.openqa.selenium.remote.RemoteWebDriver;

import java.util.ArrayList;
import java.util.List;


@Slf4j
public class AccessibilityPage extends Page {
public List<Rule> resultsList = new ArrayList<>();

public AccessibilityPage(RemoteWebDriver driver) {
super(driver);
}


@Override
public void clickLink(String linkText) {
super.clickLink(linkText);
testAccessibility();
}

@Override
public void clickButton(String buttonText) {
super.clickButton(buttonText);
testAccessibility();
}

@Override
public void clickButtonLink(String buttonLinkText) {
super.clickButtonLink(buttonLinkText);
testAccessibility();
}

public void testAccessibility() {
AxeBuilder builder = new AxeBuilder();
builder.setOptions("""
{ "resultTypes": ["violations"],
"runOnly": {
"type": "tag",
"values": ["wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "section508"]
}
}
""");
Results results = builder.analyze(driver);
List<Rule> violations = results.getViolations();
violations.forEach(rule -> rule.setUrl(getTitle()));
resultsList.addAll(violations);
log.info("Testing a11y on page %s, found %s violations".formatted(driver.getTitle(), violations.size()));
}
}