Recording and Performance testing Android

Recording and Performance testing Android applications with HP Loadrunner VuGen

By   Richard Pal

Recording and Performance testing Android_第1张图片In this article I will show how to create a Loadrunner test to replicate the network traffic generated by an Android application. The Android SDK will be used to execute the application under test, while HP Loadrunner Virtual User Generator (VuGen) captures the network packets and translates it to Loadrunner virtual user script.

Prerequisites:

  • Loadrunner/Performance Center Virtual User Generator 9.5x
  • Android SDK with the Android emulator
  • A test application

Prepare the Android emulator

First, the Android SDK is to be downloaded. After unzipping the SDK, the SDK Manager.exe configures the SDK and downloads the available binaries for the different Android OS variants.

This will take a while. When done, an Android device is to be created. For this example an Android 2.2 device has been created with the name ’A22’.

Configure a new Android virtual image to host the application under test within the SDK Manager

Get the application under test ready

Have your Android installation package (.apk file) ready for installation.

For this example the Android SDK’s Wiktionary example will be used. As it is shipped without the built binaries, I used IntelliJ Idea Community Edition (which comes with built-in support of Android development) to build it. The source code of Wiktionary can be located in the Android SDK’s directory at: ….\android-sdk-windows\samples\android-13\Wiktionary\out\production\Wiktionary

Deploy the Android application into the emulator

Start the created virtual device, either from the SDK Manager user interface, or from command line (specify the appropriate device name instead of A22 if it was named differently):

1
D:\apps\android-sdk-windows\tools\emulator.exe -avd A22 -netspeed full -netdelay none ~/.android/A22.avd

[Update] Since I have written this article the emulator’s parameter list has been changed. Now you can start an emulator device by emulator.exe @DeviceName, e.g. based on our example emulator.exe @A22

Once the device has finished booting, deploy the build Android package (the APK file) into it with the adb tool in the Android SDK (execute it from the directory which contains the APK file):

1
D:\apps\android-sdk-windows\platform-tools\adb install Wiktionary.apk

Start the application in the emulator device, and ensure, that it works properly.

Capture the network traffic of the Andoid application with VuGen

Close the emulator window.

Create a new virtual user script in Virtual User Generator. As Wiktionary uses HTTP and JSON, the http/WEB protocol will be used.

In the Start Recording dialog specify the executable of the Android emulator and the runtime parameters of the virtual device:

  • Program to record: D:\apps\android-sdk-windows\tools\emulator.exe
  • Program arguments: -avd A22 -netspeed full -netdelay none (see the [Update] on argument list above)

(specify the appropriate device name instead of A22 if it was named differently)

Recording and Performance testing Android_第2张图片

Before starting recording, the Network Capture level should be modified to „Socket level and WinInet level data”. (the other two options either do not record any traffic or crash the emulator during recording…)

Recording and Performance testing Android_第3张图片

Add the content-type “application/json” to Non-Resources. This will produce separated web_url calls for Json resources. Otherwise json calls might be placed into EXTRA_RES section.

Recording and Performance testing Android_第4张图片

Adding content types to 'non-resources' list in VuGen Recording options

Start recording and execute the steps of the test. Make sure, that the Recording toolbar shows recorded events.

After stopping the test the VuGen testscript is generated. Here is a sample recording:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Action()
{
web_url( "api.php" ,
"URL=http://en.wiktionary.org/w/api.php?action=query&list=random&format=json" ,
"TargetFrame=" ,
"Resource=1" ,
"RecContentType=application/json" ,
"Referer=" ,
"Snapshot=t1.inf" ,
LAST);
 
web_url( "api.php_2" ,
"URL=http://en.wiktionary.org/w/api.php?action=query&prop=revisions&titles=phosphourous&rvprop=content&format=json&rvexpandtemplates=true" ,
"TargetFrame=" ,
"Resource=1" ,
"RecContentType=application/json" ,
"Referer=" ,
"Snapshot=t2.inf" ,
LAST);
 
lr_think_time(5);
 
web_url( "api.php_3" ,
"URL=http://en.wiktionary.org/w/api.php?action=query&prop=revisions&titles=phosphorous&rvprop=content&format=json&rvexpandtemplates=true" ,
"TargetFrame=" ,
"Resource=1" ,
"RecContentType=application/json" ,
"Referer=" ,
"Snapshot=t3.inf" ,
LAST);
 
return 0;
}

