Espresso with Compose Empty Test Rule

Link to Espresso with Compose Empty Test Rule copied to clipboard
Free Trial

This example highlights the use of the setEmptyComposeTestRule(params) API available in axe DevTools Mobile with Compose. When utilizing the AxeDevToolsCompose object in UITests with the ComposeEmptyTestRule capabilities of Android, the setEmptyComposeTestRule(params) aids in setting the library up properly.

Quick links:

Below is an example of the AxeDevToolsCompose object in an Espresso test when utilizing the ComposeEmptyTestRule capabilities of Android.

Complete Example

@RunWith(AndroidJUnit4::class)
class EmptyComposeRuleAPITest {
    @get:Rule
    val composeEmptyTestRule = createEmptyComposeRule()

    private lateinit var activity: ComponentActivity

    lateinit var scenario: ActivityScenario<ComponentActivity>

    companion object {
        val axe = AxeDevToolsCompose()

        init {
            axe.loginWithApiKey(
                "YOUR_API_KEY_HERE"
            )
        }
    }

    @Before
    fun setup() {
        scenario = ActivityScenario.launch(ComponentActivity::class.java)
        scenario.onActivity { activity ->
            this.activity = activity
            activity.setContent {
                Surface {
                    Column {
                        Text("Hello World")
                    }   
                }
            }   
        }
        composeEmptyTestRule.mainClock.autoAdvance = false
        composeEmptyTestRule.waitForIdle()
    }

    @Test
    fun doGenericScan() {
        axe.setEmptyComposeTestRule(composeEmptyTestRule, activity)
        axe.scan()?.uploadToDashboard()
    }

}