File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
androidx/test/uiautomator
com/google/samples/apps/nowinandroid/foryou Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -46,3 +46,15 @@ enum class HasChildrenOp {
4646 EXACTLY ,
4747 AT_MOST ,
4848}
49+
50+ /* *
51+ * Waits until an object with [selector] if visible on screen and returns the object.
52+ * If the element is not available in [timeout], throws [AssertionError]
53+ */
54+ fun UiDevice.waitAndFindObject (selector : BySelector , timeout : Long ): UiObject2 {
55+ if (! wait(Until .hasObject(selector), timeout)) {
56+ throw AssertionError (" Element not found on screen in ${timeout} ms (selector=$selector )" )
57+ }
58+
59+ return findObject(selector)
60+ }
Original file line number Diff line number Diff line change @@ -20,14 +20,15 @@ import androidx.benchmark.macro.MacrobenchmarkScope
2020import androidx.test.uiautomator.By
2121import androidx.test.uiautomator.Until
2222import androidx.test.uiautomator.untilHasChildren
23+ import androidx.test.uiautomator.waitAndFindObject
2324import com.google.samples.apps.nowinandroid.flingElementDownUp
2425
2526fun MacrobenchmarkScope.forYouWaitForContent () {
2627 // Wait until content is loaded by checking if topics are loaded
2728 device.wait(Until .gone(By .res(" loadingWheel" )), 5_000 )
2829 // Sometimes, the loading wheel is gone, but the content is not loaded yet
2930 // So we'll wait here for topics to be sure
30- val obj = device.findObject (By .res(" forYou:topicSelection" ))
31+ val obj = device.waitAndFindObject (By .res(" forYou:topicSelection" ), 10_000 )
3132 // Timeout here is quite big, because sometimes data loading takes a long time!
3233 obj.wait(untilHasChildren(), 60_000 )
3334}
You can’t perform that action at this time.
0 commit comments