use of org.asqatasun.rules.elementchecker.ElementChecker in project Asqatasun by Asqatasun.
the class Rgaa22Rule07081 method check.
@Override
protected void check(SSPHandler sspHandler, TestSolutionHandler testSolutionHandler) {
// Tags check
ElementChecker ec = new ElementPresenceChecker(TestSolution.FAILED, TestSolution.PASSED, PRESENTATION_TAG_DETECTED_MSG, null);
ec.check(sspHandler, deprecatedElementHandler, testSolutionHandler);
// Attributes checks
for (Map.Entry<String, ElementHandler> attrElementHandlerMapEntry : attrElementHandlerMap.entrySet()) {
ElementChecker attrEc = new ElementWithAttributePresenceChecker(new ImmutablePair(TestSolution.FAILED, PRESENTATION_ATTR_DETECTED_MSG), new ImmutablePair(TestSolution.PASSED, ""), attrElementHandlerMapEntry.getKey());
attrEc.check(sspHandler, attrElementHandlerMapEntry.getValue(), testSolutionHandler);
}
}
use of org.asqatasun.rules.elementchecker.ElementChecker in project Asqatasun by Asqatasun.
the class Rgaa30Rule110101 method check.
@Override
protected void check(SSPHandler sspHandler, TestSolutionHandler testSolutionHandler) {
// If the page has no input form element, the test is not applicable
if (inputFormHandler.isEmpty()) {
testSolutionHandler.addTestSolution(NOT_APPLICABLE);
return;
}
// If all the input form have a label, the test is passed
if (inputFormWithoutLabelHandler.isEmpty()) {
testSolutionHandler.addTestSolution(PASSED);
return;
}
ElementChecker ec = new ElementPresenceChecker(new ImmutablePair(FAILED, INVALID_FORM_FIELD_MSG), new ImmutablePair(PASSED, ""));
ec.check(sspHandler, inputFormWithoutLabelHandler, testSolutionHandler);
}
use of org.asqatasun.rules.elementchecker.ElementChecker in project Asqatasun by Asqatasun.
the class Rgaa30Rule110103 method check.
@Override
protected void check(SSPHandler sspHandler, TestSolutionHandler testSolutionHandler) {
/* If the page has no input form element, the test is not applicable */
if (inputFormMap.entrySet().isEmpty()) {
testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE);
return;
}
for (Map.Entry<Element, ElementHandler<Element>> entry : inputFormMap.entrySet()) {
/* The attribute Emptiness Checker. Keep default value i.e failed
when attribute is empty
*/
ElementChecker attributeEmptinessChecker = new TextEmptinessChecker(new TextAttributeOfElementBuilder(ARIA_LABELLEDBY_ATTR), ARIA_LABELLEDBY_EMPTY_MSG, null);
attributeEmptinessChecker.check(sspHandler, entry.getValue(), testSolutionHandler);
ElementHandler<Element> inputWithoutLabel = new ElementHandlerImpl();
ElementHandler<Element> notUniqueLabel = new ElementHandlerImpl();
for (Element el : entry.getValue().get()) {
if (StringUtils.isNotEmpty(el.attr(ARIA_LABELLEDBY_ATTR))) {
ElementHandler<Element> labelHandler = new ElementHandlerImpl();
labelHandler.addAll(entry.getKey().select(CssLikeSelectorBuilder.buildSelectorFromAttributeTypeAndValue(ID_ATTR, el.attr(ARIA_LABELLEDBY_ATTR))));
if (labelHandler.get().isEmpty()) {
inputWithoutLabel.add(el);
} else if (labelHandler.get().size() > 1) {
notUniqueLabel.add(el);
notUniqueLabel.addAll(labelHandler.get());
}
}
}
/* Check if the form element has a label associated */
ElementChecker elementPresenceChecker = new ElementPresenceChecker(new ImmutablePair(TestSolution.FAILED, FORM_ELEMENT_WITHOUT_LABEL_MSG), new ImmutablePair(TestSolution.PASSED, ""));
elementPresenceChecker.check(sspHandler, inputWithoutLabel, testSolutionHandler);
/* Check if the id attr of the label associated to the form element is unique */
elementPresenceChecker = new ElementPresenceChecker(new ImmutablePair(TestSolution.FAILED, FORM_ELEMENT_WITH_NOT_UNIQUE_LABEL_MSG), new ImmutablePair(TestSolution.PASSED, ""));
elementPresenceChecker.check(sspHandler, notUniqueLabel, testSolutionHandler);
}
}
use of org.asqatasun.rules.elementchecker.ElementChecker in project Asqatasun by Asqatasun.
the class Rgaa30Rule110102 method check.
@Override
protected void check(SSPHandler sspHandler, TestSolutionHandler testSolutionHandler) {
/* If the page has no input form element, the test is not applicable */
if (inputFormMap.entrySet().isEmpty()) {
testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE);
return;
}
for (Map.Entry<Element, ElementHandler<Element>> entry : inputFormMap.entrySet()) {
/* The attribute Presence Checker */
ElementChecker attributePresenceChecker = new AttributePresenceChecker(ID_ATTR, new ImmutablePair(TestSolution.PASSED, ""), new ImmutablePair(TestSolution.FAILED, ID_MISSING_MSG));
attributePresenceChecker.check(sspHandler, entry.getValue(), testSolutionHandler);
/* The attribute Emptiness Checker. Keep default value i.e failed
when attribute is empty
*/
ElementChecker attributeEmptinessChecker = new TextEmptinessChecker(new TextAttributeOfElementBuilder(ID_ATTR), ID_MISSING_MSG, null);
attributeEmptinessChecker.check(sspHandler, entry.getValue(), testSolutionHandler);
/* The id unicityChecker */
ElementChecker idUnicityChecker = new IdUnicityChecker(ID_NOT_UNIQUE_MSG);
idUnicityChecker.check(sspHandler, entry.getValue(), testSolutionHandler);
}
for (Map.Entry<Element, ElementHandler<Element>> entry : labelFormMap.entrySet()) {
/* The attribute Presence Checker */
ElementChecker attributePresenceChecker = new AttributePresenceChecker(FOR_ATTR, new ImmutablePair(TestSolution.PASSED, ""), new ImmutablePair(TestSolution.FAILED, FOR_MISSING_MSG));
attributePresenceChecker.check(sspHandler, entry.getValue(), testSolutionHandler);
/* The attribute Emptiness Checker. Keep default value i.e failed
when attribute is empty
*/
ElementChecker attributeEmptinessChecker = new TextEmptinessChecker(new TextAttributeOfElementBuilder(FOR_ATTR), FOR_MISSING_MSG, null);
attributeEmptinessChecker.check(sspHandler, entry.getValue(), testSolutionHandler);
}
for (Map.Entry<Element, ElementHandler<Element>> entry : inputFormMap.entrySet()) {
ElementHandler<Element> inputOnError = new ElementHandlerImpl();
/* Check if each input id attribute is linked to a for attribute*/
for (Element el : entry.getValue().get()) {
String id = el.id();
if (StringUtils.isNotBlank(id)) {
ElementHandler<Element> linkedLabelToInputHandler = new ElementHandlerImpl();
if (entry.getKey().select(LABEL_ELEMENT + " " + CssLikeSelectorBuilder.buildSelectorFromElementsAndAttributeValue(INPUT_ELEMENT, ID_ATTR, id)).isEmpty()) {
linkedLabelToInputHandler.addAll(entry.getKey().select(CssLikeSelectorBuilder.buildSelectorFromElementsAndAttributeValue(LABEL_ELEMENT, FOR_ATTR, id)));
if (linkedLabelToInputHandler.isEmpty()) {
inputOnError.add(el);
}
}
}
}
ElementChecker elementPresenceChecker = new ElementPresenceChecker(new ImmutablePair(TestSolution.FAILED, INVALID_INPUT_MSG), new ImmutablePair(TestSolution.PASSED, ""));
elementPresenceChecker.check(sspHandler, inputOnError, testSolutionHandler);
}
for (Map.Entry<Element, ElementHandler<Element>> entry : labelFormMap.entrySet()) {
ElementHandler<Element> labelOnError = new ElementHandlerImpl();
/* Check if each label for attribute is associated to an input id attribute*/
for (Element el : entry.getValue().get()) {
String id = el.attr(FOR_ATTR);
if (StringUtils.isNotBlank(id)) {
ElementHandler<Element> linkedLabelToInputHandler = new ElementHandlerImpl();
linkedLabelToInputHandler.addAll(entry.getKey().select(CssLikeSelectorBuilder.buildSelectorFromId(id)));
if (linkedLabelToInputHandler.isEmpty()) {
labelOnError.add(el);
}
}
}
ElementChecker elementPresenceChecker = new ElementPresenceChecker(new ImmutablePair(TestSolution.FAILED, INVALID_LABEL_MSG), new ImmutablePair(TestSolution.PASSED, ""));
elementPresenceChecker.check(sspHandler, labelOnError, testSolutionHandler);
}
}
use of org.asqatasun.rules.elementchecker.ElementChecker in project Asqatasun by Asqatasun.
the class Aw22Rule06061 method check.
@Override
protected void check(SSPHandler sspHandler, TestSolutionHandler testSolutionHandler) {
if (linksHandler.isEmpty()) {
testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE);
return;
}
if (emptyLinksHandler.isEmpty()) {
testSolutionHandler.addTestSolution(TestSolution.PASSED);
return;
}
ElementChecker ec = new ElementPresenceChecker(TestSolution.FAILED, TestSolution.PASSED, EMPTY_LINK_MSG, null, HREF_ATTR);
ec.check(sspHandler, emptyLinksHandler, testSolutionHandler);
}
Aggregations