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

Unten finden Sie ein Beispiel für die ersten Schritte beim Testen von axe DevTools mit Espresso. Sehen Sie sich unbedingt den Abschnitt Android SDK-Funktionen an, um alles zu erfahren, was Sie in Ihren Barrierefreiheitstests mit axe DevTools Mobile anpassen können.

Für 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()
        }
    }
}

Für 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()
    }
}