automation – Unable to launch Calculator app on real android device using Appium

I am new to mobile automation and learning it using Appium on a real android device. I am just trying to open Calculator app on my android device. However I am unable to launch it. Below are the required code, Appium logs for the reference. Could you please let me know what wrong I am doing here.

PS: I have already checked many posts on stack overflow but none resolved my issue. Hence posting it here.

Thanks in advance

public class CalculatorTest {

    static AndroidDriver driver;

    public static void main(String[] args) {

        try {
            openCalculator();
        } catch (Exception e) {
            //System.out.println(e.getCause());
            System.out.println(e.getMessage());
            e.printStackTrace();
        }

    }

    public static void openCalculator() throws Exception {

        //Setting mobile capabilities
        DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
        desiredCapabilities.setCapability("deviceName", "Redmi 6 Pro");
        desiredCapabilities.setCapability("udid","0986fbcd0805");
        desiredCapabilities.setCapability("platformName","Android");
        desiredCapabilities.setCapability("platformVersion","9 PKQ1.180917.001");
        desiredCapabilities.setCapability("appPackage","com.miui.calculator");
        desiredCapabilities.setCapability("appActivity","com.miui.calculator.cal.CalculatorActivity");

        //Setting Url
        URL url = new URL("http://127.0.0.1:4723/wd/hub");

        //setting driver
        driver = new AndroidDriver(url,desiredCapabilities);
        System.out.println("application started");
    }
}
=============================================================================================
Appium Logs:
    C:Usersahmed>appium --session-override
    [Appium] Welcome to Appium v1.22.3
    [Appium] Non-default server args:
    [Appium]   sessionOverride: true
    [Appium] Appium REST http interface listener started on 0.0.0.0:4723
    [debug] [HTTP] Request idempotency key: d305fc02-d9b3-4cd4-9eba-49c2433cf199
    [HTTP] --> POST /wd/hub/session
    [HTTP] {"capabilities":{"firstMatch":[{}],"alwaysMatch":{"appium:appActivity":"com.miui.calculator.cal.CalculatorActivity","appium:appPackage":"com.miui.calculator","appium:deviceName":"Redmi 6 Pro","appium:platformVersion":"9 PKQ1.180917.001","appium:udid":"0986fbcd0805","platformName":"android"}}}
    [debug] [W3C] Calling AppiumDriver.createSession() with args: [null,null,{"firstMatch":[{}],"alwaysMatch":{"appium:appActivity":"com.miui.calculator.cal.CalculatorActivity","appium:appPackage":"com.miui.calculator","appium:deviceName":"Redmi 6 Pro","appium:platformVersion":"9 PKQ1.180917.001","appium:udid":"0986fbcd0805","platformName":"android"}}]
    [debug] [BaseDriver] Event 'newSessionRequested' logged at 1654167042557 (16:20:42 GMT+0530 (India Standard Time))
    [Appium]
    [Appium] ======================================================================
    [Appium]   DEPRECATION WARNING:
    [Appium]
    [Appium]   The 'automationName' capability was not provided in the desired
    [Appium]   capabilities for this Android session
    [Appium]
    [Appium]   Setting 'automationName=UiAutomator2' by default and using the
    [Appium]   UiAutomator2 Driver
    [Appium]
    [Appium]   The next major version of Appium (2.x) will **require** the
    [Appium]   'automationName' capability to be set for all sessions on all
    [Appium]   platforms
    [Appium]
    [Appium]   In previous versions (Appium <= 1.13.x), the default was
    [Appium]   'automationName=UiAutomator1'
    [Appium]
    [Appium]   If you wish to use that automation instead of UiAutomator2, please
    [Appium]   add 'automationName=UiAutomator1' to your desired capabilities
    [Appium]
    [Appium]   For more information about drivers, please visit
    [Appium]   http://appium.io/docs/en/about-appium/intro/ and explore the
    [Appium]   'Drivers' menu
    [Appium]
    [Appium] ======================================================================
    [Appium]
    [Appium] Appium v1.22.3 creating new AndroidUiautomator2Driver (v1.70.1) session
    [debug] [Appium] There are no active sessions for cleanup
    [debug] [BaseDriver] Creating session with W3C capabilities: {
    [debug] [BaseDriver]   "alwaysMatch": {
    [debug] [BaseDriver]     "platformName": "android",
    [debug] [BaseDriver]     "appium:appActivity": "com.miui.calculator.cal.CalculatorActivity",
    [debug] [BaseDriver]     "appium:appPackage": "com.miui.calculator",
    [debug] [BaseDriver]     "appium:deviceName": "Redmi 6 Pro",
    [debug] [BaseDriver]     "appium:platformVersion": "9 PKQ1.180917.001",
    [debug] [BaseDriver]     "appium:udid": "0986fbcd0805"
    [debug] [BaseDriver]   },
    [debug] [BaseDriver]   "firstMatch": [
    [debug] [BaseDriver]     {}
    [debug] [BaseDriver]   ]
    [debug] [BaseDriver] }
    [BaseDriver] Session created with session id: cd8e2324-e292-49e0-90f2-1f7437f4d176
    [UiAutomator2] Starting 'com.miui.calculator' directly on the device
    [ADB] Found 0 'build-tools' folders under 'F:Downloadsandroid_sdk' (newest first):
    [ADB] Using 'adb.exe' from 'F:Downloadsandroid_sdkplatform-toolsadb.exe'
    [debug] [ADB] Running 'F:Downloadsandroid_sdkplatform-toolsadb.exe -P 5037 start-server'
    [AndroidDriver] Retrieving device list
    [debug] [ADB] Trying to find a connected android device
    [debug] [ADB] Getting connected devices
    [debug] [ADB] Connected devices: [{"udid":"0986fbcd0805","state":"device"}]
    [AndroidDriver] Using device: 0986fbcd0805
    [ADB] Using 'adb.exe' from 'F:Downloadsandroid_sdkplatform-toolsadb.exe'
    [debug] [ADB] Running 'F:Downloadsandroid_sdkplatform-toolsadb.exe -P 5037 start-server'
    [debug] [ADB] Setting device id to 0986fbcd0805
    [debug] [ADB] Running 'F:Downloadsandroid_sdkplatform-toolsadb.exe -P 5037 -s 0986fbcd0805 shell getprop ro.build.version.sdk'
    [debug] [ADB] Current device property 'ro.build.version.sdk': 28
    [ADB] Getting device platform version
    [debug] [ADB] Running 'F:Downloadsandroid_sdkplatform-toolsadb.exe -P 5037 -s 0986fbcd0805 shell getprop ro.build.version.release'
    [debug] [ADB] Current device property 'ro.build.version.release': 9
    [debug] [ADB] Device API level: 28
    [UiAutomator2] Relaxing hidden api policy
    [debug] [ADB] Running 'F:Downloadsandroid_sdkplatform-toolsadb.exe -P 5037 -s 0986fbcd0805 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
    [debug] [ADB] Running 'F:Downloadsandroid_sdkplatform-toolsadb.exe -P 5037 -s 0986fbcd0805 wait-for-device'
    [debug] [ADB] Running 'F:Downloadsandroid_sdkplatform-toolsadb.exe -P 5037 -s 0986fbcd0805 shell echo ping'
    [debug] [AndroidDriver] Pushing settings apk to device...
    [debug] [ADB] Getting install status for io.appium.settings
    [debug] [ADB] Running 'F:Downloadsandroid_sdkplatform-toolsadb.exe -P 5037 -s 0986fbcd0805 shell dumpsys package io.appium.settings'
    [debug] [ADB] 'io.appium.settings' is installed
    [debug] [ADB] Getting package info for 'io.appium.settings'
    [debug] [ADB] Running 'F:Downloadsandroid_sdkplatform-toolsadb.exe -P 5037 -s 0986fbcd0805 shell dumpsys package io.appium.settings'
    [debug] [ADB] The version name of the installed 'io.appium.settings' is greater or equal to the application version name ('3.4.0' >= '3.4.0')
    [debug] [ADB] There is no need to install/upgrade 'C:UsersahmedAppDataRoamingnpmnode_modulesappiumnode_modulesio.appium.settingsapkssettings_apk-debug.apk'
    [debug] [ADB] Getting IDs of all 'io.appium.settings' processes
    [debug] [ADB] Running 'F:Downloadsandroid_sdkplatform-toolsadb.exe -P 5037 -s 0986fbcd0805 shell 'pgrep --help; echo $?''
    [debug] [ADB] Running 'F:Downloadsandroid_sdkplatform-toolsadb.exe -P 5037 -s 0986fbcd0805 shell pgrep -f ([[:blank:]]|^)io.appium.settings([[:blank:]]|$)'
    [debug] [AndroidDriver] io.appium.settings is already running. There is no need to reset its permissions.
    [debug] [ADB] Running 'F:Downloadsandroid_sdkplatform-toolsadb.exe -P 5037 -s 0986fbcd0805 shell appops set io.appium.settings android:mock_location allow'
    [debug] [Logcat] Starting logs capture with command: F:\Downloads\android_sdk\platform-tools\adb.exe -P 5037 -s 0986fbcd0805 logcat -v threadtime
    [debug] [UiAutomator2] Forwarding UiAutomator2 Server port 6790 to local port 8201
    [debug] [ADB] Forwarding system: 8201 to device: 6790
    [debug] [ADB] Running 'F:Downloadsandroid_sdkplatform-toolsadb.exe -P 5037 -s 0986fbcd0805 forward tcp:8201 tcp:6790'
    [debug] [ADB] Getting install status for io.appium.uiautomator2.server
    [debug] [ADB] Running 'F:Downloadsandroid_sdkplatform-toolsadb.exe -P 5037 -s 0986fbcd0805 shell dumpsys package io.appium.uiautomator2.server'
    [debug] [ADB] 'io.appium.uiautomator2.server' is not installed
    [debug] [ADB] App 'C:UsersahmedAppDataRoamingnpmnode_modulesappiumnode_modulesappium-uiautomator2-serverapksappium-uiautomator2-server-v4.27.0.apk' is not installed
    [debug] [UiAutomator2] io.appium.uiautomator2.server installation state: notInstalled
    [debug] [ADB] Checking app cert for C:UsersahmedAppDataRoamingnpmnode_modulesappiumnode_modulesappium-uiautomator2-serverapksappium-uiautomator2-server-v4.27.0.apk
    [ADB] Using 'apksigner.jar' from 'F:Downloadsandroid_sdkplatform-toolsapksigner.jar'
    [debug] [ADB] Starting apksigner: 'C:\Program Files\Java\jdk-15.0.1\bin\java.exe' -Xmx1024M -Xss1m -jar F:\Downloads\android_sdk\platform-tools\apksigner.jar verify --print-certs C:\Users\ahmed\AppData\Roaming\npm\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-v4.27.0.apk
    [HTTP] <-- POST /wd/hub/session - - ms - -
    [HTTP]
    [HTTP] Could not cache the response identified by 'd305fc02-d9b3-4cd4-9eba-49c2433cf199', because it has not been completed
    [HTTP] Does the client terminate connections too early?
    [Logcat] Logcat terminated with code 0, signal null

Stacktrace:

> Task :CalculatorTest.main()
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:561)
    at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:225)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:151)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:79)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:87)
    at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:116)
    at appiumTests.CalculatorTest.openCalculator(CalculatorTest.java:39)
    at appiumTests.CalculatorTest.main(CalculatorTest.java:14)
Caused by: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '4.1.1', revision: 'e8fcc2cecf'
Caused by: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException

System info: host: 'DESKTOP-6FC8K77', ip: '192.168.0.123', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '15.0.1'
Driver info: driver.version: AndroidDriver
    at io.appium.java_client.remote.AppiumProtocolHandshake.createSession(AppiumProtocolHandshake.java:130)
    at io.appium.java_client.remote.AppiumProtocolHandshake.createSession(AppiumProtocolHandshake.java:102)
    at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:146)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:180)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
    ... 7 more
Caused by: java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at io.appium.java_client.remote.AppiumProtocolHandshake.createSession(AppiumProtocolHandshake.java:126)
    ... 11 more
Caused by: java.lang.RuntimeException: NettyHttpHandler request execution error
    at org.openqa.selenium.remote.http.netty.NettyHttpHandler.makeCall(NettyHttpHandler.java:83)
    at org.openqa.selenium.remote.http.RetryRequest.lambda$apply$6(RetryRequest.java:83)
    at net.jodah.failsafe.Functions.lambda$get$0(Functions.java:48)
    at net.jodah.failsafe.RetryPolicyExecutor.lambda$supply$0(RetryPolicyExecutor.java:66)
    at net.jodah.failsafe.RetryPolicyExecutor.lambda$supply$0(RetryPolicyExecutor.java:66)
    at net.jodah.failsafe.RetryPolicyExecutor.lambda$supply$0(RetryPolicyExecutor.java:66)
    at net.jodah.failsafe.Execution.executeSync(Execution.java:128)
    at net.jodah.failsafe.FailsafeExecutor.call(FailsafeExecutor.java:379)
    at net.jodah.failsafe.FailsafeExecutor.get(FailsafeExecutor.java:68)
    at org.openqa.selenium.remote.http.RetryRequest.lambda$apply$7(RetryRequest.java:83)
    at org.openqa.selenium.remote.http.AddSeleniumUserAgent.lambda$apply$0(AddSeleniumUserAgent.java:42)
    at io.appium.java_client.remote.AppiumCommandExecutor.lambda$createSession$0(AppiumCommandExecutor.java:149)
    at org.openqa.selenium.remote.http.Filter.lambda$andFinally$1(Filter.java:56)
    at org.openqa.selenium.remote.http.netty.NettyHttpHandler.execute(NettyHttpHandler.java:51)
    at org.openqa.selenium.remote.http.RetryRequest.lambda$apply$6(RetryRequest.java:83)
    at net.jodah.failsafe.Functions.lambda$get$0(Functions.java:48)
    at net.jodah.failsafe.RetryPolicyExecutor.lambda$supply$0(RetryPolicyExecutor.java:66)
    at net.jodah.failsafe.RetryPolicyExecutor.lambda$supply$0(RetryPolicyExecutor.java:66)
    at net.jodah.failsafe.RetryPolicyExecutor.lambda$supply$0(RetryPolicyExecutor.java:66)
    at net.jodah.failsafe.Execution.executeSync(Execution.java:128)
    at net.jodah.failsafe.FailsafeExecutor.call(FailsafeExecutor.java:379)
    at net.jodah.failsafe.FailsafeExecutor.get(FailsafeExecutor.java:68)
    at org.openqa.selenium.remote.http.RetryRequest.lambda$apply$7(RetryRequest.java:83)
    at org.openqa.selenium.remote.http.AddSeleniumUserAgent.lambda$apply$0(AddSeleniumUserAgent.java:42)
    at io.appium.java_client.remote.AppiumCommandExecutor.lambda$createSession$0(AppiumCommandExecutor.java:149)
    at org.openqa.selenium.remote.http.Filter.lambda$andFinally$1(Filter.java:56)
    at org.openqa.selenium.remote.http.netty.NettyClient.execute(NettyClient.java:110)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:102)
    ... 16 more
