サンプルテストクラス
Not for use with personal data
次のコードスニペットでは、Espresso用の完全なサンプルテストを確認できます。まず、AxeDevToolsライブラリがインポートされ、初期化されます。@Beforeブロックで情報レジストリをAxe DevToolsに渡すことで、ビュー階層への接続が可能になります。同じブロックでは、設定をカスタマイズする方法の一例が示されています。最後にスキャンが実行され、結果がダッシュボードにアップロードされます。このスニペットの各部分の詳細は、我々のドキュメントでご確認ください。
class ExampleTest {
private val axe = AxeDevTools()
init {
// Connect using an API key
axe.startScanSession(apiKey = "<DEQUE_APIKEY>",
projectId = "<DEVHUB_PROJECT_ID>")
// Include the projectId to post results to axe Developer Hub (recommended)
}
@Before
fun setup() {
// Pass the information registry to axe DevTools
axe.setInstrumentation(InstrumentationRegistry.getInstrumentation())
// Optional: Add tags or utilize other customization features here
axe.tagScanAs(setOf("Team A"))
}
@Test
fun foobar() {
// Scan the app for accessibility issues and upload to the dashboard
axe.scan()?.uploadToDashboard()
axe.tearDown()
}
companion object {
@JvmStatic
@AfterClass
fun afterClass() {
axe.generateHtmlReportAndSummary("optional_name")
}
}
}