スキャンを実行する

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
Not for use with personal data

準備、用意、スキャン

フレームワークをインポートして初期化したら、 axeDevToolsXCUI スキャンの準備完了です。UIテスト内のどこでも、アクセシビリティをテストしたい XCUIElement を渡すことでスキャンを実行できます。以下の例では、 XCUIApplication を渡して、アプリのフローで現在表示されているすべてのビューをテストしています。

func testAccessibility() throws {
    let result = try axe?.run(onElement: app)
}

サンプルスキャン

import axeDevToolsXCUI
import XCTest

class MyUITests: XCTestCase {
    var axe: AxeDevTools?
    var app = XCUIApplication()

    override func setUpWithError() throws {
        axe = try AxeDevTools.startSession(apiKey: "<DEQUE_APIKEY>",
            projectId: "<DEVHUB_PROJECT_ID>")

        app.launch()
    }

    func testAccessibility() throws {
        guard let result = try axe?.run(onElement: app) else {
            XCTFail()
            return
        }

        // Send results to axe Developer Hub.
        try axe?.postResult(result)

        // Fail the build if failures were found
        XCTAssertEqual(result.failures.count, 0)
    }
}

非初期化

ベストプラクティスとして、 axe オブジェクトを tearDown 関数を使って非初期化し、前のテストの状態をクリアします。

override func tearDown() {
    axe = nil
  }

次はどうする?

さらに詳しく知るには、 スキャン結果をaxe Developer Hubにアップロードする結果をローカルに保存するについて学びましょう。