Skip to main content

Accessibility testing using the axe-core library

Run Accessibility tests on your website using BrowserStack Automate and the axe-core library

This document provides you with the step-by-step process to verify if your website follows the WCAG and other guidelines (as supported by axe-core library), ensuring your website is accessible to all types of users on the Internet. Axe is a fast and lightweight accessibility testing tool that checks the entire document against the rules and generates a report with all violations, passes, etc.

In this guide, you will learn:


Before you can integrate your tests with BrowserStack and generate reports using the axe-core library, ensure that the following pre-requisites are complete:

Run your first accessibility test

The following sample script opens the file you downloaded in the pre-requisite step and injects the axe.min.js script in the DOM of the website under test. After that, using a Javascript Executor, the accessibility checks are invoked using the axe-core library. The generated report is saved in a JSON file as per the path provided in the script.

Note: You can also write assertions in your script based on the violations in the report.json and mark your test passed or failed based on these assertions.
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;


public class test{
	public static final String AUTOMATE_USERNAME = "YOUR_USERNAME";
	public static final String AUTOMATE_ACCESS_KEY = "YOUR_ACCESS_KEY";
	public static final String URL = "";
	public static void main(String[] args) throws Exception {
		 DesiredCapabilities caps = new DesiredCapabilities();
		 caps.setCapability("os_version", "10");
		 caps.setCapability("browser", "chrome");
		 caps.setCapability("browser_version", "latest");
		 caps.setCapability("os", "Windows");
		 caps.setCapability("name", "Accessibility Test - Google"); // test name
		 caps.setCapability("build", "Java Accessibility Test Sample Build"); // CI/CD job or build name
		 WebDriver driver = new RemoteWebDriver(new URL(URL), caps);

		 JavascriptExecutor jse = (JavascriptExecutor)driver;
		 Path path = Paths.get("path/to/axe.min.js");

		 String content = new String(Files.readAllBytes(path));

		 File output = new File("path/to/report.json");
		 FileWriter writer = new FileWriter(output);
		 String result = String.valueOf(jse.executeAsyncScript("var callback = arguments[arguments.length - 1]; => callback(results));"));
         Gson g = new Gson();
         String p = g.toJson(result);
const webdriver = require('selenium-webdriver');
const fs = require('fs')

// Input capabilities
const capabilities = {
  'browserName': 'chrome',
  'browserVersion': 'latest',
  'os': 'windows',
  'os_version': '10',
  'build': 'Accessibility Test Sample Build',
  'name': 'Accessibility test - Google'
async function runAccessibilityTest () {
  let driver = new webdriver.Builder()
  await driver.get("");
  const data = await fs.readFileSync('path/to/axe.min.js', 'utf8')
  await driver.executeScript(data.toString());
  let result = await driver.executeAsyncScript('var callback = arguments[arguments.length - 1]; => callback(results))');
  await fs.writeFileSync('path/to/report.json', JSON.stringify(result));
  await driver.quit();
using System;
using System.IO;
using Newtonsoft.Json;
using OpenQA.Selenium.Remote;
namespace SeleniumTest
    class Program
        static readonly string axe = @"/path/to/axe.min.js";
        static readonly string report = @"/path/where/you/want/to/save/report.json";
        static void Main(string[] args)
            RemoteWebDriver driver;
            OpenQA.Selenium.Chrome.ChromeOptions capability = new OpenQA.Selenium.Chrome.ChromeOptions();
            capability.AddAdditionalCapability("os_version", "10", true);
            capability.AddAdditionalCapability("browser", "Chrome", true);
            capability.AddAdditionalCapability("browser_version", "latest", true);
            capability.AddAdditionalCapability("os", "Windows", true);
            capability.AddAdditionalCapability("name", "Accessibility Test - Google", true); // test name
            capability.AddAdditionalCapability("build", "C-sharp Accessibility Test Sample Build", true); // CI/CD job or build name
            capability.AddAdditionalCapability("browserstack.user", "YOUR_USERNAME", true);
            capability.AddAdditionalCapability("browserstack.key", "YOUR_ACCESS_KEY", true);
            driver = new RemoteWebDriver(
                new Uri(""), capability
            if (File.Exists(axe))
                string axeCode = File.ReadAllText(axe);
                IJavaScriptExecutor javascriptExecutor = (IJavaScriptExecutor) driver;
                string result = JsonConvert.SerializeObject(javascriptExecutor.ExecuteAsyncScript("var callback = arguments[arguments.length - 1]; => callback(results))"), Formatting.Indented);
                File.WriteAllText(report, result);
  use Facebook\WebDriver\Remote\RemoteWebDriver;
  use Facebook\WebDriver\WebDriverBy;
  $caps = array(
    "os_version" => "10",
    "browser" => "Chrome",
    "browser_version" => "latest",
    "os" => "Windows",
    "name" => "Accessibility testing", // test name
    "build" => "Accessibility Testing Sample Build" // CI/CD job or build name
  $web_driver = RemoteWebDriver::create(

  $axe_script = fopen("path/to/axe.min.js", "r");
  $result = $web_driver->executeAsyncScript('var callback = arguments[arguments.length - 1]; => callback(results))');
  $file = fopen("path/to/report.json", "w");
  // $reportJSON = json_encode($result);
  fwrite($file,json_encode($result, JSON_PRETTY_PRINT));
from selenium import webdriver
import json

desired_cap = {
        "browser": "chrome",
        "browser_version": "latest",
        "os": "windows",
        "os_version": "10",
        'build': 'Python Accessibility Test Build',
        'name': 'Axe-core testing microsoft'
driver = webdriver.Remote(
axe_script = open('./axe.min.js', 'r')
result = driver.execute_async_script('var callback = arguments[arguments.length - 1]; => callback(results))')
file = open("./report.json", "w")
require	'rubygems'
require	'selenium-webdriver'
require 'json'

#Input Capabilities
caps =
caps["os"] = "Windows"
caps["os_version"] = "10"
caps["browser"] = "chrome"
caps["browser_version"] = "latest"
caps["build"] = "Sample Accessibility Test Build"
caps["name"] = "Accessibility test - Google"
caps["javascriptEnabled"] = "true"

driver = Selenium::WebDriver.for(:remote,
	:url => "",
	:desired_capabilities => caps)

	# Searching for 'BrowserStack' on ""
	axe_script = open('path/to/axe.min.js', 'r')
	result = driver.execute_async_script('var callback = arguments[arguments.length - 1]; => callback(results))')
	file = open("path/to/report.json", "w")


You need the JSON module to run and save the report in JSON format. Follow the steps below the install the module if you have not already done so:

Download the JSON module (JSON-4.02.tar.gz or any later version) and run the steps:

$tar xvfz JSON-4.02.tar.gz
$cd JSON-4.02
$perl Makefile.PL
$make install

Now, you can run the perl script given below to run Accessibility tests on BrowserStack:

use Selenium::Remote::Driver;
use JSON;  # Including this requires the pre-requisite steps
# Input capabilities
my $extraCaps = {
  'browserName'=> 'chrome',
  'browserVersion'=> 'latest',
  'os'=> 'windows',
  'build'=>'Accessibility Test Sample Build',
  'name'=>'Accessibility test - Google'
my $login = "YOUR_USERNAME";
my $key = "YOUR_ACCESS_KEY";
my $host = "$login:$key\";
my $driver = new Selenium::Remote::Driver('remote_server_addr' => $host,
  'port' => '80', 'extra_capabilities' => $extraCaps);


my $file_content = "";
open(FH, '<', 'path/to/axe.min.js') or die $!;
   $file_content = $file_content.$_;

$json = JSON->new->allow_nonref;
$json = encode_json($driver->execute_async_script('var callback = arguments[arguments.length - 1]; => callback(results))'));

open my $fh, ">", "path/to/report.json";
print $fh $json;
close $fh;


Understand components of the JSON report

After you successfully run test script, a report.json file is generated as per the path set in the script. The report.json JSON file contains the following accessibility test information:

		testEngine: {}
		passes: []
		inapplicable: []
		url: “<URL of the website under test>”
		timestamp: “time when the json result is generated”
		testRunner: {}
		toolOptions: {}
		testEnvironment: {}
		violations: {}
		incomplete: {}

Some of the information components available in the generated JSON report are:

  1. violations (json): These results indicate what elements failed in the rules.
  2. passes (array): These results indicate what elements passed in the rules.
  3. incomplete (json): It contains results that were aborted and require further testing. This can happen either because of technical restrictions to what the rule can test or because a javascript error that occurred.
  4. inapplicable (array): These results indicate rules that did not run because no matching content was found on the page. For example, if no video exists, those rules won’t run.

Each object returned in these arrays has some properties that can be found in the axe-core API documentation

Protip: You can also conduct Accessibility testing of your websites on browsers where High Contrast Mode is enabled by setting BrowserStack’s custom capability browserstack.high_contrast to true. Check out high contrast mode to learn more.

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked

Thank you for your valuable feedback

Is this page helping you?


We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked

Thank you for your valuable feedback!

Talk to an Expert
Talk to an Expert