appium / appium

Cross-platform automation framework for all kinds of apps, built on top of the W3C WebDriver protocol
http://appium.io/
Apache License 2.0
18.63k stars 6.05k forks source link

Android driver fails before emulator is booted #17200

Closed jmalczak closed 2 years ago

jmalczak commented 2 years ago

The problem

When I use avd capability to start emulator, android driver fails even before emulator is booted up.

adb -P 5037 -s emulator-5554 shell 'settings delete global hidden_api_policy_pre_p_apps;settings delete global hidden_api_policy_p_apps;settings delete global hidden_api_policy'' exited with code 20'; Command output: cmd: Can't find service: settings
cmd: Can't find service: settings
cmd: Can't find service: settings

Environment

Details

Used capabilities

            appiumOptions.AddAdditionalAppiumOption(MobileCapabilityType.PlatformName, "Android");
            appiumOptions.AddAdditionalAppiumOption("appPackage", "appPackage");
            appiumOptions.AddAdditionalAppiumOption("appActivity", "SplashScreen");
            appiumOptions.AddAdditionalAppiumOption("avd", "Pixel_2_API_31");
            appiumOptions.AddAdditionalAppiumOption("avdArgs", "-no-snapshot-load");
            appiumOptions.AddAdditionalAppiumOption("androidInstallTimeout", 120000); 
            appiumOptions.AddAdditionalAppiumOption("newCommandTimeout", 120); 
            appiumOptions.AddAdditionalAppiumOption("acceptInsecureCerts", true); 
            appiumOptions.AddAdditionalAppiumOption("appWaitDuration", 60000);
            appiumOptions.AddAdditionalAppiumOption("avdLaunchTimeout", 180000); 
            appiumOptions.AddAdditionalAppiumOption("avdReadyTimeout", 180000); 

            var driver = new AndroidDriver(ap, appiumOptions); // initialize Android 

When AndroidDriver is instantiated, it starts android emulator, emulator starts booting, shows google logo, appium fails with error:

adb -P 5037 -s emulator-5554 shell 'settings delete global hidden_api_policy_pre_p_apps;settings delete global hidden_api_policy_p_apps;settings delete global hidden_api_policy'' exited with code 20'; Command output: cmd: Can't find service: settings
cmd: Can't find service: settings
cmd: Can't find service: settings

10 seconds later emulator is booted up to home screen properly. When I start emulator manually before running appium everything works just fine.

RSM-SBA commented 2 years ago

How long does the emulator need to start ? I also send some avd args to "optimize" the emulator maybe that helps -no-boot-anim -gpu auto -no-snapshot -no-audio -netfast -partition-size 4096 -cache-size 4000

mykola-mokhnach commented 2 years ago

Unfortunately we cannot help without full server log. It also makes sense to try the most recent driver version (only available with Appium 2).

As @StephanB75 mentioned this could be an issue with slow hardware, where emulator services require longer time to start while emulator itself is being reported as ready

jmalczak commented 2 years ago

Thanks for fast reply, really appreciate it! @mykola-mokhnach server logs https://gist.github.com/jmalczak/d1c3bfd3a9cb6afbd44b0bfa7a30a0e4. I have tried using params provided by @StephanB75 but without success. Emulator is quite fast, it starts in around 10 - 15s when cold booted.

RSM-SBA commented 2 years ago

Same problem with API 30 or 29 ? Is Android Studio and Emulator on latest version (cause there are some AVD warnings in the logs)

Also aren't the capabilities "appium:...." only for appium 2 ? @mykola-mokhnach are they also recognized by appium 1 ?

mykola-mokhnach commented 2 years ago

Thanks for fast reply, really appreciate it! @mykola-mokhnach server logs https://gist.github.com/jmalczak/d1c3bfd3a9cb6afbd44b0bfa7a30a0e4. I have tried using params provided by @StephanB75 but without success. Emulator is quite fast, it starts in around 10 - 15s when cold booted.

It anyway makes sense to try the most recent driver version. If that one still fails we could always add another condition to validate emulator boot and check if corresponding services are running

jmalczak commented 2 years ago

