roughly Accessing Composables from UiAutomator | by Tomáš Mlynarič | Android Builders | Feb, 2023 will lid the newest and most present steering simply in regards to the world. open slowly consequently you perceive skillfully and appropriately. will buildup your data properly and reliably

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

UiAutomator has a number of methods to entry UI components on the display screen relying on the kind of ingredient. you need to use the By selector class to entry the weather. You should utilize By.textual content() to entry components 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 it is advisable allow testTagAsResourceId within the composable hierarchy you need to take a look at. This flag will help you convert the testTag to the useful resource ids for all nested composables. If in case you have a single exercise compose mission, you may allow it solely as soon as close to the foundation of the composable tree. This may be certain 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 crucial person journey.
// Right here we're involved in 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 crucial person journey.
// Right here we're involved in 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")
system.wait(Till.hasObject(By.res("forYou:feed")), 5_000)
val feedList = system.findObject(By.res("forYou:feed"))

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

// Fling the feed
feedList.fling(Path.DOWN)
system.waitForIdle()
feedList.fling(Path.UP)


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

I want the article roughly Accessing Composables from UiAutomator | by Tomáš Mlynarič | Android Builders | Feb, 2023 provides perception to you and is helpful for toting as much as your data

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

By admin

x