スキャンを実行する
Not for use with personal data
準備、用意、スキャン
axeDevToolsXCUIフレームワークをインポートして初期化したら、スキャンの準備は完了です。テストしたいXCUIElementを渡すことで、UIテストのどこでもスキャンを実行できます。以下の例では、アプリのフローで現在表示されているすべてのビューをテストするために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.startScanSession(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)
}
}非初期化
ベストプラクティスとして、以前のテストの状態をクリアするためにtearDown関数を使用してaxeオブジェクトを非初期化します。
override func tearDown() {
axe = nil
}次はどうする?
スキャン結果をAxe Developer Hubにアップロードおよび結果をローカルに保存するについてさらに学びましょう。
