-
Notifications
You must be signed in to change notification settings - Fork 222
WIP: Migrate benchmarks to UiAutomator 3.0 API #322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,18 +16,14 @@ | |
|
||
package com.example.macrobenchmark.baselineprofile | ||
|
||
import androidx.benchmark.macro.MacrobenchmarkScope | ||
import androidx.test.uiautomator.UiDevice | ||
import androidx.test.uiautomator.UiAutomatorTestScope | ||
|
||
const val TARGET_PACKAGE = "com.example.macrobenchmark.target" | ||
|
||
/** | ||
* Clears the application data for the package specified in the [MacrobenchmarkScope]. | ||
* @param scope The [MacrobenchmarkScope] providing information about the benchmark, | ||
* including the package name of the app under test. | ||
* Clears the application data for the launcher package. | ||
*/ | ||
fun UiDevice.clearData(scope: MacrobenchmarkScope) { | ||
val command = "pm clear ${scope.packageName}" | ||
val output = executeShellCommand(command) | ||
// Assert.assertEquals("Success", output) | ||
fun UiAutomatorTestScope.clearData() { | ||
val command = "pm clear $TARGET_PACKAGE" | ||
uiDevice.executeShellCommand(command) | ||
Comment on lines
+26
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ package com.example.macrobenchmark.baselineprofile | |
import android.content.Intent | ||
import androidx.benchmark.macro.junit4.BaselineProfileRule | ||
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner | ||
import androidx.test.uiautomator.By | ||
import androidx.test.uiautomator.uiAutomator | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
@@ -37,12 +37,13 @@ class LoginBaselineProfileGenerator { | |
maxIterations = 15, | ||
stableIterations = 3 | ||
) { | ||
device.clearData(this) | ||
startActivityAndWait(Intent("$packageName.LOGIN_ACTIVITY")) | ||
device.findObject(By.res("userName")).text = "user" | ||
device.findObject(By.res("password")).text = "password" | ||
device.findObject(By.res("login")).click() | ||
device.waitForIdle() | ||
uiAutomator { | ||
clearData() | ||
startIntent(Intent("$packageName.LOGIN_ACTIVITY")) | ||
onView { viewIdResourceName == "userName" }.text = "user" | ||
onView { viewIdResourceName == "password" }.text = "password" | ||
onView { viewIdResourceName == "login" }.click() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ package com.example.macrobenchmark.baselineprofile | |
|
||
import androidx.benchmark.macro.junit4.BaselineProfileRule | ||
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner | ||
import androidx.test.uiautomator.uiAutomator | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
@@ -41,7 +42,9 @@ class StartupProfileGenerator { | |
stableIterations = 3, | ||
includeInStartupProfile = true | ||
) { | ||
startActivityAndWait() | ||
uiAutomator { | ||
startApp() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. startActivityAndWait is a macrobenchmark function, this new one is a UIAutomator function. Are we sure this is correct? startActivityAndWait isn't doing anything else that now wouldn't be done? |
||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,10 +25,11 @@ import androidx.benchmark.macro.StartupMode | |
import androidx.benchmark.macro.StartupTimingMetric | ||
import androidx.benchmark.macro.junit4.MacrobenchmarkRule | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.uiautomator.By | ||
import androidx.test.uiautomator.UiAutomatorTestScope | ||
import androidx.test.uiautomator.uiAutomator | ||
import com.example.macrobenchmark.benchmark.permissions.allowNotifications | ||
import com.example.macrobenchmark.benchmark.util.DEFAULT_ITERATIONS | ||
import com.example.macrobenchmark.benchmark.util.TARGET_PACKAGE | ||
import com.example.macrobenchmark.benchmark.permissions.allowNotifications | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
@@ -51,33 +52,35 @@ class LoginBenchmark { | |
@Test | ||
fun loginInSetupBlock() { | ||
benchmarkLoginActivity(setupBlock = { | ||
startActivityAndWait(Intent("$packageName.LOGIN_ACTIVITY")) | ||
login() | ||
uiAutomator { | ||
startIntent(Intent("$packageName.LOGIN_ACTIVITY")) | ||
login() | ||
} | ||
}) | ||
} | ||
|
||
@Test | ||
fun loginWithUiAutomator() { | ||
benchmarkLoginActivity { | ||
login() | ||
uiAutomator { login() } | ||
} | ||
} | ||
|
||
@Test | ||
fun loginInAfterPermissionsGranted() { | ||
benchmarkLoginActivity(setupBlock = { | ||
allowNotifications() | ||
|
||
startActivityAndWait(Intent("$packageName.LOGIN_ACTIVITY")) | ||
login() | ||
uiAutomator { | ||
startIntent(Intent("$packageName.LOGIN_ACTIVITY")) | ||
login() | ||
} | ||
}) | ||
} | ||
|
||
private fun MacrobenchmarkScope.login() { | ||
device.findObject(By.res("userName")).text = "user" | ||
device.findObject(By.res("password")).text = "password" | ||
device.findObject(By.res("login")).click() | ||
device.waitForIdle() | ||
private fun UiAutomatorTestScope.login() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
onView { viewIdResourceName == "userName" }.text = "user" | ||
onView { viewIdResourceName == "password" }.text = "password" | ||
onView { viewIdResourceName == "login" }.click() | ||
} | ||
|
||
private fun benchmarkLoginActivity( | ||
|
@@ -93,12 +96,10 @@ class LoginBenchmark { | |
iterations = DEFAULT_ITERATIONS, | ||
setupBlock = setupBlock, | ||
) { | ||
startActivityAndWait( | ||
Intent() | ||
.putExtras(extras) | ||
.setAction("$packageName.LOGIN_ACTIVITY") | ||
) | ||
measureBlock() | ||
uiAutomator { | ||
startIntent(Intent().putExtras(extras).setAction("$packageName.LOGIN_ACTIVITY")) | ||
measureBlock() | ||
} | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.