Ensure with replaying the script that the scenario is correct. The script usually needs customization to properly imitate user interaction (parameters, correlation, think times, pacing, etc.)

The recorded and the replayed network traffic can be tracked in the Tree view.

Recording and Performance testing Android_第5张图片

If the script is ready, it can be load-tested using the Performance Center user site as usual.

I hope this short introduction will help you to set up load test of Android applications.

Tags: Android, device applications, mobile, performance test

16 Responses to Recording and Performance testing Android applications with HP Loadrunner VuGen

  1. Yair on November 16, 2011 at 1:25 pm

    Hi Richard,

    Thanks for the great blog post, it was good to see you address mobile performance testing.

    I’m part of the HP team working on LoadRunner, Performance Center and mobile and I have two comments/questions.

    1. I noticed that you used VuGen 9.5x and the Web protocol. Have you looked at the two mobile protocols that are available for LoadRunner 11 and Performance Center 11 – Mobile TruClient and Mobile Apps?

    2. What approach have you taken to test iOS applications?

    Thanks again for the post and insight.
    Yair

    REPLY
  2. Richard P on November 23, 2011 at 11:22 am

    Hi Yair,

    thanks for your feedback.

    Meanwhile I have written a new article which addresses the recording of load tests with real “hard” devices as opposed to emulators (still based on Loadrunner 9.5x). This approach also makes possible to deal with iOS applications.

    http://www.perftesting.co.uk/performance-testing-iphone-ios-android/

    I am keen to read your opinion and feedback on the topic, any contribution is welcome!

    The capabilities of HP Loadrunner 11 Patch #3 wrt. Mobile testing will be the next topic for me to investigate. [Update: see the review of the LR11 mobile testing capabilities here: http://www.perftesting.co.uk/reviewing-the-mobile-application-testing-capabilities-in-loadrunner-11/2011/12/03/ ]

    cheers
    Richard

    REPLY
  3. UmamaheswaraRao Suda on November 25, 2011 at 3:49 am

    Hi Richard,

    I like this article, as currently I am working with AppPerfect Load test tool for IOS and safari browser.
    I will try to work with Android emulator for IPhone and update the status to you.
    If you have more links on this, please share the same.

    REPLY
    • Leo on January 24, 2012 at 6:55 pm

      Hi Richard,

      Recently I tried to run the emulator on command line only but I keep getting many errors.
      I created the AVD on AVD Manager interface, and then I tried to emulate the device using the command: “emulator @test ” but I got the message:
      C:\Android\tools>emulator: ERROR: This AVD’s configuration is missing a kernel file!!

      Then I added the parameter as below:
      emulator @test -kernel C:\Android\system-images\android-15\armeabi-v7a

      But then I got this:
      “C:\Android\tools>emulator: ERROR: No initial system image for this configuration”

      Even by adding the -system (pointing to the same system directory, but to specific system.img file), the response I got is:

      emulator: warning: opening audio output failed
      C:\Android\system-images\android-15\armeabi-v7a: Permission denied
      qemu: could not load kernel ‘C:\Android\system-images\android-15\armeabi-v7a’

      What am I missing here?

      REPLY
      • Richard P on February 18, 2012 at 11:12 am

        Hi,

        it looks like you Android SDK is corrupted. Try to remove it and reinstall the latest.

        cheers
        R.

        REPLY
    • srikant on January 31, 2012 at 8:30 pm

      Hi Richard,
      This was a very useful and i am currently working to create a script Android application.I set up the Android appln,deployed the .apk file and opened the emulator in the emulator and it worked fine.But when i tried to record using VuGen 9.52,using the same commands as you mentioned,the Emulator doesn’t gets opened up.Instead,a command prompt displays something and disappears quickly.Then gets the windows error dialogue window saying “emulator_arm.exe encountered an error”.Could you please help me in sorting out this issue.Thanks in advance.

      REPLY
      • srikant on January 31, 2012 at 8:31 pm

        Hi Richard,
        This was a very useful and i am currently working to create a script for an Android application.I set up the Android appln,deployed the .apk file and opened the appln in the emulator and it worked fine.But when i tried to record using VuGen 9.52,using the same commands as you mentioned,the Emulator doesn’t gets opened up.Instead,a command prompt displays something and disappears quickly.Then gets the windows error dialogue saying “emulator_arm.exe encountered an error”.Could you please help me in sorting out this issue.Thanks in advance.

        REPLY
      • Richard P on February 18, 2012 at 11:07 am

        Hi,

        recently Google has updated the emulator tool’s parameter list — see the update inserted into the article. Make sure that your emulator starts up properly (without Loadrunner).

        Sometimes the emulator gets stuck, and Loadrunner is not able to start it. Use basic methods like discovering+eliminating stuck emulator process with Task manager.

        cheers
        Richard

        REPLY
      • Jack on January 17, 2013 at 6:23 am

        Hi, this problem seems to be caused by the memory size of the emulator. Try to reduce the memory size of emulator to 384, then the emulator can be launched by loadrunner.

        REPLY
  4. Dennis on March 7, 2012 at 8:59 pm

    Hi,

    –Before starting recording, the Network Capture level should be modified to „Socket level and WinInet level data”. (the other two options either do not record any traffic or crash the emulator during recording…)

    This part is grayed-out I cannot select anything. And as commented, the emulator did not even start. It crashes as soon as it launches. Any ideas? I am still LR 11 with Patch 3.

    REPLY
  5. Vikram Patil on August 20, 2012 at 12:45 pm

    Hello,
    I am using Loadrunner 11.5 evaluation copy on Windows 7-64 bit.
    I am trying to test Android based mobile application (built on Android 2.2) using the Protocol option ‘Mobile Application – HTTP/HTML’ which is provided by Loadrunner 11.5.
    I have created a AVD, named ‘Test_1′ with Target Name: Android 2.2, Platform: 2.2, API Level 8 and CPU/ABI: ARM(armeabi).
    I am performing the following steps:
    1.Open VuGen.
    2.File –> New script and solution –> Protocol: Mobile Application – HTTP/HTML
    3.Recording Options: Port Mapping –> Capture Level –> Socket Level Data (By default only one option and non-editable)
    4.Record –> Recording Type –> Record Emulator – Record Script using a mobile device emulator 5.Emulator to record: F:\android-sdk-windows-1.5_r2\android-sdk-windows-1.5_r2\AVD_Manager.exe 6.Command Line: ‘-avd Test_1 -netspeed full -netdelay none’ where Test_1 is the ‘AVD name’ which is displayed when the AVD Manager is opened.
    7.Working Directory: F:\android-sdk-windows-1.5_r2\android-sdk-windows-1.5_r2
    8.Record into action: Action
    9.Finish

    I am getting 3 different results at different times:

    RESULT 1: The recording starts and I am getting pop-up named ‘Critical Error’ displaying ‘Unable to determine AUT’s bit capacity’ (As per my knowledge, AUT means ‘Application Under Test’.) alongwith a command window with title as ‘F:\android-sdk-windows-1.5_r2\android-sdk-windows-1.5_r2\AVD_Manager.exe’ Later on I have to close both the Pop-ups.
    RESULT 2: The recording starts and I am getting pop-up named ‘Critical Error’ displaying ‘Unable to determine AUT’s bit capacity’ (As per my knowledge, AUT means ‘Application Under Test’.) alongwith a command window with title as ‘F:\android-sdk-windows-1.5_r2\android-sdk-windows-1.5_r2\AVD_Manager.exe’ Then when I press OK on the pop-up, the AVD Manager opens. Then I select the device name i.e. Test_1 and click on start. The Emulator starts and then i can record. But this happened only ONCE.
    RESULT 3: The recording starts and I am getting pop-up named emulator-arm.exe has stopped working.
    Please let me know where am i going wrong or do i need to put some more inputs?
    Do I need to provide \tools\emulator.exe in the 5th step above?
    Expecting for a quick reply as my evaluation copy will get over on 26th Aug’12.

    Thanks a lot!

    REPLY
    • Richard P on August 20, 2012 at 4:46 pm

      Hi,

      here are my suggestions:

      1. open a fault ticket for HP Loadrunner :)
      2. I presume this problem is related to 32/64 bit incompatibility, so try the same using a 32-bit system if you have an appropriate environment or VM for that.
      3. Try the simple Web(HTML/HTTP) protocol type (instead of the mobile). I think it is more robust due to historic reasons :)

      Please let us hear from your results,
      cheers
      R.

      REPLY
  6. samme on August 31, 2012 at 9:17 pm

    After the Emulator is set up , you mentioned the APK file and sample , can you tell me where do I find the APK file ? Also how do I get the sample Wictionary APP installed on the Emulator

    I installed SDK and downloaded SDK and Platorm Tools aswell and installedallunder Andoid Version

    Now do I co to C:\\Program Files\Android… to find the apk for the sample app ?

    REPLY
  7. commondoubts on October 2, 2012 at 6:04 pm

    from the emulator, i am able to do secure transactions. For example user login. But when starting the same from Vugen, secure transactions are failing and not getting recorded. Please let me know what needs to be done.

    REPLY
  8. Khushbu on October 15, 2012 at 10:10 am

    Hi,

    I have to generate the script fo rnative application which is on ANDROID.
    I have tried ut method but my script is generated in some unreadeable format.Please look at the generated script below:

    web_custom_request(“tm”,
    “URL=http://xcbbjd.iop.com:5001/tm/?cid=0″,
    “Method=POST”,
    “TargetFrame=”,
    “Resource=0″,
    “Referer=”,
    “Snapshot=t1.inf”,
    “Mode=HTML”,
    “BodyBinary=159\r\n\\x03\\x82.\\xE3\\x00\\x81\\x03\\x87\\x00\\x80\\x1D\\xC5\\xE9\\xFC\\xD6\\xF8\\xFC\\x8B\\xF6\\x7FF\\xC2q,L\\xF4E+\\x0B\\x9D\\xA86\\x0C\\xE6\\x89\\xACF:\\xBB\\xB8C\\xFA\\x93\\x97e\\xAC\\x04\\xB4\\x97\\xE3\\x0E\\xE8\\xCFo\\xE6\\xA9\\xF1\\xD2m\\x17\\xCB8\\xEBFD\\xF6\\x07r9\\xFC\\x1C\\xAC8e\\xC0\\xB4Q\\xB2\\x02\\x18\\xBA\\x16U\\xA7\\xDB\\xF9\\x0BY\\xB5|\\x04\\x89&.\\x86 \\x87\\x1CA^Y\\xE2\\x9D\\x05\\x8AC\\xA7|p\\x11d\\x11]]7u{\\xD8,”
    “!nu\\xFA\\xB0\\x04\\x19\\xDF\\x9Bk\\xD1\\x19\\xA0G\\x88\\xA8\\x88*Rk\\xF3E\\x97\\x91L\\x95Mp\\xBA0,\\xDE_\\xA5\\x91j\t\\xB9\\xE5C/6\\xB0X\\xFA\r\\x93&B\\x17\\xAF\\x97S\t(\\x14\\xB5)\\xA6MI\\xEAA\\x12\\xAE\\xDD)\\xE5\\xFE\\x95\\xE2\\x03\\xCDu\\xE6\\xB1\\xE2\\xCA8M\\x81X\\xF9\\x1A\\x19\t\\xE9\\xC2.\\xF7\\xEB_y\\\\_\\x1Ef\\xF2′\\xE3\\xD7\\x92\\xDCm\\xD0#!\\xF4m\\xB3^”
    “\\xE75\\x81\\xF8.i*\\xF7\\x93\\x8EJ\\x08\\xC1\\x9D\\xD8yL\\xB3N\\xAA\\x9EF\\xECV\\xD6\\xAF\\x86\\x84z\\x1A\\x86c\\x03\\xBE\\xD4\\x8A#\\xDAsU\\x1E\\x06!;t\\xBE\\xB1\\x91\\x8F\\xD0\\xC8N\\x9A\\x05[4\\x1D\\x8Bv\\xD3a\\xFB\\x18o\\xD2\\x13\\x08\\xE9%l;\\x10\\x01\\x9F\\x9BJ\\xA9\\xB0C\”\\x04\\xD4\\x92\\xC4\\x1EY\\xAD\\xF6\nlr\\xB2\\xDB\\x8Bq\”\\x0E\\x00.\\xF8\\x89\\xC9#\\xE7\\xA7\t\\x1B\\x16\\xDF\\x84/5\\x85YQ\r\n0\r\n\r\n”,
    LAST);

    Can u suggest me how to generate the script in readeable format.

    REPLY
  9. pfa on March 19, 2013 at 10:50 am

    I have done exactly following your above instruction, a command line appear with a message: “Error reading clientFlags”
    Pls help me, thanks in advance

你可能感兴趣的:(Recording and Performance testing Android)