Search code examples
androidappium

Run Chrome on emulator with appium?


I have somme issues when I am trying to run Chrome on emulator device with appium. I am pretty sure that Chrome is not installed on my emulator, but not 100% sure that is the case, and if it is how to fix it.

Currently mu Appim server logs looks like:

[debug] [ADB] Running '/Users/test/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys deviceidle whitelist +io.appium.settings ; dumpsys deviceidle whitelist +io.appium.uiautomator2.server ; dumpsys deviceidle whitelist +io.appium.uiautomator2.server.test ;'
[debug] [UiAutomator2] No app capability. Assuming it is already on the device
[debug] [ADB] Getting install status for com.android.chrome
[debug] [ADB] Running '/Users/test/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys package com.android.chrome'
[debug] [ADB] 'com.android.chrome' is not installed
[debug] [UiAutomator2] Deleting UiAutomator2 session
[debug] [UiAutomator2] Deleting UiAutomator2 server session
[debug] [WD Proxy] Matched '/' to command name 'deleteSession'
[UiAutomator2] Did not get confirmation UiAutomator2 deleteSession worked; Error was: UnknownError: An unknown server-side error occurred while processing the command. Original error: Trying to proxy a session command without session id
[debug] [Logcat] Stopping logcat capture
[debug] [ADB] Removing forwarded port socket connection: 8207 
[debug] [ADB] Running '/Users/test/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 forward --remove tcp:8207'
[UiAutomator2] Restoring hidden api policy to the device default configuration
[debug] [ADB] Running '/Users/test/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''
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1634917808720 (17:50:08 GMT+0200 (Central European Summer Time))
[debug] [W3C] Encountered internal error running command: Error: 'app' option is required for reinstall
[debug] [W3C]     at Object.resetApp (/usr/local/lib/node_modules/appium/node_modules/appium-android-driver/lib/android-helpers.js:392:11)
[debug] [W3C]     at AndroidUiautomator2Driver.initAUT (/usr/local/lib/node_modules/appium/node_modules/appium-uiautomator2-driver/lib/driver.js:546:9)
[debug] [W3C]     at AndroidUiautomator2Driver.startUiAutomator2Session (/usr/local/lib/node_modules/appium/node_modules/appium-uiautomator2-driver/lib/driver.js:408:5)
[debug] [W3C]     at AndroidUiautomator2Driver.createSession (/usr/local/lib/node_modules/appium/node_modules/appium-uiautomator2-driver/lib/driver.js:229:7)
[debug] [W3C]     at AppiumDriver.createSession (/usr/local/lib/node_modules/appium/lib/appium.js:387:35)

And the code which I am using is:

DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "EmulatorName");
cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");
cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
cap.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
cap.setCapability("appium:chromeOptions", ImmutableMap.of("w3c", false));
cap.setCapability("chromedriverExecutable", "/Users/test/Downloads/chromedriver");


driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), cap);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

Solution

  • If Appium cannot find the application, It tries to install it on the device. So it is important to add the App variable in your desired capabilities with the location of the APK file. This line shows that Appium tried to install the chrome on the device but couldn't find the APP variable in the Caps.

    Encountered internal error running the command: Error: 'app' option is required for reinstall

    Just add this to your caps:

    cap.setCapability(MobileCapabilityType.APP, "APK PATH OF CHROME");