Why on my virtual android device, when the app is opened, it closes automatically again. This is a recurring error for me on different devices I have.
The video I recorded of that situation:
Error in terminal script:
WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: socket hang up
Appium logs:
[HTTP] --> POST /wd/hub/session
[HTTP] {"capabilities":{"firstMatch":[{"platformName":"Android","appium:deviceName":"Android","appium:automationName":"UiAutomator2","appium:udid":"emulator-5556"}]},"desiredCapabilities":{"platformName":"Android","deviceName":"Android","automationName":"UiAutomator2","udid":"emulator-5556"}}
[W3C] Calling AppiumDriver.createSession() with args: [{"platformName":"Android","deviceName":"Android","automationName":"UiAutomator2","udid":"emulator-5556"},null,{"firstMatch":[{"platformName":"Android","appium:deviceName":"Android","appium:automationName":"UiAutomator2","appium:udid":"emulator-5556"}]}]
[BaseDriver] Event 'newSessionRequested' logged at 1706945526064 (11:02:06 GMT+0330 (Iran Standard Time))
[Appium] Appium v1.22.3 creating new AndroidUiautomator2Driver (v1.70.1) session
[Appium] Applying relaxed security to 'AndroidUiautomator2Driver' as per server command line argument. All insecure features will be enabled unless explicitly disabled by --deny-insecure
[BaseDriver] W3C capabilities and MJSONWP desired capabilities were provided
[BaseDriver] Creating session with W3C capabilities: {
[BaseDriver] "alwaysMatch": {
[BaseDriver] "platformName": "Android",
[BaseDriver] "appium:deviceName": "Android",
[BaseDriver] "appium:automationName": "UiAutomator2",
[BaseDriver] "appium:udid": "emulator-5556"
[BaseDriver] },
[BaseDriver] "firstMatch": [
[BaseDriver] {}
[BaseDriver] ]
[BaseDriver] }
[BaseDriver] Session created with session id: b697bc9f-318e-4d86-b2df-7ef7d69103ba
[UiAutomator2] Neither 'app' nor 'appPackage' was set. Starting UiAutomator2 without the target application
[ADB] Using 'adb' from '/Users/amir/Library/Android/sdk/platform-tools/adb'
[ADB] Running '/Users/amir/Library/Android/sdk/platform-tools/adb -P 5037 start-server'
[AndroidDriver] Retrieving device list
[ADB] Trying to find a connected android device
[ADB] Getting connected devices
[ADB] Connected devices: [{"udid":"emulator-5554","state":"device"},{"udid":"emulator-5556","state":"device"}]
[AndroidDriver] Using device: emulator-5556
[ADB] Using 'adb' from '/Users/amir/Library/Android/sdk/platform-tools/adb'
[ADB] Running '/Users/amir/Library/Android/sdk/platform-tools/adb -P 5037 start-server'
[ADB] Setting device id to emulator-5556
[ADB] Running '/Users/amir/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5556 shell getprop ro.build.version.sdk'
[Instrumentation] io.appium.uiautomator2.server.test.AppiumUiAutomator2Server:
[ADB] Current device property 'ro.build.version.sdk': 34
[ADB] Getting device platform version
[ADB] Running '/Users/amir/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5556 shell getprop ro.build.version.release'
[ADB] Current device property 'ro.build.version.release': 14
[ADB] Device API level: 34
[UiAutomator2] Relaxing hidden api policy
[ADB] Running '/Users/amir/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5556 shell 'settings put global hidden_api_policy_pre_p_apps 1;settings put global hidden_api_policy_p_apps 1;settings put global hidden_api_policy 1''
[AndroidDriver] No app sent in, not parsing package/activity
[ADB] Running '/Users/amir/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5556 wait-for-device'
[ADB] Running '/Users/amir/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5556 shell echo ping'
[AndroidDriver] Pushing settings apk to device...
[ADB] Getting install status for io.appium.settings
[ADB] Running '/Users/amir/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5556 shell dumpsys package io.appium.settings'
[ADB] 'io.appium.settings' is installed
[ADB] Getting package info for 'io.appium.settings'
[ADB] Running '/Users/amir/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5556 shell dumpsys package io.appium.settings'
[ADB] The version code of the installed 'io.appium.settings' is greater than the application version code (60 > 30)
[ADB] There is no need to downgrade 'io.appium.settings'
[ADB] Getting IDs of all 'io.appium.settings' processes
[ADB] Running '/Users/amir/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5556 shell 'pgrep --help; echo $?''
[ADB] Running '/Users/amir/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5556 shell pgrep -f \(\[\[:blank:\]\]\|\^\)io\.appium\.settings\(\[\[:blank:\]\]\|\$\)'
[AndroidDriver] io.appium.settings is already running. There is no need to reset its permissions.
[Logcat] Starting logs capture with command: /Users/amir/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5556 logcat -v threadtime
[UiAutomator2] Forwarding UiAutomator2 Server port 6790 to local port 8203
[ADB] Forwarding system: 8203 to device: 6790
[ADB] Running '/Users/amir/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5556 forward tcp:8203 tcp:6790'
[ADB] Getting install status for io.appium.uiautomator2.server
[ADB] Running '/Users/amir/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5556 shell dumpsys package io.appium.uiautomator2.server'
[ADB] 'io.appium.uiautomator2.server' is installed
[ADB] Getting package info for 'io.appium.uiautomator2.server'
[ADB] Running '/Users/amir/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5556 shell dumpsys package io.appium.uiautomator2.server'
[ADB] The version name of the installed 'io.appium.uiautomator2.server' is greater or equal to the application version name ('4.27.0' >= '4.27.0')
[UiAutomator2] io.appium.uiautomator2.server installation state: sameVersionInstalled
[ADB] Checking app cert for /Applications/Appium Server GUI copy.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v4.27.0.apk
[ADB] Using the previously cached signature entry for 'appium-uiautomator2-server-v4.27.0.apk'
[ADB] sha256 hash did match for 'appium-uiautomator2-server-v4.27.0.apk'
[ADB] Getting install status for io.appium.uiautomator2.server.test
[ADB] Running '/Users/amir/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5556 shell dumpsys package io.appium.uiautomator2.server.test'
[ADB] 'io.appium.uiautomator2.server.test' is installed
[ADB] Checking app cert for /Applications/Appium Server GUI copy.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk
[ADB] Using the previously cached signature entry for 'appium-uiautomator2-server-debug-androidTest.apk'
[ADB] sha256 hash did match for 'appium-uiautomator2-server-debug-androidTest.apk'
[UiAutomator2] Server packages are not going to be (re)installed
[UiAutomator2] Waiting up to 30000ms for services to be available
[ADB] Running '/Users/amir/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5556 shell pm list instrumentation'
[UiAutomator2] Instrumentation target 'io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner' is available
[ADB] Adding packages ["io.appium.settings","io.appium.uiautomator2.server","io.appium.uiautomator2.server.test"] to Doze whitelist
[ADB] Got the following command chunks to execute: [["dumpsys","deviceidle","whitelist","+io.appium.settings",";","dumpsys","deviceidle","whitelist","+io.appium.uiautomator2.server",";","dumpsys","deviceidle","whitelist","+io.appium.uiautomator2.server.test",";"]]
[ADB] Running '/Users/amir/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5556 shell dumpsys deviceidle whitelist +io.appium.settings ; dumpsys deviceidle whitelist +io.appium.uiautomator2.server ; dumpsys deviceidle whitelist +io.appium.uiautomator2.server.test ;'
[UiAutomator2] No app capability. Assuming it is already on the device
[UiAutomator2] Performing shallow cleanup of automation leftovers
[UiAutomator2] No obsolete sessions have been detected
[ADB] Running '/Users/amir/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5556 shell am force-stop io.appium.uiautomator2.server.test'
[UiAutomator2] Starting UIAutomator2 server 4.27.0
[UiAutomator2] Using UIAutomator2 server from '/Applications/Appium Server GUI copy.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v4.27.0.apk' and test from '/Applications/Appium Server GUI copy.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk'
[UiAutomator2] Waiting up to 30000ms for UiAutomator2 to be online...
[ADB] Creating ADB subprocess with args: ["-P",5037,"-s","emulator-5556","shell","am","instrument","-w","-e","disableAnalytics",true,"io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner"]
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8203/wd/hub/status] with no body
[WD Proxy] Got response with status 200: {"sessionId":"None","value":{"message":"UiAutomator2 Server is ready to accept commands","ready":true}}
[UiAutomator2] The initialization of the instrumentation process took 44ms
[WD Proxy] Matched '/session' to command name 'createSession'
[WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8203/wd/hub/session] with body: {"capabilities":{"firstMatch":[{"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformName":"Android","deviceName":"Android","automationName":"UiAutomator2","udid":"emulator-5556"},"platformName":"Android","deviceName":"emulator-5556","automationName":"UiAutomator2","udid":"emulator-5556","deviceUDID":"emulator-5556"}],"alwaysMatch":{}}}
[WD Proxy] Got response with status 200: {"sessionId":"944fae6f-aba9-4184-9c0a-aaeb89806753","value":{"capabilities":{"firstMatch":[{"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformName":"Android","deviceName":"Android","automationName":"UiAutomator2","udid":"emulator-5556"},"platformName":"Android","deviceName":"emulator-5556","automationName":"UiAutomator2","udid":"emulator-5556","deviceUDID":"emulator-5556"}],"alwaysMatch":{}},"sessionId":"944fae6f-aba9-4184-9c0a-aaeb89806753"}}
[WD Proxy] Determined the downstream protocol as 'W3C'
[WD Proxy] Proxying [GET /appium/device/info] to [GET http://127.0.0.1:8203/wd/hub/session/944fae6f-aba9-4184-9c0a-aaeb89806753/appium/device/info] with no body
[WD Proxy] Got response with status 200: {"sessionId":"944fae6f-aba9-4184-9c0a-aaeb89806753","value":{"androidId":"96d51743aeda4692","apiVersion":"34","bluetooth":{"state":"OFF"},"brand":"google","carrierName":"T-Mobile","displayDensity":420,"locale":"en_US","manufacturer":"Google","model":"sdk_gphone64_x86_64","networks":[{"capabilities":{"SSID":null,"linkDownBandwidthKbps":30000,"linkUpstreamBandwidthKbps":12000,"networkCapabilities":"NET_CAPABILITY_NOT_METERED,NET_CAPABILITY_INTERNET,NET_CAPABILITY_NOT_RESTRICTED,NET_CAPABILITY_TRUSTED,NET_CAPABILITY_NOT_VPN,NET_CAPABILITY_VALIDATED,NET_CAPABILITY_NOT_ROAMING,NET_CAPABILITY_FOREGROUND,NET_CAPABILITY_NOT_CONGESTED,NET_CAPABILITY_NOT_SUSPENDED","signalStrength":-50,"transportTypes":"TRANSPORT_WIFI"},"detailedState":"CONNECTED","extraInfo":"","isAvailable":true,"isConnected":true,"isFailover":false,"isRoaming":false,"state":"CONNECTED","subtype":-1,"subtypeName":"","type":1,"typeName":"WIFI"},{"capabilities":{"SSID":null,"linkDownBandwidthKbps":30000,"linkUpstreamBandwidthKbps":15000,"networkCapa...
[ADB] Running '/Users/amir/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5556 shell dumpsys window'
[AndroidDriver] Screen already unlocked, doing nothing
[WD Proxy] Proxying [GET /appium/device/pixel_ratio] to [GET http://127.0.0.1:8203/wd/hub/session/944fae6f-aba9-4184-9c0a-aaeb89806753/appium/device/pixel_ratio] with no body
[WD Proxy] Got response with status 200: {"sessionId":"944fae6f-aba9-4184-9c0a-aaeb89806753","value":2.625}
[WD Proxy] Matched '/appium/device/system_bars' to command name 'getSystemBars'
[WD Proxy] Proxying [GET /appium/device/system_bars] to [GET http://127.0.0.1:8203/wd/hub/session/944fae6f-aba9-4184-9c0a-aaeb89806753/appium/device/system_bars] with no body
[WD Proxy] Got response with status 200: {"sessionId":"944fae6f-aba9-4184-9c0a-aaeb89806753","value":{"statusBar":136}}
[WD Proxy] Matched '/window/current/size' to command name 'getWindowSize'
[WD Proxy] Proxying [GET /window/current/size] to [GET http://127.0.0.1:8203/wd/hub/session/944fae6f-aba9-4184-9c0a-aaeb89806753/window/current/size] with no body
[WD Proxy] Got response with status 200: {"sessionId":"944fae6f-aba9-4184-9c0a-aaeb89806753","value":{"height":2201,"width":1080}}
[Appium] New AndroidUiautomator2Driver session created successfully, session b697bc9f-318e-4d86-b2df-7ef7d69103ba added to master session list
[BaseDriver] Event 'newSessionStarted' logged at 1706945530978 (11:02:10 GMT+0330 (Iran Standard Time))
[W3C (b697bc9f)] Cached the protocol value 'W3C' for the new session b697bc9f-318e-4d86-b2df-7ef7d69103ba
[W3C (b697bc9f)] Responding to client with driver.createSession() result: {"capabilities":{"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformName":"Android","deviceName":"Android","automationName":"UiAutomator2","udid":"emulator-5556"},"platformName":"Android","deviceName":"emulator-5556","automationName":"UiAutomator2","udid":"emulator-5556","deviceUDID":"emulator-5556","deviceApiLevel":34,"platformVersion":"14","deviceScreenSize":"1080x2400","deviceScreenDensity":420,"deviceModel":"sdk_gphone64_x86_64","deviceManufacturer":"Google","pixelRatio":2.625,"statBarHeight":136,"viewportRect":{"left":0,"top":136,"width":1080,"height":2065}}}
[HTTP] <-- POST /wd/hub/session 200 4917 ms - 794
[HTTP]
[HTTP] --> POST /wd/hub/session/b697bc9f-318e-4d86-b2df-7ef7d69103ba/element
[HTTP] {"using":"id","value":"android:id/aerr_close"}
[W3C (b697bc9f)] Calling AppiumDriver.findElement() with args: ["id","android:id/aerr_close","b697bc9f-318e-4d86-b2df-7ef7d69103ba"]
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, css selector, -android uiautomator
[BaseDriver] Waiting up to 0 ms for condition
[WD Proxy] Matched '/element' to command name 'findElement'
[WD Proxy] Proxying [POST /element] to [POST http://127.0.0.1:8203/wd/hub/session/944fae6f-aba9-4184-9c0a-aaeb89806753/element] with body: {"strategy":"id","selector":"android:id/aerr_close","context":"","multiple":false}
[WD Proxy] Got response with status 404: {"sessionId":"944fae6f-aba9-4184-9c0a-aaeb89806753","value":{"error":"no such element","message":"An element could not be located on the page using the given search parameters","stacktrace":"io.appium.uiautomator2.common.exceptions.ElementNotFoundException: An element could not be located on the page using the given search parameters\n\tat io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:70)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:59)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:266)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:260)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:68)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.chann...
[W3C] Matched W3C error code 'no such element' to NoSuchElementError
[W3C (b697bc9f)] Encountered internal error running command: NoSuchElementError: An element could not be located on the page using the given search parameters.
[W3C (b697bc9f)] at AndroidUiautomator2Driver.findElOrEls (/Applications/Appium Server GUI copy.app/Contents/Resources/app/node_modules/appium/node_modules/appium-android-driver/lib/commands/find.js:75:11)
[W3C (b697bc9f)] at runMicrotasks ()
[W3C (b697bc9f)] at processTicksAndRejections (internal/process/task_queues.js:97:5)
[W3C (b697bc9f)] at AndroidUiautomator2Driver.findElOrElsWithProcessing (/Applications/Appium Server GUI copy.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/commands/find.js:33:12)
[W3C (b697bc9f)] at AndroidUiautomator2Driver.findElement (/Applications/Appium Server GUI copy.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/commands/find.js:53:10)
[HTTP] <-- POST /wd/hub/session/b697bc9f-318e-4d86-b2df-7ef7d69103ba/element 404 151 ms - 963
[HTTP]
[Instrumentation] INSTRUMENTATION_RESULT: shortMsg=Process crashed.
[Instrumentation] INSTRUMENTATION_CODE: 0
[Instrumentation] The process has exited with code 0
[HTTP] --> POST /wd/hub/session/b697bc9f-318e-4d86-b2df-7ef7d69103ba/element
[HTTP] {"using":"id","value":"android:id/aerr_close"}
[W3C (b697bc9f)] Calling AppiumDriver.findElement() with args: ["id","android:id/aerr_close","b697bc9f-318e-4d86-b2df-7ef7d69103ba"]
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, css selector, -android uiautomator
[BaseDriver] Waiting up to 0 ms for condition
[WD Proxy] Matched '/element' to command name 'findElement'
[WD Proxy] Proxying [POST /element] to [POST http://127.0.0.1:8203/wd/hub/session/944fae6f-aba9-4184-9c0a-aaeb89806753/element] with body: {"strategy":"id","selector":"android:id/aerr_close","context":"","multiple":false}
[WD Proxy] socket hang up
[W3C (b697bc9f)] Encountered internal error running command: UnknownError: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: socket hang up
[W3C (b697bc9f)] at UIA2Proxy.command (/Applications/Appium Server GUI copy.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/jsonwp-proxy/proxy.js:274:13)
[W3C (b697bc9f)] at runMicrotasks ()
[W3C (b697bc9f)] at processTicksAndRejections (internal/process/task_queues.js:97:5)
[W3C (b697bc9f)] at AndroidUiautomator2Driver.helpers.doFindElementOrEls (/Applications/Appium Server GUI copy.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-driver/lib/commands/find.js:32:12)
[W3C (b697bc9f)] at doFind (/Applications/Appium Server GUI copy.app/Contents/Resources/app/node_modules/appium/node_modules/appium-android-driver/lib/commands/find.js:36:17)
[W3C (b697bc9f)] at wrappedCondFn (/Applications/Appium Server GUI copy.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/commands/timeout.js:151:12)
[W3C (b697bc9f)] at spin (/Applications/Appium Server GUI copy.app/Contents/Resources/app/node_modules/appium/node_modules/asyncbox/lib/asyncbox.js:138:20)
[W3C (b697bc9f)] at waitForCondition (/Applications/Appium Server GUI copy.app/Contents/Resources/app/node_modules/appium/node_modules/asyncbox/lib/asyncbox.js:155:10)
[W3C (b697bc9f)] at AndroidUiautomator2Driver.implicitWaitForCondition (/Applications/Appium Server GUI copy.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/commands/timeout.js:153:10)
[W3C (b697bc9f)] at AndroidUiautomator2Driver.findElOrEls (/Applications/Appium Server GUI copy.app/Contents/Resources/app/node_modules/appium/node_modules/appium-android-driver/lib/commands/find.js:60:5)
[W3C (b697bc9f)] at AndroidUiautomator2Driver.findElOrElsWithProcessing (/Applications/Appium Server GUI copy.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/commands/find.js:33:12)
[W3C (b697bc9f)] at AndroidUiautomator2Driver.findElement (/Applications/Appium Server GUI copy.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/commands/find.js:53:10)
[HTTP] <-- POST /wd/hub/session/b697bc9f-318e-4d86-b2df-7ef7d69103ba/element 500 23 ms - 2373
[HTTP]
[Instrumentation] io.appium.uiautomator2.server.test.AppiumUiAutomator2Server: