Is it possible to automatically uninstall Android App?

Mobile Testing, Android App Testing.
Mague
Posts: 6
Joined: Wed Aug 26, 2015 1:23 am

Is it possible to automatically uninstall Android App?

Post by Mague » Fri Aug 28, 2015 7:43 pm

Hi everyone,

I am new with Ranorex and I wonder if is it possible to add a end step in my Android App test that uninstall the App from the device?

The device is connected with USB

Thank you

lucian.teodorescu
Posts: 82
Joined: Fri Oct 24, 2014 10:58 am
Location: Bucharest

Re: Is it possible to automatically uninstall Android App?

Post by lucian.teodorescu » Mon Aug 31, 2015 10:14 am

Hi Mague,

In user code and with adb.exe you can do the trick. Assuming that you have only one device connected (otherwise you will need some extra lines to identify and access the right one), this is what you need:

Code: Select all

string pathToAdb = "C:\\<folder[s]>\\Android SDK\\sdk\\platform-tools\\adb.exe";                  //your path to adb.exe goes here
//string appPackageName = "myAndroidApp";   //the packagename of your app
			
Report.Info("INFO", "Uninstall WERA from device <deviceName>"); 
Report.Info("ADB command", "adb uninstall" + appPackageName );
			
Process adbClearProcess = new Process();
adbUninstallApp.StartInfo.FileName  = pathToAdb;
adbUninstallApp.StartInfo.Arguments = string.Format(" uninstall " + appPackageName);
adbUninstallApp.Start();
adbUninstallApp.WaitForExit();
If this helped, let others know in a short reply.
Cheers!
Lucian Teodorescu
NetSun Software

Mague
Posts: 6
Joined: Wed Aug 26, 2015 1:23 am

Re: Is it possible to automatically uninstall Android App?

Post by Mague » Mon Aug 31, 2015 9:40 pm

Hi Lucian,

thank you for your answer.

I just tried it but I have an error with method "process()" which is not recognized by Ranorex :-(
Error message: The type or namespace name "Process" could not be find (Are you missing a unsing directive or assembly reference?) (CS0246)

How I built my user code:
1- In my recording, I used User code Action and parameters:
Add new action > User Code => Created Method: UninstallApp
Args => created 2 variables PathToAdb and appPackageName
2- Go to "View Code"
Add your code for the method from Report.info(...) to the end:

Code: Select all

     
Report.Info("INFO", "Uninstall WERA from device <deviceName>"); 
Report.Info("ADB command", "adb uninstall" + appPackageName );
         
Process adbClearProcess = new Process();
adbClearProcess.adbUninstallApp.StartInfo.FileName  = pathToAdb;
adbClearProcess.adbUninstallApp.StartInfo.Arguments = string.Format(" uninstall " + appPackageName);
adbClearProcess.adbUninstallApp.Start();
adbClearProcess.adbUninstallApp.WaitForExit();

lucian.teodorescu
Posts: 82
Joined: Fri Oct 24, 2014 10:58 am
Location: Bucharest

Re: Is it possible to automatically uninstall Android App?

Post by lucian.teodorescu » Tue Sep 01, 2015 5:57 am

Hi Mague,

Just add the reference to System.Diagnostics in the top of your user code method.

Code: Select all

using System.Diagnostics;

Ranorex does not need it so it's not added by default.
Lucian Teodorescu
NetSun Software

Mague
Posts: 6
Joined: Wed Aug 26, 2015 1:23 am

Re: Is it possible to automatically uninstall Android App?

Post by Mague » Tue Sep 01, 2015 6:28 pm

Hi Lucian,

exactly.
Now, it's work perfectly. :D

Code: Select all

String pathToAdb = "<my path To adb.exe >";
String appPackageName= "<my app name>";

System.Diagnostics.Process adbClearProcess = new System.Diagnostics.Process();
adbClearProcess .StartInfo.FileName  = pathToAdb;
adbClearProcess .StartInfo.Arguments = string.Format(" uninstall " + appPackageName);
adbClearProcess .Start();
adbClearProcess .WaitForExit();
Thank you very much.

User avatar
sandamal
Posts: 28
Joined: Wed Jul 08, 2015 7:50 am

Re: Is it possible to automatically uninstall Android App?

Post by sandamal » Fri Feb 17, 2017 7:27 am

Mague wrote:Hi Lucian,

thank you for your answer.

I just tried it but I have an error with method "process()" which is not recognized by Ranorex :-(
Error message: The type or namespace name "Process" could not be find (Are you missing a unsing directive or assembly reference?) (CS0246)

How I built my user code:
1- In my recording, I used User code Action and parameters:
Add new action > User Code => Created Method: UninstallApp
Args => created 2 variables PathToAdb and appPackageName
2- Go to "View Code"
Add your code for the method from Report.info(...) to the end:

Code: Select all

     
Report.Info("INFO", "Uninstall WERA from device <deviceName>"); 
Report.Info("ADB command", "adb uninstall" + appPackageName );
         
Process adbClearProcess = new Process();
adbClearProcess.adbUninstallApp.StartInfo.FileName  = pathToAdb;
adbClearProcess.adbUninstallApp.StartInfo.Arguments = string.Format(" uninstall " + appPackageName);
adbClearProcess.adbUninstallApp.Start();
adbClearProcess.adbUninstallApp.WaitForExit();

HI, above solution works fine (application is uninstalling) but im facing an issue ,
i wrote this in a separate code module and call at the end of the test suit , but the issue im facing is device connectivity with ranorex is disconnecting when i call this ADB command,
If i retry the devices in studio , devices device is getting back to green

is this an expected behavior ?
can i call this device connection retry in a code module ?
are there any other possible workarounds ?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Is it possible to automatically uninstall Android App?

Post by Support Team » Tue Feb 21, 2017 8:48 pm

Hi Sandamal,

Are you using the included ADB.exe located in "C:\Program Files (x86)\Ranorex 6.2\Bin\RxEnv\Android\tools"? If not that might be the explanation for your observed behavior. Using a different ADB will kill the existing ADB daemon, which could cause a disconnection to your device.
Anyway, you can use the following line of code to reconnect your mobile device during runtime
Ranorex.Core.Remoting.RemoteServiceLocator.Service.GetByDisplayName("DEVICE_NAME").Reconnect();
Please let me know if that helps.
Regards,
Markus (S)
.
Image