Skip to content
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

Espresso driver : Could not launch intent Intent #805

Open
Rjakubiec opened this issue Jul 27, 2022 · 2 comments
Open

Espresso driver : Could not launch intent Intent #805

Rjakubiec opened this issue Jul 27, 2022 · 2 comments

Comments

@Rjakubiec
Copy link

Tests
[email protected]
appium java-client 8.1.1
espresso-driver [email protected]

For some reason I am not able to start the activity using the espresso driver (I tried on 2 different applications and I get the same error every time)

With uiautomator2 driver tests works

Appium Serwer

[EspressoDriver@119a (06ed73ed)] Got response with status 500: {"id":"db079aaa-5839-4150-9054-e5bcae56b043","sessionId":null,"value":{"error":"session not created","message":"java.lang.RuntimeException: Could not launch intent Intent { act=ACTION_MAIN flg=0x14000000 cmp=com.example.compose_example/.MainActivity } within 45000 milliseconds. Perhaps the main thread has not gone idle within a reasonable amount of time? There could be an animation or something constantly repainting the screen. Or the activity is doing network calls on creation? See the threaddump logs. For your reference the last time the event queue was idle before your activity launch request was 1658925991593 and now the last time the queue went idle was: 1658925991593. If these numbers are the same your activity might be hogging the event queue.","stacktrace":"io.appium.espressoserver.lib.handlers.exceptions.SessionNotCreatedException: java.lang.RuntimeException: Could not launch intent Intent { act=ACTION_MAIN flg=0x14000000 cmp=com.example.compose_example/.MainActivity } within 45000 milliseconds. P...
[debug] [W3C] Matched W3C error code 'session not created' to SessionNotCreatedError
[debug] [EspressoDriver@119a (06ed73ed)] Deleting espresso session
[debug] [ADB] Running 'C:\Users\rjakubiec\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s 461c4771 shell dumpsys activity services io.appium.settings/.recorder.RecorderService'
[debug] [ADB] Running 'C:\Users\rjakubiec\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s 461c4771 shell am force-stop com.example.compose_example'
[debug] [EspressoDriver@119a (06ed73ed)] [Instrumentation] INSTRUMENTATION_RESULT: shortMsg=Process crashed.
[debug] [EspressoDriver@119a (06ed73ed)] INSTRUMENTATION_CODE: 0
[debug] [Logcat] Stopping logcat capture
[EspressoDriver@119a (06ed73ed)] Restoring hidden api policy to the device default configuration
[debug] [ADB] Running 'C:\Users\rjakubiec\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s 461c4771 shell 'settings delete global hidden_api_policy_pre_p_apps;settings delete global hidden_api_policy_p_apps;settings delete global hidden_api_policy''
[debug] [ADB] Removing forwarded port socket connection: 8300
[debug] [ADB] Running 'C:\Users\rjakubiec\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s 461c4771 forward --remove tcp:8300'
[debug] [AppiumDriver@7d00] Event 'newSessionStarted' logged at 1658926038214 (14:47:18 GMT+0200 (czas środkowoeuropejski letni))
[debug] [AppiumDriver@7d00] Encountered internal error running command: A new session could not be created. Details: java.lang.RuntimeException: Could not launch intent Intent { act=ACTION_MAIN flg=0x14000000 cmp=com.example.compose_example/.MainActivity } within 45000 milliseconds. Perhaps the main thread has not gone idle within a reasonable amount of time? There could be an animation or something constantly repainting the screen. Or the activity is doing network calls on creation? See the threaddump logs. For your reference the last time the event queue was idle before your activity launch request was 1658925991593 and now the last time the queue went idle was: 1658925991593. If these numbers are the same your activity might be hogging the event queue. Check https://github.com/appium/appium-espresso-driver#troubleshooting regarding advanced session startup troubleshooting.
[debug] [AppiumDriver@7d00] io.appium.espressoserver.lib.handlers.exceptions.SessionNotCreatedException: java.lang.RuntimeException: Could not launch intent Intent { act=ACTION_MAIN flg=0x14000000 cmp=com.example.compose_example/.MainActivity } within 45000 milliseconds. Perhaps the main thread has not gone idle within a reasonable amount of time? There could be an animation or something constantly repainting the screen. Or the activity is doing network calls on creation? See the threaddump logs. For your reference the last time the event queue was idle before your activity launch request was 1658925991593 and now the last time the queue went idle was: 1658925991593. If these numbers are the same your activity might be hogging the event queue.
[debug] [AppiumDriver@7d00]     at io.appium.espressoserver.lib.handlers.CreateSession.handleInternal(CreateSession.kt:54)
[debug] [AppiumDriver@7d00]     at io.appium.espressoserver.lib.handlers.CreateSession.handleInternal(CreateSession.kt:29)
[debug] [AppiumDriver@7d00]     at io.appium.espressoserver.lib.handlers.RequestHandler$DefaultImpls.handle(RequestHandler.kt:57)
[debug] [AppiumDriver@7d00]     at io.appium.espressoserver.lib.handlers.CreateSession.handle(CreateSession.kt:29)
[debug] [AppiumDriver@7d00]     at io.appium.espressoserver.lib.handlers.CreateSession.handle(CreateSession.kt:29)
[debug] [AppiumDriver@7d00]     at io.appium.espressoserver.lib.http.Router.route(Router.kt:229)
[debug] [AppiumDriver@7d00]     at io.appium.espressoserver.lib.http.Server.serve(Server.kt:51)
[debug] [AppiumDriver@7d00]     at fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:945)
[debug] [AppiumDriver@7d00]     at fi.iki.elonen.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:192)
[debug] [AppiumDriver@7d00]     at java.lang.Thread.run(Thread.java:923)
[debug] [AppiumDriver@7d00] Caused by: java.lang.RuntimeException: Could not launch intent Intent { act=ACTION_MAIN flg=0x14000000 cmp=com.example.compose_example/.MainActivity } within 45000 milliseconds. Perhaps the main thread has not gone idle within a reasonable amount of time? There could be an animation or something constantly repainting the screen. Or the activity is doing network calls on creation? See the threaddump logs. For your reference the last time the event queue was idle before your activity launch request was 1658925991593 and now the last time the queue went idle was: 1658925991593. If these numbers are the same your activity might be hogging the event queue.
[debug] [AppiumDriver@7d00]     at androidx.test.runner.MonitoringInstrumentation.startActivitySync(MonitoringInstrumentation.java:509)
[debug] [AppiumDriver@7d00]     at io.appium.espressoserver.lib.helpers.ActivityHelpers.startActivity(ActivityHelpers.kt:113)
[debug] [AppiumDriver@7d00]     at io.appium.espressoserver.lib.handlers.CreateSession.handleInternal(CreateSession.kt:43)
[debug] [AppiumDriver@7d00]     ... 9 more
[debug] [AppiumDriver@7d00]
[HTTP] <-- POST /wd/hub/session 500 85146 ms - 3364
[HTTP]
[EspressoDriver@119a] Instrumentation process exited with code 0 from signal null

