axe-devtools-unittest API リファレンス
unittest 用のアクセシビリティアサーションを提供する axe-devtools-unittest パッケージの API リファレンス
このパッケージは、 unittest をAxe DevToolsと統合するためのヘルパーアサーションを提供します。
axe_devtools_unittest.AxeAssertions
アクセシビリティアサーションを追加するミックスインクラスです。 unittest.TestCase。テストクラスは、両方を拡張する必要があります。 unittest.TestCase と AxeAssertions。
class MyTests(unittest.TestCase, AxeAssertions):
...assertIsAxeClean(results)
axe-coreが違反を検出しなかったことをアサートします。
results:から返された結果オブジェクト。 Axe.analyze()。
違反がある場合は例外を発生させます。エラーメッセージには違反レポートが含まれています。 AssertionError
assertNoIncomplete(results)
axe-core が試みたすべてのチェックを完了したことをアサートします。
不完全なチェックは、明確に合格したとも失敗したとも言えず、手動でのレビューが必要です。
results:から返された結果オブジェクト。 Axe.analyze()。
不完全なチェックがある場合は例外を発生させます。 AssertionError
assertInapplicable(results, *rules)
指定したルールが該当しない結果を生成したことをアサートします。
results:から返された結果オブジェクト。 Axe.analyze()。
rules:該当しないステータスを確認するための1つまたは複数のルールID。
指定したルールのいずれかが該当しない結果に含まれていない場合は例外を発生させます。 AssertionError
例
次の例は、Python を使って直接実行することができます。ただし、 axe-devtools-api、 axe-devtools-selenium、および axe-devtools-unittest がインストールされている場合に限ります。
import unittest
from os import path
from axe_devtools_api import Axe
from axe_devtools_selenium import AxeDriver
from axe_devtools_unittest import AxeAssertions
from selenium import webdriver
class TestAxe(unittest.TestCase, AxeAssertions):
def setUp(self):
self.page = webdriver.Chrome()
self.page.get("http://localhost:8000/example-page.html")
self.axe = Axe(AxeDriver(self.page))
def test_run_axe(self):
res = self.axe.analyze()
assert res.is_axe_clean(), res.violations_report()
def test_with_rules(self):
res = self.axe \
.with_rules("document-title", "label") \
.with_rules("region") \
.analyze()
self.assertNoIncomplete(res)
self.assertIsAxeClean(res)
def test_including_within_frame(self):
res = self.axe \
.including("#my-frame", "body") \
.analyze()
self.assertNoIncomplete(res)
self.assertIsAxeClean(res)
if __name__ == '__main__':
unittest.main()