Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I connect appium to existing running application on android

I am writing a cross platform automation where I have a selenium desktop driver and I perform some action which launches my service on device and an alert is launched on android device and i want to accept the alert and then use both web driver and mobile driver together to perform some functionality.

The web driver is working fine it performs the desired action on web browser and creates an alert on device side.

Hence my application/service is already launched on the device and now when i try to set the appium capabilities:

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platform", "ANDROID");
capabilities.setCapability("version", "4.4");
capabilities.setCapability("automationName", "uiautomator2");
capabilities.setCapability("deviceName", "karnak");
capabilities.setCapability("platformVersion", "7.1");
capabilities.setCapability("noReset", "true");
capabilities.setCapability("autoGrantPermissions", "true");
capabilities.setCapability("appPackage", "xyz");
capabilities.setCapability("appActivity", ".abc");
capabilities.setCapability("optionalIntentArguments", payload);

What happens is appium will kill the existing session that i have and will install the application and try to start the activity with the provided payload which won't be valid now.

So there a way where i can create a mobile driver for existing running application/service on the device without have to install the application and re-launching it.

I found that you have to do noReset but that doesn't seem to work for me. I tried providing appWaitPackage and appWaitActivity instead of appPackage and appActivity and that didn't work either.

Let me know if any of you know how i can attach the mobile driver to existing running application/service.

like image 626
Anup Hariyani Avatar asked Nov 17 '22 08:11

Anup Hariyani


1 Answers

Appium allows for a couple ways to utilize your applications per https://appium.io/docs/en/writing-running-appium/caps/

If you don't specify the app tag with a link to the apk it won't install anything. However, as you noted, it will still launch a new instance of the application based off the appPackage / appActivity.

To address that use the flag autoLaunch Initializing the app under test automatically. Appium does not install/launch the app under test if this is false. Defaults to true.

You can then combine this with the dontStopAppOnReset=true to leave your application running when your tests complete.

like image 176
Matthew Dahm Avatar answered Dec 26 '22 10:12

Matthew Dahm