Git Product home page Git Product logo

a11y-audit-elixir's Introduction

A11yAudit

GitHub Workflow status version on Hex.pm number of downloads on Hex.pm license on Hex.pm

Automated accessibility testing for Elixir web applications using axe-core.

Expected page to have no accessibility violations, but got 1 violation. Form elements must have labels.

Installation

The library can be installed by adding a11y_audit to your list of dependencies in mix.exs:

def deps do
  [
    {:a11y_audit, "~> 0.2.0", only: :test}
  ]
end

Usage

A11yAudit provides assertions for browser-based tests.

For Wallaby

Call A11yAudit.Wallaby.assert_no_violations/1 in your Wallaby tests.

defmodule MyAppWeb.HomeTest do
  use ExUnit.Case, async: true
  use Wallaby.Feature

  feature "home page", %{session: session} do
    session
    |> visit("/")
    |> assert_has(Query.css("h1", text: "My App"))
    |> A11yAudit.Wallaby.assert_no_violations()
  end
end

For Hound

Call A11yAudit.Hound.assert_no_violations/0 in your Hound tests.

defmodule MyAppWeb.HomeTest do
  use ExUnit.Case
  use Hound.Helpers

  test "home page" do
    navigate_to("#{MyAppWeb.Endpoint.url()}/")

    heading = find_element(:css, "h1")
    assert inner_text(heading) == "My App"

    A11yAudit.Hound.assert_no_violations()
  end
end

For other environments

If you're running browser-based tests in Elixir without using Wallaby or Hound, you can still use A11yAudit. You will need a way to execute JavaScript snippets, and to get their return values back into your Elixir code. Assuming you have an execute_script function that can do that, you can use the test assertions like so:

get_audit_result =
  fn ->
    execute_script(A11yAudit.JS.axe_core())
    axe_result_map = execute_script(A11yAudit.JS.await_audit_results())
    A11yAudit.Results.from_json(axe_result_map)
  end

A11yAudit.Assertions.assert_no_violations(get_audit_result.())

Configuration

See the documentation for A11yAudit.Assertions.assert_no_violations/1 for a full list of options.

Configuration options can be passed to the assertion functions (A11yAudit.Wallaby.assert_no_violations/1, A11yAudit.Hound.assert_no_violations/0, A11yAudit.Assertions.assert_no_violations/1).

Supported browsers

Please reference axe-core's documentation to find out which browsers are supported.

Checks

Please reference axe-core's documentation to find out which accessibility checks are run.

Caveats

CSS transitions might cause flaky tests

If the accessibility audit runs while a CSS transition is in progress, it might lead to intermittent failures of the color contrast check. To prevent this, I recommend turning off CSS transitions in the test environment.

a11y-audit-elixir's People

Contributors

angelikatyborska avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

woylie

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.