I have updated emulator and sdk to latest versions. Also removed appium 1.* and installed appium 2. Slightly different error https://gist.github.com/jmalczak/7569f656f402c3d828e2cab1c5499d1b now.

RSM-SBA commented 2 years ago

was there an appium settings app from the previous runs on the device ? image

Try to delete it so that appium can reinstall it. That helped me in the past when switching versions.

jmalczak commented 2 years ago

Hey @StephanB75 I did have appium settings from previous runs. I have deleted it and we are back to first error again https://gist.github.com/jmalczak/efa9e97f3fecb5e93afc185a5873242a

mykola-mokhnach commented 2 years ago

I've changed the boot detection logic - lets see if it helps

mykola-mokhnach commented 2 years ago

The patch has been published In uia2 driver 2.4.4

RSM-SBA commented 2 years ago

@mykola-mokhnach since the driver update i have some test that not recognize the emulator, but the emulator is started https://gist.github.com/StephanB75/9286642ef15bb9e987a1c38057869eac

In this test appium is starting the emulator. I have other test which are running, where the emulators are started before from jenkins scripts

Here another log from a testrun with android API Level 29 https://gist.github.com/StephanB75/a549843ff303aa9868dbabf31f4bd60a

mykola-mokhnach commented 2 years ago

@StephanB75 What is the actual output of the adb shell service list on the target emulator after the failure?

RSM-SBA commented 2 years ago

i don't know everything is shutting down immediatly after test is failed. I have to write this into the jenkins scripts. I will try it.

But i have tried now to start the emulator in the jenkins script before test starts, than it is detected

RSM-SBA commented 2 years ago

adb shell service list

