com.version1.webdriver.AccessibilityBase Maven / Gradle / Ivy
package com.version1.webdriver;
import com.deque.html.axecore.results.Results;
import com.deque.html.axecore.results.Rule;
import com.deque.html.axecore.selenium.AxeBuilder;
import com.deque.html.axecore.selenium.AxeReporter;
import org.junit.Assert;
import org.openqa.selenium.WebDriver;
import java.io.IOException;
import java.util.List;
/**
* A simple representation class for Accessibility testing
*/
public class AccessibilityBase {
private static final String reportPath = System.getProperty("user.dir") + "\\src\\test\\java\\reports\\";
/**
* Checks the Accessibility Violations
* @param webDriver active WebDriver instance
*/
public static void checkAccessibilityViolations(WebDriver webDriver) throws IOException {
String reportFile = reportPath + "accessibilityReport";
AxeBuilder builder = new AxeBuilder();
Results results = builder.analyze(webDriver);
saveReport(results, reportFile);
}
/**
* Saves the Accessibility testing report in the report file
* @param results of type class Results
* @param reportFile, Json file where the report is written
*/
private static void saveReport(Results results, String reportFile) {
List violations = results.getViolations();
if (violations.size() == 0) {
Assert.assertTrue("No violations found", true);
} else {
AxeReporter.writeResultsToJsonFile(reportFile, results);
Assert.assertEquals(0, violations.size());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy