Espresso

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

Hieronder staat een voorbeeld van het starten met axe DevTools-testen met Espresso. Vergeet niet de Android SDK-functies sectie te bekijken voor alles wat je kunt aanpassen in je toegankelijkheidstests met axe DevTools Mobile.

Voor XML-layouts

class ExampleInstrumentedTestWithAccessibility : Utils {

    @Rule
    @JvmField
    var rule: ActivityScenarioRule<MainActivity> = ActivityScenarioRule(MainActivity::class.java)

    private val axe = AxeDevTools()

    init {
        //Login using an API Key
        axe.loginWithApiKey(
            "<API_KEY>"
        )
    }

    @Before
    fun setup() {
        axe.tagScanAs(setOf("YourTag"))
        axe.setTestingConfig(AxeDevToolsEspressoConfig(IdlingRegistry.getInstance()))
    }

    @Test
    fun exampleTest() {
        onView(withText("Your View Name")).perform(click())
        onView(withText("Button")).perform(click())
        onView(withContentDescription("Content Description")).perform(click())
    }

    @After
    fun runAccessibilityScan() {
        rule.scenario.onActivity {
            val scan = axe.scan(it)
            scan?.uploadToDashboard()
            axe.tearDown()
        }
    }
}

Voor Compose-layouts

@ExperimentalComposeUiApi
class ExampleComposeTest {
    @get:Rule
    val composeTestRule = createAndroidComposeRule<TestComposeActivity>()

    private val axe = AxeDevToolsCompose()

    init {
        // Login using an API key 
        axe.loginWithApiKey(
            "<API_KEY>"
        )
    }

    @Before
    fun setup() {
        composeTestRule.setContent { YourComposableFunction() }
        composeTestRule.mainClock.autoAdvance = false
        composeTestRule.waitForIdle()

        axe.tagScanAs(setOf("YourTag"))
    }

    @Test
    fun foobar() {
        // Must be set in the tests itself
        axe.setComposeTestRule(composeTestRule)
        val scan = axe.scan()
        scan?.uploadToDashboard()
        axe.tearDown()
    }
}