Accessing Composables from UiAutomator | by Tomáš Mlynarič | Android Builders | Feb, 2023 | Tech Do

roughly Accessing Composables from UiAutomator | by Tomáš Mlynarič | Android Builders | Feb, 2023 will lid the newest and most present steerage not far off from the world. proper of entry slowly therefore you perceive nicely and appropriately. will accrual your information proficiently and reliably

How are you going to use UiAutomator in Jetpack Compose apps?

UiAutomator has a number of methods to entry UI parts on the display relying on the kind of ingredient. you should use the By selector class to entry the weather. You should utilize By.textual content() to entry parts by textual content label, By.desc() entry by contentDescriptionby ingredient flags like By.scrollable(), By.checkable(), By.clickable(), and so on; and By.res() to entry a component by its useful resource ID android:id="@+id/some_id".

First you have to allow testTagAsResourceId within the composable hierarchy you wish to check. This flag will assist you to convert the testTag to the useful resource ids for all nested composables. If in case you have a single exercise compose undertaking, you possibly can allow it solely as soon as close to the foundation of the composable tree. This can make sure that all nested composables with Modifier.testTag are accessible from the UiAutomator.

/* Copyright 2022 Google LLC. 
SPDX-License-Identifier: Apache-2.0 */

Scaffold(
modifier = Modifier.semantics
testTagsAsResourceId = true
,
// ...
)

/* Copyright 2022 Google LLC. 
SPDX-License-Identifier: Apache-2.0 */

LazyVerticalGrid(
modifier = modifier
.fillMaxSize()
.testTag("forYou:feed"),
// ...
)

/* Copyright 2022 Google LLC. 
SPDX-License-Identifier: Apache-2.0 */

class BaselineProfileGenerator
@get:Rule
val rule = BaselineProfileRule()

@Take a look at
enjoyable generate()
rule.collectBaselineProfile(PACKAGE_NAME)
// This block defines the app's vital person journey.
// Right here we're fascinated with optimizing for app startup.
pressHome()
startActivityAndWait()


/* Copyright 2022 Google LLC. 
SPDX-License-Identifier: Apache-2.0 */

class BaselineProfileGenerator
@get:Rule
val rule = BaselineProfileRule()

@Take a look at
enjoyable generate()
rule.collectBaselineProfile(PACKAGE_NAME)
// This block defines the app's vital person journey.
// Right here we're fascinated with optimizing for app startup.
pressHome()
startActivityAndWait()

// Wait till content material is asynchronously loaded.
// We discover ingredient with resource-id "forYou:feed", which equals to Modifier.testTag("forYou:feed")
gadget.wait(Till.hasObject(By.res("forYou:feed")), 5_000)
val feedList = gadget.findObject(By.res("forYou:feed"))

// Set some margin from the perimeters to stop triggering system navigation
feedList.setGestureMargin(gadget.displayWidth / 5)

// Fling the feed
feedList.fling(Course.DOWN)
gadget.waitForIdle()
feedList.fling(Course.UP)


After studying this text, you’ve got seen that enabling UiAutomator interop with Jetpack Compose is simple, and you’ll go away the content material description for accessibility.

I hope the article kind of Accessing Composables from UiAutomator | by Tomáš Mlynarič | Android Builders | Feb, 2023 provides perspicacity to you and is beneficial for toting as much as your information

Accessing Composables from UiAutomator | by Tomáš Mlynarič | Android Developers | Feb, 2023

x