API below 28 Found 100 services: 0 carrier_config: [com.android.internal.telephony.ICarrierConfigLoader] 1 phone: [com.android.internal.telephony.ITelephony] 2 isms: [com.android.internal.telephony.ISms] 3 iphonesubinfo: [com.android.internal.telephony.IPhoneSubInfo] 4 simphonebook: [com.android.internal.telephony.IIccPhoneBook] 5 isub: [com.android.internal.telephony.ISub] 6 telecom: [com.android.internal.telecom.ITelecomService] 7 imms: [com.android.internal.telephony.IMms] 8 media_projection: [android.media.projection.IMediaProjectionManager] 9 launcherapps: [android.content.pm.ILauncherApps] 10 fingerprint: [android.hardware.fingerprint.IFingerprintService] 11 trust: [android.app.trust.ITrustManager] 12 media_router: [android.media.IMediaRouterService] 13 media_session: [android.media.session.ISessionManager] 14 restrictions: [android.content.IRestrictionsManager] 15 print: [android.print.IPrintManager] 16 graphicsstats: [android.view.IGraphicsStats] 17 assetatlas: [android.view.IAssetAtlas] 18 dreams: [android.service.dreams.IDreamManager] 19 commontime_management: [] 20 samplingprofiler: [] 21 diskstats: [] 22 voiceinteraction: [com.android.internal.app.IVoiceInteractionManagerService] 23 appwidget: [com.android.internal.appwidget.IAppWidgetService] 24 backup: [android.app.backup.IBackupManager] 25 jobscheduler: [android.app.job.IJobScheduler] 26 serial: [android.hardware.ISerialManager] 27 usb: [android.hardware.usb.IUsbManager] 28 midi: [android.media.midi.IMidiManager] 29 DockObserver: [] 30 audio: [android.media.IAudioService] 31 wallpaper: [android.app.IWallpaperManager] 32 dropbox: [com.android.internal.os.IDropBoxManagerService] 33 search: [android.app.ISearchManager] 34 country_detector: [android.location.ICountryDetector] 35 location: [android.location.ILocationManager] 36 devicestoragemonitor: [] 37 notification: [android.app.INotificationManager] 38 updatelock: [android.os.IUpdateLock] 39 servicediscovery: [android.net.nsd.INsdManager] 40 connectivity: [android.net.IConnectivityManager] 41 rttmanager: [android.net.wifi.IRttManager] 42 wifiscanner: [android.net.wifi.IWifiScanner] 43 wifi: [android.net.wifi.IWifiManager] 44 wifip2p: [android.net.wifi.p2p.IWifiP2pManager] 45 netpolicy: [android.net.INetworkPolicyManager] 46 netstats: [android.net.INetworkStatsService] 47 network_score: [android.net.INetworkScoreService] 48 textservices: [com.android.internal.textservice.ITextServicesManager] 49 network_management: [android.os.INetworkManagementService] 50 clipboard: [android.content.IClipboard] 51 statusbar: [com.android.internal.statusbar.IStatusBarService] 52 device_policy: [android.app.admin.IDevicePolicyManager] 53 deviceidle: [android.os.IDeviceIdleController] 54 lock_settings: [com.android.internal.widget.ILockSettings] 55 uimode: [android.app.IUiModeManager] 56 mount: [IMountService] 57 accessibility: [android.view.accessibility.IAccessibilityManager] 58 input_method: [com.android.internal.view.IInputMethodManager] 59 media.radio: [android.hardware.IRadioService] 60 media.sound_trigger_hw: [android.hardware.ISoundTriggerHwService] 61 media.audio_policy: [android.media.IAudioPolicyService] 62 media.camera: [android.hardware.ICameraService] 63 input: [android.hardware.input.IInputManager] 64 window: [android.view.IWindowManager] 65 alarm: [android.app.IAlarmManager] 66 consumer_ir: [android.hardware.IConsumerIrService] 67 vibrator: [android.os.IVibratorService] 68 content: [android.content.IContentService] 69 account: [android.accounts.IAccountManager] 70 media.camera.proxy: [android.hardware.ICameraServiceProxy] 71 telephony.registry: [com.android.internal.telephony.ITelephonyRegistry] 72 scheduling_policy: [android.os.ISchedulingPolicyService] 73 webviewupdate: [android.webkit.IWebViewUpdateService] 74 usagestats: [android.app.usage.IUsageStatsManager] 75 battery: [] 76 sensorservice: [android.gui.SensorServer] 77 processinfo: [android.os.IProcessInfoService] 78 permission: [android.os.IPermissionController] 79 cpuinfo: [] 80 dbinfo: [] 81 gfxinfo: [] 82 meminfo: [] 83 procstats: [com.android.internal.app.IProcessStats] 84 activity: [android.app.IActivityManager] 85 user: [android.os.IUserManager] 86 package: [android.content.pm.IPackageManager] 87 android.service.gatekeeper.IGateKeeperService: [android.service.gatekeeper.IGateKeeperService] 88 android.hardware.fingerprint.IFingerprintDaemon: [android.hardware.fingerprint.IFingerprintDaemon] 89 display: [android.hardware.display.IDisplayManager] 90 power: [android.os.IPowerManager] 91 appops: [com.android.internal.app.IAppOpsService] 92 batterystats: [com.android.internal.app.IBatteryStats] 93 media.resource_manager: [android.media.IResourceManagerService] 94 media.player: [android.media.IMediaPlayerService] 95 media.audio_flinger: [android.media.IAudioFlinger] 96 drm.drmManager: [drm.IDrmManagerService] 97 android.security.keystore: [android.security.IKeystoreService] 98 batteryproperties: [android.os.IBatteryPropertiesRegistrar] 99 SurfaceFlinger: [android.ui.ISurfaceComposer]

API 28 Found 123 services: 0 carrier_config: [com.android.internal.telephony.ICarrierConfigLoader] 1 phone: [com.android.internal.telephony.ITelephony] 2 isms: [com.android.internal.telephony.ISms] 3 iphonesubinfo: [com.android.internal.telephony.IPhoneSubInfo] 4 simphonebook: [com.android.internal.telephony.IIccPhoneBook] 5 isub: [com.android.internal.telephony.ISub] 6 telecom: [com.android.internal.telecom.ITelecomService] 7 contexthub: [android.hardware.location.IContextHubService] 8 netd_listener: [android.net.metrics.INetdEventListener] 9 connmetrics: [android.net.IIpConnectivityMetrics] 10 autofill: [android.view.autofill.IAutoFillManager] 11 imms: [com.android.internal.telephony.IMms] 12 media.camera.proxy: [android.hardware.ICameraServiceProxy] 13 media_projection: [android.media.projection.IMediaProjectionManager] 14 launcherapps: [android.content.pm.ILauncherApps] 15 shortcut: [android.content.pm.IShortcutService] 16 fingerprint: [android.hardware.fingerprint.IFingerprintService] 17 media_router: [android.media.IMediaRouterService] 18 media_resource_monitor: [android.media.IMediaResourceMonitor] 19 media_session: [android.media.session.ISessionManager] 20 restrictions: [android.content.IRestrictionsManager] 21 print: [android.print.IPrintManager] 22 graphicsstats: [android.view.IGraphicsStats] 23 dreams: [android.service.dreams.IDreamManager] 24 commontime_management: [] 25 network_time_update_service: [] 26 diskstats: [] 27 voiceinteraction: [com.android.internal.app.IVoiceInteractionManagerService] 28 appwidget: [com.android.internal.appwidget.IAppWidgetService] 29 backup: [android.app.backup.IBackupManager] 30 trust: [android.app.trust.ITrustManager] 31 soundtrigger: [com.android.internal.app.ISoundTriggerService] 32 jobscheduler: [android.app.job.IJobScheduler] 33 hardware_properties: [android.os.IHardwarePropertiesManager] 34 serial: [android.hardware.ISerialManager] 35 usb: [android.hardware.usb.IUsbManager] 36 midi: [android.media.midi.IMidiManager] 37 DockObserver: [] 38 audio: [android.media.IAudioService] 39 wallpaper: [android.app.IWallpaperManager] 40 search: [android.app.ISearchManager] 41 country_detector: [android.location.ICountryDetector] 42 location: [android.location.ILocationManager] 43 devicestoragemonitor: [] 44 notification: [android.app.INotificationManager] 45 updatelock: [android.os.IUpdateLock] 46 servicediscovery: [android.net.nsd.INsdManager] 47 connectivity: [android.net.IConnectivityManager] 48 rttmanager: [android.net.wifi.IRttManager] 49 wifiscanner: [android.net.wifi.IWifiScanner] 50 wifi: [android.net.wifi.IWifiManager] 51 netpolicy: [android.net.INetworkPolicyManager] 52 netstats: [android.net.INetworkStatsService] 53 network_score: [android.net.INetworkScoreService] 54 textservices: [com.android.internal.textservice.ITextServicesManager] 55 network_management: [android.os.INetworkManagementService] 56 clipboard: [android.content.IClipboard] 57 statusbar: [com.android.internal.statusbar.IStatusBarService] 58 device_policy: [android.app.admin.IDevicePolicyManager] 59 deviceidle: [android.os.IDeviceIdleController] 60 lock_settings: [com.android.internal.widget.ILockSettings] 61 uimode: [android.app.IUiModeManager] 62 storagestats: [android.app.usage.IStorageStatsManager] 63 mount: [android.os.storage.IStorageManager] 64 accessibility: [android.view.accessibility.IAccessibilityManager] 65 input_method: [com.android.internal.view.IInputMethodManager] 66 pinner: [] 67 vrmanager: [android.service.vr.IVrManager] 68 input: [android.hardware.input.IInputManager] 69 window: [android.view.IWindowManager] 70 alarm: [android.app.IAlarmManager] 71 consumer_ir: [android.hardware.IConsumerIrService] 72 vibrator: [android.os.IVibratorService] 73 settings: [] 74 content: [android.content.IContentService] 75 account: [android.accounts.IAccountManager] 76 overlay: [android.content.om.IOverlayManager] 77 telephony.registry: [com.android.internal.telephony.ITelephonyRegistry] 78 scheduling_policy: [android.os.ISchedulingPolicyService] 79 sec_key_att_app_id_provider: [android.security.keymaster.IKeyAttestationApplicationIdProvider] 80 webviewupdate: [android.webkit.IWebViewUpdateService] 81 usagestats: [android.app.usage.IUsageStatsManager] 82 sensorservice: [android.gui.SensorServer] 83 battery: [] 84 dropbox: [com.android.internal.os.IDropBoxManagerService] 85 processinfo: [android.os.IProcessInfoService] 86 permission: [android.os.IPermissionController] 87 cpuinfo: [] 88 dbinfo: [] 89 gfxinfo: [] 90 meminfo: [] 91 procstats: [com.android.internal.app.procstats.IProcessStats] 92 activity: [android.app.IActivityManager] 93 user: [android.os.IUserManager] 94 otadexopt: [android.content.pm.IOtaDexopt] 95 package_native: [android.content.pm.IPackageManagerNative] 96 package: [android.content.pm.IPackageManager] 97 display: [android.hardware.display.IDisplayManager] 98 recovery: [android.os.IRecoverySystem] 99 power: [android.os.IPowerManager] 100 appops: [com.android.internal.app.IAppOpsService] 101 batterystats: [com.android.internal.app.IBatteryStats] 102 device_identifiers: [android.os.IDeviceIdentifiersPolicyService] 103 netd: [] 104 media.sound_trigger_hw: [android.hardware.ISoundTriggerHwService] 105 media.audio_policy: [android.media.IAudioPolicyService] 106 media.camera: [android.hardware.ICameraService] 107 media.audio_flinger: [android.media.IAudioFlinger] 108 drm.drmManager: [drm.IDrmManagerService] 109 media.metrics: [android.media.IMediaAnalyticsService] 110 media.extractor: [android.media.IMediaExtractorService] 111 media.resource_manager: [android.media.IResourceManagerService] 112 media.player: [android.media.IMediaPlayerService] 113 wificond: [] 114 storaged: [Storaged] 115 android.service.gatekeeper.IGateKeeperService: [] 116 media.drm: [android.media.IMediaDrmService] 117 android.security.keystore: [android.security.IKeystoreService] 118 installd: [] 119 gpu: [android.ui.IGpuService] 120 SurfaceFlinger: [android.ui.ISurfaceComposer] 121 thermalservice: [android.os.IThermalService] 122 batteryproperties: [android.os.IBatteryPropertiesRegistrar]

