Skip to content

Commit

Permalink
XWIKI-21916: Allow to ignore errors happening during wcag validation …
Browse files Browse the repository at this point in the history
…in integration tests

  * Provide a new parameter wcagStopOnError which default is true, to
    allow ignoring wcag validation errors

(cherry picked from commit f554c87)
  • Loading branch information
surli committed Feb 22, 2024
1 parent 4db70f2 commit f2e3326
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public class UITestTestConfigurationResolver

private static final String WCAG_PROPERTY = "xwiki.test.ui.wcag";

private static final String WCAG_STOP_ON_ERROR_PROPERTY = "xwiki.test.ui.wcagStopOnError";

private static final String PROPERTIES_PREFIX_PROPERTY = "xwiki.test.ui.properties.";

private static final String PROFILES_PROPERTY = "xwiki.test.ui.profiles";
Expand Down Expand Up @@ -96,6 +98,7 @@ public TestConfiguration resolve(UITest uiTestAnnotation)
configuration.setJDBCDriverVersion(resolveJDBCDriverVersion(uiTestAnnotation.jdbcDriverVersion()));
configuration.setVNC(resolveVNC(uiTestAnnotation.vnc()));
configuration.setWCAG(resolveWCAG(uiTestAnnotation.wcag()));
configuration.setWCAGStopOnError(resolveWCAGStopOnError(uiTestAnnotation.wcagStopOnError()));
configuration.setProperties(resolveProperties(uiTestAnnotation.properties()));
configuration.setExtraJARs(resolveExtraJARs(uiTestAnnotation.extraJARs()));
configuration.setResolveExtraJARs(resolveResolveExtraJARs(uiTestAnnotation.resolveExtraJARs()));
Expand Down Expand Up @@ -229,6 +232,11 @@ private boolean resolveWCAG(boolean wcag)
return resolve(wcag, WCAG_PROPERTY);
}

private boolean resolveWCAGStopOnError(boolean wcagStopOnError)
{
return resolve(wcagStopOnError, WCAG_STOP_ON_ERROR_PROPERTY);
}

private boolean resolveOffice(boolean office)
{
return resolve(office, OFFICE_PROPERTY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,10 @@ private BrowserWebDriverContainer startBrowser(TestConfiguration testConfigurati
testConfiguration.getServletEngine().getInternalPort()));

// Setup the wcag validation context.
testContext.getUtil().getWCAGUtils().setupWCAGValidation(testConfiguration.isWCAG(),
extensionContext.getTestClass().get().getName());
testContext.getUtil().getWCAGUtils().setupWCAGValidation(
testConfiguration.isWCAG(),
extensionContext.getTestClass().get().getName(),
testConfiguration.shouldWCAGStopOnError());


// - the one used by RestTestUtils, i.e. outside of any container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public class TestConfiguration

private boolean wcag;

private boolean wcagStopOnError;

private Properties properties;

private List<ExtensionOverride> extensionOverrides;
Expand Down Expand Up @@ -105,6 +107,7 @@ public void merge(TestConfiguration testConfiguration) throws DockerTestExceptio
mergeJDBCDriverVersion(testConfiguration.getJDBCDriverVersion());
mergeVNC(testConfiguration.vnc());
mergeWCAG(testConfiguration.isWCAG());
mergeWCAGStopOnError(testConfiguration.shouldWCAGStopOnError());
mergeProperties(testConfiguration.getProperties());
mergeExtraJARs(testConfiguration.getExtraJARs());
mergeResolveExtraJARs(testConfiguration.isResolveExtraJARs());
Expand Down Expand Up @@ -244,6 +247,11 @@ private void mergeWCAG(boolean wcag)
this.wcag = isWCAG() || wcag;
}

private void mergeWCAGStopOnError(boolean wcagStopOnError)
{
this.wcagStopOnError = shouldWCAGStopOnError() || wcagStopOnError;
}

private void mergeOffice(boolean office)
{
if (!isOffice() && office) {
Expand Down Expand Up @@ -513,6 +521,24 @@ public void setWCAG(boolean wcag)
this.wcag = wcag;
}

/**
* @return {@code false} if WCAG validation should ignore errors, {@code true} otherwise.
* @since 16.1.0
*/
public boolean shouldWCAGStopOnError()
{
return this.wcagStopOnError;
}

/**
* @param wcagStopOnError {@code false} if WCAG validation should ignore errors, {@code true} otherwise.
* @since 16.1.0
*/
public void setWCAGStopOnError(boolean wcagStopOnError)
{
this.wcagStopOnError = wcagStopOnError;
}

/**
* @return the list of configuration properties to use when generating the XWiki configuration files such as as
* {@code xwiki.properties} (check {@code xwiki.properties.vm} to find the list of supported properties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@
*/
boolean wcag() default false;

/**
* @return {@code false} if WCAG validation should ignore errors, {@code true} otherwise.
* @since 16.1.0
*/
boolean wcagStopOnError() default true;

/**
* @return the list of configuration properties to use when generating the XWiki configuration files such as
* {@code xwiki.properties} with Velocity (check {@code xwiki.properties.vm} to find the list of supported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ String getIncompleteReport()

private String testMethodName;

private boolean stopOnError = true;

/**
* Sets the current test class name. This name is the string representation of the TestUI class in which the
* current wcag validation happens.
Expand Down Expand Up @@ -451,6 +453,22 @@ public boolean isWCAGEnabled()
return this.wcagEnabled;
}

/**
* @param stopOnError {@code false} if WCAG validation should ignore errors, {@code true} otherwise.
*/
public void setWCAGStopOnError(boolean stopOnError)
{
this.stopOnError = stopOnError;
}

/**
* @return {@code false} if WCAG validation should ignore errors, {@code true} otherwise.
*/
public boolean shouldWCAGStopOnError()
{
return this.stopOnError;
}

/**
* @return any of the validations found an incomplete check.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ public class WCAGUtils
/**
* @param wcag true if WCAG tests must be executed, false otherwise
* @param testClassName the PO class name to use for logging and reporting
* @param stopOnError {@code false} if WCAG validation should ignore errors, {@code true} otherwise.
*/
public void setupWCAGValidation(boolean wcag, String testClassName)
public void setupWCAGValidation(boolean wcag, String testClassName, boolean stopOnError)
{
this.wcagContext.setWCAGEnabled(wcag);
this.wcagContext.setWCAGStopOnError(stopOnError);
if (wcag) {
LOGGER.info("WCAG validation is enabled.");
wcagContext.setTestClassName(testClassName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,23 +687,31 @@ public void validateWCAG(WCAGContext wcagContext, boolean checkCache)
return;
}

long startTime = System.currentTimeMillis();
// Run WCAG tests on the current UI page if the current URL + PO class name are not in the cache, or if checking
// the cache is disabled.
if (!checkCache || wcagContext.isNotCached(this.getPageURL(), this.getClass().getName())) {
XWikiWebDriver driver = this.getDriver();
AxeBuilder axeBuilder = wcagContext.getAxeBuilder();
Results axeResult = axeBuilder.analyze(driver);
wcagContext.addWCAGResults(driver.getCurrentUrl(), this.getClass().getName(), axeResult);
long stopTime = System.currentTimeMillis();
long deltaTime = stopTime - startTime;
LOGGER.debug("[{} : {}] WCAG Validation on this element took [{}] ms.",
this.getPageURL(), this.getClass().getName(), deltaTime);
wcagContext.addWCAGTime(deltaTime);
} else {
// If the identifying pair is already in the cache, don't perform accessibility validation.
LOGGER.debug("[{} : {}] This combination of URL:class was already WCAG-checked.",
this.getPageURL(), this.getClass().getName());
try {
long startTime = System.currentTimeMillis();
// Run WCAG tests on the current UI page if the current URL + PO class name are not in the cache, or if checking
// the cache is disabled.
if (!checkCache || wcagContext.isNotCached(this.getPageURL(), this.getClass().getName())) {
XWikiWebDriver driver = this.getDriver();
AxeBuilder axeBuilder = wcagContext.getAxeBuilder();
Results axeResult = axeBuilder.analyze(driver);
wcagContext.addWCAGResults(driver.getCurrentUrl(), this.getClass().getName(), axeResult);
long stopTime = System.currentTimeMillis();
long deltaTime = stopTime - startTime;
LOGGER.debug("[{} : {}] WCAG Validation on this element took [{}] ms.",
this.getPageURL(), this.getClass().getName(), deltaTime);
wcagContext.addWCAGTime(deltaTime);
} else {
// If the identifying pair is already in the cache, don't perform accessibility validation.
LOGGER.debug("[{} : {}] This combination of URL:class was already WCAG-checked.",
this.getPageURL(), this.getClass().getName());
}
} catch (Exception e) {
if (wcagContext.shouldWCAGStopOnError()) {
throw e;
} else {
LOGGER.debug("Error during WCAG execution, but ignored thanks to wcagStopOnError flag: ", e);
}
}
}

Expand Down

0 comments on commit f2e3326

Please sign in to comment.