mobile-dev-inc / maestro

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

"Unable to obtain active app id" error on maestro commands for iOS #646

Closed edgarfroes closed 1 year ago

edgarfroes commented 1 year ago

I get the error below when running commands on an iOS simulator on the latest maestro version (1.19.5):

Commands that I've tested so far and that are failing: test, studio, and hierarchy.

Click to see the complete error log

``` bash java.lang.IllegalStateException: Unable to obtain active app id at ios.xctest.XCTestIOSDevice.contentDescriptor(XCTestIOSDevice.kt:48) at ios.LocalIOSDevice.contentDescriptor(LocalIOSDevice.kt:32) at maestro.drivers.IOSDriver.contentDescriptor(IOSDriver.kt:175) at maestro.Maestro$findElementWithTimeout$1.invoke(Maestro.kt:344) at maestro.Maestro$findElementWithTimeout$1.invoke(Maestro.kt:343) at maestro.utils.MaestroTimer.withTimeout(MaestroTimer.kt:16) at maestro.Maestro.findElementWithTimeout(Maestro.kt:343) at maestro.orchestra.Orchestra.findElement(Orchestra.kt:646) at maestro.orchestra.Orchestra.findElement$default(Orchestra.kt:628) at maestro.orchestra.Orchestra.tapOnElement(Orchestra.kt:558) at maestro.orchestra.Orchestra.executeCommand(Orchestra.kt:159) at maestro.orchestra.Orchestra.runSubFlow(Orchestra.kt:443) at maestro.orchestra.Orchestra.runFlowCommand(Orchestra.kt:358) at maestro.orchestra.Orchestra.executeCommand(Orchestra.kt:185) at maestro.orchestra.Orchestra.runSubFlow(Orchestra.kt:443) at maestro.orchestra.Orchestra.runFlowCommand(Orchestra.kt:358) at maestro.orchestra.Orchestra.executeCommand(Orchestra.kt:185) at maestro.orchestra.Orchestra.executeCommands(Orchestra.kt:137) at maestro.orchestra.Orchestra.runFlow(Orchestra.kt:91) at maestro.cli.runner.MaestroCommandRunner.runCommands(MaestroCommandRunner.kt:120) at maestro.cli.runner.TestRunner$runSingle$result$1.invoke(TestRunner.kt:36) at maestro.cli.runner.TestRunner$runSingle$result$1.invoke(TestRunner.kt:32) at maestro.cli.runner.TestRunner.runCatching(TestRunner.kt:123) at maestro.cli.runner.TestRunner.runSingle(TestRunner.kt:32) at maestro.cli.command.TestCommand$call$1.invoke(TestCommand.kt:139) at maestro.cli.command.TestCommand$call$1.invoke(TestCommand.kt:100) at maestro.cli.session.MaestroSessionManager.newSession(MaestroSessionManager.kt:92) at maestro.cli.command.TestCommand.call(TestCommand.kt:100) at maestro.cli.command.TestCommand.call(TestCommand.kt:39) 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 picocli.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:122) ```

A few key points:

1 - When running xcrun simctl list devices booted I get only one device running, which is my emulator. 2 - I thought that it was a problem where I had Connect via network enabled on my physical device on Xcode's Window > Devices and Simulators > Devices > Select my physical device, so I disabled it and the error still persisted. Tried disabling the option Show as run destination as well. 3 - Tried to set the device id with maestro --device=[DEVICE_ID_HERE] test clear_safari_cache.yaml. 4 - Tried with different and newly created iOS simulators. 5 - Tried restarting the mac. 6 - The same error is happening when I try to run maestro studio. 7 - The same error is also occurring on maestro version 1.19.2, which leads me to ask: is there a problem with external dependencies getting upgraded and breaking maestro? 8 - Upon locally running the command xcrun simctl listapps booted in this function, the app that I'm using as the appId property of the yaml test file is being listed properly.

Steps to reproduce:

1 - Boot an iOS Simulator 2 - Create the file below and name it clear_safari_cache.yaml 3 - Run maestro test clear_safari_cache.yaml

appId: com.apple.Preferences
---
- launchApp
- tapOn: "Safari"
- swipe:
    direction: UP
    duration: 300