mykola-mokhnach commented 2 years ago

@StephanB75 Try uia2 driver v. 2.4.5

RSM-SBA commented 2 years ago

@StephanB75 Try uia2 driver v. 2.4.5

Seems to work now :) Thank you for the quick fix 👍

jmalczak commented 2 years ago

@mykola-mokhnach thanks, looks like it works most of the time for me as well. Sometimes I still get Error: Appium Settings app is not running after 5000ms, it's not very often though but it happens. Is there any switch where i can increase this 5000ms timeout?

Thanks!

mykola-mokhnach commented 2 years ago

I'm afraid the timeout there is hardcoded. Although I don't see a reason it could not be increased

mykola-mokhnach commented 2 years ago

Closed as fixed

amrsa1 commented 1 year ago

@mykola-mokhnach

Im getting the same error, when running test against emulator using appium 2 and latest UIautomator plugin

An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: 'Command '/Users/runner/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell 'settings delete global hidden_api_policy_pre_p_apps;settings delete global hidden_api_policy_p_apps;settings delete global hidden_api_policy'' exited with code 20'; Command output: cmd: Can't find service: settings
[0-0] cmd: Can't find service: settings
[0-0] cmd: Can't find service: settings
 alwaysMatch: {
[0-0]       'appium:platformName': 'android',
[0-0]       'appium:deviceName': 'nexus',
[0-0]       'appium:app': './src/test/api.apk',
[0-0]       'appium:platformVersion': '13',
[0-0]       'appium:uiautomator2ServerInstallTimeout': 150000,
[0-0]       'appium:appWaitForLaunch': true,
[0-0]       'appium:disableWindowAnimation': true,
[0-0]       'appium:autoGrantPermissions': true,
[0-0]       'appium:clearSystemFiles': true,
[0-0]       'appium:nativeWebScreenshot': true,
[0-0]       'appium:adbExecTimeout': 80000,
[0-0]       'appium:automationName': 'uiautomator2'
[0-0]     },