mobile-dev-inc / maestro

Painless Mobile UI Automation
https://maestro.mobile.dev/
Apache License 2.0
5.89k stars 281 forks source link

Support creating baseline profiles for Android #1170

Open lcdsmao opened 1 year ago

lcdsmao commented 1 year ago

Is your feature request related to a problem? Please describe.

We are trying to create baseline profiles for our apps. The documentation example uses UI Automator to control the behavior of the app, which is hard to use. I'm wondering if we can use Maestro to create a baseline profile.

Describe the solution you'd like

I was trying to create a test like this:

@OptIn(ExperimentalBaselineProfilesApi::class)
class BaselineProfileGenerator {
    @get:Rule
    val baselineProfileRule = BaselineProfileRule()

    @Test
    fun appStartupAndUserJourneys() {
        baselineProfileRule.collectBaselineProfile(packageName = PACKAGE_NAME) {
            device.wait(By.pkg(PACKAGE_NAME), 5000L)

            while (isMaestro()) {
                SystemClock.sleep(500L)
            }
        }
    }

    private fun isMaestro(): Boolean {
        return try {
            Socket("localhost", 7001).use { true }
        } catch(ignored: IOException) {
            false
        }
    }
}

Then I execute the test and wait for the test starts. After the test started I execute maestro: maestro test myflow.yaml. But maestro cannot start property with this exception:

java.util.concurrent.TimeoutException: Maestro Android driver did not start up in time 
    at maestro.drivers.AndroidDriver.await Launch (AndroidDriver.kt:138)
    at maestro.drivers.AndroidDriver.open (AndroidDriver.kt:102)
    at maestro.Maestro$Companion. android (Maestro.kt:565) at maestro.cli.session.MaestroSessionManager.createAndroid (MaestroSessionManager.kt:270)
    at maestro.cli.session.MaestroSessionManager.createMaestro (MaestroSessionManager.kt:151)
    at maestro.cli.session.MaestroSessionManager.access$createMaestro (MaestroSessionManager.kt:49)
    at maestro.cli.session.MaestroSessionManager$newSession$session$1.invoke(MaestroSessionManager.kt:81)
    at maestro.cli.session.MaestroSessionManager$newSession$session$1.invoke(MaestroSessionManager.kt:80)
    at maestro.cli.db.KeyValueStore.withExclusive Lock (KeyValueStore.kt:37)
    at maestro.cli.session.SessionStore.with ExclusiveLock (SessionStore.kt:74)
    at maestro.cli.session.MaestroSessionManager.newSession (MaestroSessionManager.kt:80)
    at maestro.cli.session.MaestroSessionManager.newSession$default(MaestroSessionManager.kt:57)
    at maestro.cli.command.TestCommand.call(TestCommand.kt:126)
    at maestro.cli.command. TestCommand.call(TestCommand.kt:44)
    at picocli.CommandLine.executeUserObject (CommandLine.java:1933)
    at picocli.CommandLine.access$1200 (CommandLine.java:145)
    at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent (CommandLine.java:2332)
    at picocli.CommandLine$RunLast.handle(CommandLine.java:2326)
    at picocli, CommandLine$RunLast.handle(CommandLine.java:2291)    
    at CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2159)
    at maestro.cli. DisableAnsiMixin$Companion.executionStrategy (DisableAnsiMixin.kt:22)
    at picocli.CommandLine,execute (CommandLine.java:2058) 
    at maestro.cli.AppKt.main(App.kt:136)

Describe alternatives you've considered

Additional context

bartekpacia commented 4 months ago

Creating baseline profiles with Maestro is such a cool idea, thanks for sharing it with us.

We don't have resources to work on this right now, unfortunately, but if someone from the community would like to investigate it further (and maybe shoot us a PR with code/docs), we'd be happy to review it.