-
-
Notifications
You must be signed in to change notification settings - Fork 552
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
XWIKI-22260: WCAG automatic testing for modals #3293
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -19,10 +19,16 @@ | |||
*/ | ||||
package org.xwiki.test.ui.po; | ||||
|
||||
import com.deque.html.axecore.results.Results; | ||||
import com.deque.html.axecore.selenium.AxeBuilder; | ||||
import org.openqa.selenium.By; | ||||
import org.openqa.selenium.WebDriver; | ||||
import org.openqa.selenium.WebElement; | ||||
import org.openqa.selenium.support.ui.ExpectedCondition; | ||||
import org.slf4j.Logger; | ||||
import org.slf4j.LoggerFactory; | ||||
import org.xwiki.test.ui.WCAGContext; | ||||
import org.xwiki.test.ui.XWikiWebDriver; | ||||
|
||||
/** | ||||
* The base class for a bootstrap modal. | ||||
|
@@ -32,6 +38,8 @@ | |||
*/ | ||||
public class BaseModal extends BaseElement | ||||
{ | ||||
private static final Logger LOGGER = LoggerFactory.getLogger(BaseModal.class); | ||||
|
||||
protected WebElement container; | ||||
|
||||
/** | ||||
|
@@ -51,6 +59,9 @@ public BaseModal(By selector) | |||
String className = this.container.getAttribute("class"); | ||||
className = className.replace("fade", ""); | ||||
getDriver().executeScript("arguments[0].setAttribute(\"class\",arguments[1])", this.container, className); | ||||
// Once we're sure the modal is loaded, we can validate its content in regards to accessibility | ||||
className = this.container.getAttribute("class").split(" ")[0]; | ||||
validateWCAG(getUtil().getWCAGUtils().getWCAGContext(), true, "." + className); | ||||
} | ||||
|
||||
public String getTitle() | ||||
|
@@ -69,6 +80,42 @@ public void close() | |||
waitForClosed(); | ||||
} | ||||
|
||||
public void validateWCAG(WCAGContext wcagContext, boolean checkCache, String cssSelector) { | ||||
if (!wcagContext.isWCAGEnabled()) { | ||||
// Block WCAG validation if it is not enabled, in all cases. | ||||
return; | ||||
} | ||||
|
||||
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. | ||||
XWikiWebDriver driver = this.getDriver(); | ||||
if (!checkCache || wcagContext.isNotCached(driver.getCurrentUrl(), this.getClass().getName())) { | ||||
AxeBuilder axeBuilder = wcagContext.getAxeBuilder(); | ||||
// Only analyze the modal itself | ||||
axeBuilder.include(cssSelector); | ||||
Results axeResult = axeBuilder.analyze(driver); | ||||
wcagContext.addWCAGResults(driver.getCurrentUrl(), this.getClass().getName(), axeResult); | ||||
long stopTime = System.currentTimeMillis(); | ||||
long deltaTime = stopTime - startTime; | ||||
LOGGER.info("[{} : {}] WCAG Validation on this element took [{}] ms.", | ||||
driver.getCurrentUrl(), 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.", | ||||
driver.getCurrentUrl(), 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); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better be an info than a debug here no? We don't enable debug often, and it could be useful to still see those, or could that be an issue on the CI? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is in line with Line 713 in 0ddc451
|
||||
} | ||||
} | ||||
} | ||||
|
||||
/** | ||||
* The modal may have a fade out effect on close which means it may not disappear instantly. It's safer to wait for | ||||
* the modal to disappear when closed, before proceeding with next actions. | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels dangerous to rely on the className only: what if you have a page with 3 modals having the class
modal
, and only one is loaded? Right now the validation will be executed on the 3 modals AFAIU.Feels like you could artificially add a new specific class (pretty much like we remove the fade class) just to identify the actual modal.