|
|
@ -16,10 +16,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
package com.google.samples.apps.nowinandroid
|
|
|
|
package com.google.samples.apps.nowinandroid
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.test.uiautomator.BySelector
|
|
|
|
import androidx.test.uiautomator.Direction
|
|
|
|
import androidx.test.uiautomator.Direction
|
|
|
|
import androidx.test.uiautomator.UiDevice
|
|
|
|
import androidx.test.uiautomator.UiDevice
|
|
|
|
import androidx.test.uiautomator.UiObject2
|
|
|
|
import androidx.test.uiautomator.UiObject2
|
|
|
|
|
|
|
|
import androidx.test.uiautomator.Until
|
|
|
|
import com.google.samples.apps.nowinandroid.benchmarks.BuildConfig
|
|
|
|
import com.google.samples.apps.nowinandroid.benchmarks.BuildConfig
|
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Convenience parameter to use proper package name with regards to build type and build flavor.
|
|
|
|
* Convenience parameter to use proper package name with regards to build type and build flavor.
|
|
|
@ -38,3 +41,24 @@ fun UiDevice.flingElementDownUp(element: UiObject2) {
|
|
|
|
waitForIdle()
|
|
|
|
waitForIdle()
|
|
|
|
element.fling(Direction.UP)
|
|
|
|
element.fling(Direction.UP)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Waits until an object with [selector] if visible on screen and returns the object.
|
|
|
|
|
|
|
|
* If the element is not available in [timeout], throws [AssertionError]
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
fun UiDevice.waitAndFindObject(selector: BySelector, timeout: Long): UiObject2 {
|
|
|
|
|
|
|
|
if (!wait(Until.hasObject(selector), timeout)) {
|
|
|
|
|
|
|
|
throw AssertionError("Element not found on screen in ${timeout}ms (selector=$selector)")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return findObject(selector)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Helper to dump window hierarchy into a string.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
fun UiDevice.dumpWindowHierarchy(): String {
|
|
|
|
|
|
|
|
val buffer = ByteArrayOutputStream()
|
|
|
|
|
|
|
|
dumpWindowHierarchy(buffer)
|
|
|
|
|
|
|
|
return buffer.toString()
|
|
|
|
|
|
|
|
}
|
|
|
|