Excessibility (Excessibility v0.14.0)

View Source

Accessibility snapshot testing for Phoenix applications.

Excessibility captures HTML snapshots during tests and runs them through axe-core for WCAG compliance checking.

Usage

Add use Excessibility to your test modules:

defmodule MyAppWeb.PageControllerTest do
  use MyAppWeb.ConnCase
  use Excessibility

  test "home page is accessible", %{conn: conn} do
    conn = get(conn, "/")
    html_snapshot(conn)
    assert html_response(conn, 200)
  end
end

Supported Sources

The html_snapshot/2 macro works with:

Options

  • :name - Custom filename (default: auto-generated from module/line)
  • :prompt_on_diff - Interactive diff resolution (default: true)
  • :tag_on_diff - Save .good.html and .bad.html on diff (default: true)
  • :screenshot? - Generate PNG screenshots (default: false)
  • :open_browser? - Open snapshot in browser (default: false)
  • :cleanup? - Delete existing module snapshots first (default: false)

See the README for full documentation.

Summary

Functions

Sets up the module for snapshot testing by importing Excessibility.

Captures an HTML snapshot from a test source for accessibility testing.

Functions

__using__(opts)

(macro)

Sets up the module for snapshot testing by importing Excessibility.

This makes the html_snapshot/1 and html_snapshot/2 macros available in your test module without needing to fully qualify them.

Example

use Excessibility

Auto-Capture

Use @tag capture_snapshots: true to automatically capture snapshots:

@tag capture_snapshots: true
test "user flow", %{conn: conn} do
  {:ok, view, _html} = live(conn, "/dashboard")
  # Snapshots captured automatically
end

html_snapshot(source, opts \\ [])

(macro)

Captures an HTML snapshot from a test source for accessibility testing.

Returns the source unchanged, allowing use in pipelines.

Parameters

Examples

# Basic snapshot
html_snapshot(conn)

# With options
html_snapshot(conn,
  name: "login_form.html",
  screenshot?: true,
  prompt_on_diff: false
)

# In a pipeline
conn
|> get("/")
|> html_snapshot()
|> html_response(200)