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
Is it possible to automatically uninstall Android App?
-
- Posts: 82
- Joined: Fri Oct 24, 2014 10:58 am
- Location: Bucharest
Re: Is it possible to automatically uninstall Android App?
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:
If this helped, let others know in a short reply.
Cheers!
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();
Cheers!
Lucian Teodorescu
NetSun Software
NetSun Software
Re: Is it possible to automatically uninstall Android App?
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:
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();
-
- Posts: 82
- Joined: Fri Oct 24, 2014 10:58 am
- Location: Bucharest
Re: Is it possible to automatically uninstall Android App?
Hi Mague,
Just add the reference to System.Diagnostics in the top of your user code method.
Ranorex does not need it so it's not added by default.
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
NetSun Software
Re: Is it possible to automatically uninstall Android App?
Hi Lucian,
exactly.
Now, it's work perfectly.
Thank you very much.
exactly.
Now, it's work perfectly.
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();
Re: Is it possible to automatically uninstall Android App?
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 ?
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Is it possible to automatically uninstall Android App?
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
Regards,
Markus (S)
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)