App logcat

07-27 14:46:32.256 13086 13115 I appium  : Starting activity 'com.example.compose_example.MainActivity' with default options: {action=ACTION_MAIN, flags=ACTIVITY_NEW_TASK, className=com.example.compose_example.MainActivity}
07-27 14:46:32.285  1820  1839 I ActivityTaskManager: START u0 {act=ACTION_MAIN flg=0x14000000 cmp=com.example.compose_example/.MainActivity} from uid 10499
07-27 14:47:17.286 13086 13115 I appium  : Responding to server with error: {error=session not created, message=java.lang.RuntimeException: Could not launch intent Intent { act=ACTION_MAIN flg=0x14000000 cmp=com.example.compose_example/.MainActivity } within 45000 milliseconds. Perhaps the main thread has not gone idle within a reasonable amount of time? There could be an animation or something constantly repainting the screen. Or the activity is doing network calls on creation? See the threaddump logs. For your reference the last time the event queue was idle before your activity launch request was 1658925991593 and now the last time the queue went idle was: 1658925991593. If these numbers are the same your activity might be hogging the event queue., stacktrace=io.appium.espressoserver.lib.handlers.exceptions.SessionNotCreatedException: java.lang.RuntimeException: Could not launch intent Intent { act=ACTION_MAIN flg=0x14000000 cmp=com.example.compose_example/.MainActivity } within 45000 milliseconds. Perhaps the main thread has not gone idle within a reasonable amount of time? There could be an animation or something constantly repainting the screen. Or the activity is doing network calls on creation? See the threaddump logs. For your reference the last time the event queue was idle before your activity launch request was 1658925991593 and now the last time the queue went idle was: 1658925991593. If these numbers are the same your activity might be hogging the event queue.
07-27 14:47:17.286 13086 13115 I appium  : Caused by: java.lang.RuntimeException: Could not launch intent Intent { act=ACTION_MAIN flg=0x14000000 cmp=com.example.compose_example/.MainActivity } within 45000 milliseconds. Perhaps the main thread has not gone idle within a reasonable amount of time? There could be an animation or something constantly repainting the screen. Or the activity is doing network calls on creation? See the threaddump logs. For your reference the last time the event queue was idle before your activity launch request was 1658925991593 and now the last time the queue went idle was: 1658925991593. If these numbers are the same your activity might be hogging the event queue.
07-27 14:47:17.483  1820  3849 I ActivityManager: Force stopping com.example.compose_example appid=10499 user=0: from process:13192
07-27 14:47:17.487  1820  3849 I ActivityManager: Killing 13086:com.example.compose_example/u0a499 (adj 0): stop com.example.compose_example due to from process:13192
07-27 14:47:17.491  1820  3849 W ActivityManager: Crash of app com.example.compose_example running instrumentation ComponentInfo{io.appium.espressoserver.test/androidx.test.runner.AndroidJUnitRunner}
07-27 14:47:17.492  1820  3849 I ActivityManager: Force stopping com.example.compose_example appid=10499 user=0: finished inst
07-27 14:47:17.507 26311 26311 D AggregateListener: onPackageRestarted packageName:com.example.compose_example

Command works fine and starts the applications correctly

adb shell am start -n com.example.compose_example/.MainActivity
@cmaganu
Copy link
Contributor

cmaganu commented Jul 28, 2022

Hi!
If by starting this activity you are just trying to start the application, then you should try without starting/specifying the activity - remove the driver.startActivity(new Activity(PACKAGE, ACTIVITY)); part (or equivalent in the client you use).
It seems that the espresso driver starts the app(main activity) automatically somehow (from the apk that is specified) and by trying to explicitly start the main activity it tries to start the app a second time when the app is already running -> concurrency problems (the errors in logcat are not informative on this part).
At least that's how I managed to get over this "launch intent" problem.
@KazuCocoa I don't know if this is a bug or proper behaviour?

@KazuCocoa
Copy link
Member

for the original report:

Espresso and UIA2 have different logic to manage the app under test.
In Espresso driver, the app under test starts via the Espresso framework, not start directly. So adb shell am start -n com.example.compose_example/.MainActivity does not help.

So, within 45000 milliseconds. Perhaps the main thread has not gone xxx meant probably the app under test did not be idle when it started via espresso, so espresso waited for the app start. You could see adb shell am instrument xxx command to see how Espresso server was started over adb.


Correct. Basically, the app under test starts via Espresso (via instrument process). It is by design in https://developer.android.com/training/testing/espresso

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants