Get version of installed Android application
I would like to log the version of the current Android application under test. I can't seem to figure out how to do it. Is it possible? I know you can get lots of application information when testing iOS, but I can't find anything similar for Android.
Lars Lund Olsen
To get version of the application installed on the Android device using TestComplete:
-- Get list of the installed applications with the code like this (DelphiScript):
DeviceObj := Mobile.Device(); PackManagerObj := DeviceObj.PackageManager; Num := PackManagerObj.InstalledPackageCount; for i := 0 to Num - 1 do begin Log.AppendFolder(i); PackObj := PackManagerObj.InstalledPackage(i); // Obtain the package name Log.Message('The package name is: ' + PackObj.Name); // Obtain the path to the package on the local computer Log.Message('The package local path is: ' + PackObj.PCPath); // Obtain the path to the package on the device Log.Message('The package device path is: ' + PackObj.DevicePath); if (PackManagerObj.IsActivePackage(PackObj)) then Log.Message('The specified package is active.') else Log.Message('The specified package is not active.'); Log.PopLogFolder(); end;
and get the package name from there;
-- Execute code line like this:
str := Mobile.Device.ShellExecute('dumpsys package <package_name> | grep versionName');
the above line of code should return the string like
-- Get version number from the above string.