DEV Community

Cover image for TestFly Part 7: Bundled axe-core Accessibility Assertions & VisualAssert Pixel Matching
Hakan GÜL
Hakan GÜL

Posted on Originally published at hakangul.lovable.app

TestFly Part 7: Bundled axe-core Accessibility Assertions & VisualAssert Pixel Matching

Accessibility & Visual Regression in TestFly

TestFly bundles axe-core 4.10.2 and a dedicated pixel-comparison engine VisualAssert directly into the core JAR.


1. Bundled axe-core Accessibility Scans (accessibility())

In BaseTest, run a WCAG scan in a single line without external dependencies:

package io.testfly.examples.a11y;

import io.testfly.accessibility.Impact;
import io.testfly.test.BaseTest;
import org.testng.annotations.Test;

public class AccessibilityTest extends BaseTest {

    @Test
    public void checkoutPassesWcagAA() {
        open("/checkout");

        accessibility()
            .withTags("wcag2a", "wcag21aa", "wcag22aa")
            .withLevel(Impact.SERIOUS) // fails on SERIOUS or CRITICAL
            .excluding("#third-party-widget")
            .run();
    }
}
Enter fullscreen mode Exit fullscreen mode

2. Pixel-Perfect Visual Regression (VisualAssert)

package io.testfly.examples.visual;

import io.testfly.test.BaseTest;
import io.testfly.visual.VisualAssert;
import io.testfly.visual.VisualTolerance;
import org.openqa.selenium.By;
import org.testng.annotations.Test;

public class VisualRegressionTest extends BaseTest {

    @Test
    public void homepageVisualMatchesBaseline() {
        open("/");

        // Full-page comparison with 1% tolerance
        VisualAssert.assertScreenshot("homepage", VisualTolerance.of(1));

        // Element-scoped comparison
        VisualAssert.assertScreenshot("login-box", By.id("login-card"));
    }
}
Enter fullscreen mode Exit fullscreen mode
  • First Run: Baseline screenshot is generated automatically.
  • Subsequent Runs: Compares against baseline; diffs saved to target/visual-diffs/.
  • Update Baselines: Run with -DupdateBaselines=true.

Top comments (0)