axe-devtools-unittest API リファレンス

This page is not available in the language you requested. You have been redirected to the English version of the page.
Link to this page copied to clipboard

unittest 用のアクセシビリティアサーションを提供する axe-devtools-unittest パッケージの API リファレンス

Not for use with personal data

このパッケージは、unittestを拡張してAxe DevToolsと統合するヘルパーアサーションを提供します。

axe_devtools_unittest.AxeAssertions

アクセシビリティアサーションをunittest.TestCaseに追加するミックスインクラスです。テストクラスは、unittest.TestCaseAxeAssertionsの両方を拡張する必要があります。

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-apiaxe-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()