Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

Retrieving the AppPackage and AppActivity of an android apk

Retrieving the AppPackage and AppActivity of an android apk

Introduction


When testing a native application on an Android device, Silk Test creates a connection string which defines the device and app to be used for testing. The “app” component of the connection string is used to specify the location of the Android apk file to be deployed to the Android device for testing. For example:
sConnectionString = "deviceName=Nexus 7;platformName=Android;host=localhost;app=C:\MyMobileApps\InsuranceMobile.apk"

If you do not wish to specify the apk file in the connection string, you can use a combination of appActivity and appPackage. This article will demonstrate how you can use Android SDK
commands to retrieve the appActivity and appPackage of the installed app on your mobile device.

This article will use the android adb command, therefore you will be required to download the Android SDK (Android SDK Tools).  Alternatively you can use the
adb.exe that is installed with Silk Test:- (%OPEN_AGENT_HOME%\mobile\windows\AndroidTools\platform-tools\).

 

4Test Code Example


See example testcase below that uses custom function "GetPackageInfo()".  This will return the appActivity and appPackage of an android apk that is installed on a specified device.  This function takes 2 parameters:

sAppName - This is the name of the android app (Eg - InsuranceMobile).
sDeviceName (Optional)  - This is the name of the device that the app is installed on.  This is an optional parameter, and is useful if you have multiple android devices connected to your machine or remote location.

[-] testcase ReturnAppDetails() appstate none
    [ ] // If you wish to return the appActivity and appPackage of your "InsuranceMobile" app
    [ ] GetPackageInfo("InsuranceMobile")

[-] testcase ReturnAppDetails() appstate none
    [ ] // If you wish to return the appActivity and appPackage of your "InsuranceMobile" app that is installed on your "Nexus 7" device
    [ ] GetPackageInfo("InsuranceMobile", "Nexus 7")

The above testcases will return the following result:-

[-] Testcase ReturnAppDetails - Passed
    [ ] App Package = silktest.insurancemobile
    [ ] App Activity = silktest.insurancemobile.LoginActivity

I can now edit my connection string to use the appPackage and appActivity instead of specifying the physical apk file:-
sConnectionString = "deviceName=Nexus 7;platformName=Android;host=localhost;appActivity=.LoginActivity;appPackage=silktest.insurancemobile"

 

Attachments


Please see attached script.t file that contains the GetPackageInfo() function

AppPackageAppActivity.zip

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2017-06-22 14:45
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.