- tapOn: "Clear History and Website Data"
- tapOn: "Clear History and Data"
- tapOn: "Close Tabs"
- stopApp
edgarfroes commented 1 year ago

Update: I've added key points 6, 7, and 8 to the main post.

amanjeetsingh150 commented 1 year ago

Hey, @edgarfroes can you dump bug report with maestro bugreport and submit all the reports in a zip.

edgarfroes commented 1 year ago

@amanjeetsingh150 Done.

The first one is when running maestro test and the second one is when running maestro studio.

2023-01-20_122642.zip 2023-01-20_122851.zip

marciliojrs commented 1 year ago

Having the same issue when trying to run the maestro studio

If that helps @amanjeetsingh150, there's another dump. 2023-01-23_110804.zip

amanjeetsingh150 commented 1 year ago

Hey @marciliojrs @edgarfroes we are root causing this. Can confirm me these things:

Also as an FYI @edgarfroes I was not able to repro the issue with steps mentioned

marciliojrs commented 1 year ago

Hi @amanjeetsingh150, In my case, I wasn't using multiple sessions and also tried after deleting the sessions folder as you explained and nothing. Tested in the latest CLI version (1.20.o) and the error persists.

Short video reproducing the issue:

https://user-images.githubusercontent.com/732738/214386731-2c1604f0-77a4-4e05-937d-82b0912a355f.mp4

The maestro studio issue:

https://user-images.githubusercontent.com/732738/214387124-a942c4f9-9271-41c3-bb1f-f8f279d7031d.mp4

logs: 2023-01-24_161448.zip 2023-01-24_161508.zip

amanjeetsingh150 commented 1 year ago

Hey @marciliojrs there would be a xctest_runner_logs directory as well. Can you submit the the zip of the directory as well that contains logs of the new driver, would help more in debugging

marciliojrs commented 1 year ago

maestro logs.zip

sorry, cleaned everything here. sending another set of logs for maestro studio

amanjeetsingh150 commented 1 year ago

Hey @marciliojrs thanks 🙌 can you send multiple reports by running maestro studio and test command both wanted to see if there is any pattern

marciliojrs commented 1 year ago

logs.zip

Logs for maestro studio. Now I'm trying to run the test .. it's starting the flow but the tapOn isn't finding the item. 🤔

marciliojrs commented 1 year ago

Sorry @amanjeetsingh150 , I've downgraded maestro here to test if it helps and sent you logs from an old version. Sending the correct ones for 1.20.0.

logs1.20.0-studio.zip logs1.20.0-test.zip

amanjeetsingh150 commented 1 year ago

Hey @marciliojrs @edgarfroes thanks for the logs and helping in debugging 🙌 can you folks reproduce this issue in latest: 1.21.0 and provide the same logs? That has some logging improvements that can help in the further investigation, I will keep you updated on the investigation and release on this one.

marciliojrs commented 1 year ago

Hi @amanjeetsingh150 seems everything working now. I've changed my environment here to Xcode 14.2 also, don't know if that helped. 🚀

efstathiosntonas commented 1 year ago

same here using 1.21.1

2023-01-26_160527.zip 2023-01-26_160537.zip xctest_runner_logs.zip

amanjeetsingh150 commented 1 year ago

Hey @efstathiosntonas, curious if you have a localhost running on 9080 port already while working on maestro test by any chance?

amanjeetsingh150 commented 1 year ago

Hey @marciliojrs, were you working with localhost running on 9080 port when you got that error?

amanjeetsingh150 commented 1 year ago

Hey @edgarfroes @marciliojrs @efstathiosntonas I was able to reproduce this locally, can you check if you folks had a localhost running already on port 9080? If yes can you stop that process and try running maestro again? If this resolves your issue let me know we'll get a fix prepared for this one.

efstathiosntonas commented 1 year ago

@amanjeetsingh150 sure, will check asap

efstathiosntonas commented 1 year ago

@amanjeetsingh150 you were right, docker is using that port: Screenshot 2023-01-27 at 08 31 30

killing docker allowed maestro to work.

browser opened and could work, console throwed this though, just for your info:

Navigate to http://localhost:9999 in your browser to open Maestro Studio. Ctrl-C to exit.
io.ktor.util.cio.ChannelWriteException: Cannot write to a channel
    at io.ktor.server.netty.cio.NettyHttpResponsePipeline.respondWithFailure(NettyHttpResponsePipeline.kt:102)
    at io.ktor.server.netty.cio.NettyHttpResponsePipeline.respondWithBodyAndTrailerMessage(NettyHttpResponsePipeline.kt:252)
    at io.ktor.server.netty.cio.NettyHttpResponsePipeline.access$respondWithBodyAndTrailerMessage(NettyHttpResponsePipeline.kt:26)
    at io.ktor.server.netty.cio.NettyHttpResponsePipeline$respondWithBodyAndTrailerMessage$1.invokeSuspend(NettyHttpResponsePipeline.kt)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174)
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)
    at io.netty.channel.kqueue.KQueueEventLoop.run(KQueueEventLoop.java:295)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at io.ktor.server.netty.EventLoopGroupProxy$Companion.create$lambda-1$lambda-0(NettyApplicationEngine.kt:288)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: io.netty.channel.StacklessClosedChannelException
    at io.netty.channel.AbstractChannel$AbstractUnsafe.write(Object, ChannelPromise)(Unknown Source)
amanjeetsingh150 commented 1 year ago

Hey @efstathiosntonas thanks for the info does it continuously fail with this exception? Can you try with new terminal session?

efstathiosntonas commented 1 year ago

I've killed running session, closed terminal, reopened, maestro studio -> same error as above. Tried 2-3 times

amanjeetsingh150 commented 1 year ago

Is maestro studio failing or even maestro tests?

efstathiosntonas commented 1 year ago

it works fine, I can run tests on the browser

amanjeetsingh150 commented 1 year ago

Ohhh ok, so maestro studio is completely unusable for you? Can you check if the process with port 9999 is also killed? That is the studio's port I believe.

efstathiosntonas commented 1 year ago

No, maestro studio works as expected, I can run tests on the browser, tap elements on app etc and then playback the tests.

amanjeetsingh150 commented 1 year ago

Ahh got it so both maestro studio and maestro test commands are successful. Its just that this exception (ChannelWriteException) is like a non-fatal?

efstathiosntonas commented 1 year ago

exactly!

amanjeetsingh150 commented 1 year ago

Ahh got it thanks for pairing on this, I'll note this behavior and see if we can fix that nonfatal. @edgarfroes let me know if this works for you as well.

efstathiosntonas commented 1 year ago

@amanjeetsingh150 you're welcome, happy to help. Thank you for this amazing product. We're awaiting for real iOS device support 🥳

efstathiosntonas commented 1 year ago

@amanjeetsingh150 don't know if it's related with the non-fatal error but I'm using Firefox Developer Edition, not Chrome.

edgarfroes commented 1 year ago

@amanjeetsingh150 I had the Logitech Hub service, the one that manages my Logitech Mouse, running on port 9080. Killing the service made it work locally. I'm gonna trigger a new build in the CI (Codemagic) with the latest Maestro version and see what happens.

edgarfroes commented 1 year ago

What if maestro gets to find an available port instead of using 9080 only?

amanjeetsingh150 commented 1 year ago

I'm gonna trigger a new build in the CI (Codemagic) with the latest Maestro version and see what happens.

Awesome do check on CI if 9080 is free.

What if maestro gets to find an available port instead of using 9080 only?

We will be addressing this in subsequent versions

amanjeetsingh150 commented 1 year ago

@amanjeetsingh150 you're welcome, happy to help. Thank you for this amazing product. We're awaiting for real iOS device support 🥳

Hey @efstathiosntonas thanks 🙌 Its going to be soon there definitely. We are slowly migrating away from idb which will enable real device support.

georges commented 1 year ago

Ran into same issue today. Logitech GHub seems to be listening to port 9080 as well...

amanjeetsingh150 commented 1 year ago

This should be fixed now folks, feel free to download the new version of maestro. Feel free to reach out in case you find any issues.

Maestro version: 1.22.1

github-actions[bot] commented 1 month ago

This issue has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar problem, please file a new issue. Make sure to follow the template and provide all the information necessary to reproduce the issue. Thank you for helping keep us our issue tracker clean!