axe-selenium-python integrates aXe and selenium to enable automated web accessibility testing.
You will need the following prerequisites in order to use axe-selenium-python:
- Python 2.7 or 3.6
- pytest-selenium >= 3.0.0
To install axe-selenium-python:
$ pip install axe-selenium-pythonTo install pytest-axe:
$ pip install pytest-axeTo run tests using pytest-selenium (a dependency of axe-selenium-python), tests must be marked with the non-destructive pytest decorator:
@pytest.mark.nondestructive
def test_my_test_function():
assert trueTest suites using axe-selenium-python must import pytest and the Axe class.
pytest-selenium relies on the base_url fixture, which can be set in a configuration file, or as a command line argument.
[pytest]
base_url = http://www.example.com$ pytest --base-url http://www.example.comtest_accessibility.py
import pytest
from axe_selenium_python import Axe
import pytest_axe
@pytest.mark.nondestructive
def test_accessibility(self, axe):
response = axe.execute()
assert len(response['violations']) == 0, axe.report()Tests not using the axe pytest fixture must use the selenium pytest fixture:
test_accessibility.py
import pytest
from axe_selenium_python import Axe
@pytest.mark.nondestructive
def test_accessibility(self, selenium):
axe = Axe(selenium)
response = axe.execute()
assert len(response['violations']) == 0, axe.report()