How I solve Permission Denial Error: starting intent when running Appium on an Android Emulator?

How I solve Permission Denial Error: starting intent when running Appium on an Android Emulator?

For QA Automation Engineering, in my team we use BrowserStack for running our tests. It’s straightforward to get started. However, this platform - as a service - is not perfect. It does an excellent job of simplifying both Web and Mobile Automation; but the service is relatively slow and I sometimes encounter an Incorrect Device Error when running tests (might be due to a different timezone). But I would nonetheless be happy to recommend this platform.

I’ve also exchanged with the organisation on this subject but they found no solution. I don’t encounter this issue much but often it becomes blocking whenever I need to write new or debug automation tests. I’ve therefore been experimenting with different approaches.

We use Selenium for Web Automation, Appium for Android Emulation and Cucumber for iOS.

I use BlueStacks emulator with the Adb Bridge settings on and connect it to adb using the command adb connect localhost:port.

Following most popular tutorials online, this process looks easy to setup.

I initially just copy and paste the desired capabilities from the BrowserStack settings. I am however greeted by missing capabilities error. My research indicates that I also need to add the appPackage and appActivity capabilities. I assume that as I installed the app on the emulator, I don't need to include it.

Nevertheless, I keep getting one particular error. Whenever I start the test or use Appium to debug the app, I get the "Permission Denial Error: starting intent". When I dug further onto this matter, it seems that Appium calls the wrong starting Activity. By searching around, I get a solution that is supposed to get the first activity, one that is accessible outside. I try it by using this command in adb shell:

dumpsys window windows | grep -E 'mCurrentFocus'

I still get the same permission denial error. Due to other priorities, days go by before I again start experimenting with running the tests locally on an Emulator. This time I also install Android Studio with it’s emulator and try the same process. I encounter the same issue. I know I am close though as each time I change a capability, I have another more critical error such as missing capability.

I continue investigating and experimenting with different solutions until this one works as expected. I finally get the real starting activity:

adb shell "cmd package resolve-activity --brief appPackage | tail -n 1"

The above command detected LoginActivity as the first activity which is incorrect. For me, not being an Android developer, will be hard to guess the exact one, particularly without the source code available. Nevertheless, with this command, I get the SplashScreen activity and after the change, I no longer have the Permission error.

I can run the Appium tests on the Simulator.