Caused by: java.util.concurrent.ExecutionException: java.util.concurrent.TimeoutException: Request timeout to 127.0.0.1/127.0.0.1:4723 after 600000 ms
    at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:395)
    at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2086)
    at org.asynchttpclient.netty.NettyResponseFuture.get(NettyResponseFuture.java:206)
    at org.openqa.selenium.remote.http.netty.NettyHttpHandler.makeCall(NettyHttpHandler.java:66)
    ... 43 more
Caused by: java.lang.reflect.InvocationTargetException

Caused by: java.lang.RuntimeException: NettyHttpHandler request execution error

Caused by: java.util.concurrent.ExecutionException: java.util.concurrent.TimeoutException: Request timeout to 127.0.0.1/127.0.0.1:4723 after 600000 ms

Caused by: java.util.concurrent.TimeoutException: Request timeout to 127.0.0.1/127.0.0.1:4723 after 600000 ms
Caused by: java.util.concurrent.TimeoutException: Request timeout to 127.0.0.1/127.0.0.1:4723 after 600000 ms

    at org.asynchttpclient.netty.timeout.TimeoutTimerTask.expire(TimeoutTimerTask.java:43)
    at org.asynchttpclient.netty.timeout.RequestTimeoutTimerTask.run(RequestTimeoutTimerTask.java:50)
    at io.netty.util.HashedWheelTimer$HashedWheelTimeout.run(HashedWheelTimer.java:715)
    at io.netty.util.concurrent.ImmediateExecutor.execute(ImmediateExecutor.java:34)
    at io.netty.util.HashedWheelTimer$HashedWheelTimeout.expire(HashedWheelTimer.java:703)
    at io.netty.util.HashedWheelTimer$HashedWheelBucket.expireTimeouts(HashedWheelTimer.java:790)
    at io.netty.util.HashedWheelTimer$Worker.run(HashedWheelTimer.java:503)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.base/java.lang.Thread.run(Thread.java:832)

Leave a Comment