Wednesday, June 5, 2013

Flex Protocol Scripting in LR

Introduction

Adobe Flex is a software development kit released by Adobe Systems for the development and deployment of cross-platform rich Internet applications based on the Adobe Flash platform. Flex applications can be written using Adobe Flex Builderor by using the freely available Flex compiler from Adobe.
Developers use two core languages to create Flex applications. The first core language is MXML, the Macromedia Flex Mark-up Language, which includes a rich set of XML tags that allows developers to layout user interfaces. Some MXML constructs allow you to call remote objects, store data returned in a model, and customize your own look and feel to MXML components.
The second core language for Flex development is Action Script 2.0, which is similar to JavaScript. Action Script elements are coded inside MXML pages has robust event handling capabilities to allow the application to respond to dynamic user interactions. Unlike JavaScript, since Action Script runs inside the Flash plug-in there is no need to rewrite several versions of the same code to support different browsers.
The Flex server is responsible for translating the MXML and Action Script components into Flash byte code in the form of .SWF files. The SWF file is executed on the client in the Flash runtime environment. The Flex server provides other services such as caching, concurrency, and handling remote object requests. 


Flex Protocol with LR

VuGen allows you to create Vusers that emulate the protocol suite provided with the Flex 2 SDK.

RIAs are lightweight online programs that provide users with more dynamic control than with a standard web page. Like Web applications built with AJAX, Flex applications are more responsive, because the application does not need to load a new Web page every time the user takes action. However, unlike working with AJAX, Flex is independent of browser implementations such as JavaScript or CSS. The framework runs on Adobe's cross-platform Flash Player. 

Pre-requisite
  •     Load Runner 11.0 support the flex with the patch3
  •     JRE 6.0 
  •     Adobe flash player 10 and higher

Environment Variables

Verify for the following environment variables in Windows Operating system.

The environment variables can be reached by following the below steps:

1.    Right-click “My Computer”. Go to properties.
2.    Go to Advanced Tab
3.    Click on the Environment Variables button

Click on the “Ne“button under System variables and enter the below values:

Variable name: HP_FLEX_JAVA_LOG_FILE
Variable value: C:\flex.log

Variable name: VUGEN_PATH
Variable value: C:\Program Files\HP\Virtual User Generator\

Variable name: ANALYSIS_PATH
Variable value: C:\Program Files\HP\LoadRunner\

* The HP_FLEX_JAVA_LOG_FILE is used to generate the log file which will help us to identify the classes involved in a particular transaction.
This log file will be very useful for debugging. Ensure that there are no errors in the flex log file after recording.


Recording Options

The following recording options need to be considered before recording in flex protocol:

·         Go to Tools à Recording Options in LoadRunner.

·         Under Script Check the check box against “Generate recorded event logs”. This setting helps to generate the log files for debugging

·         Under Protocols tab select all three check boxes viz.,

o    Action Message Format (AMF)
o    Flex
o    Web(HTTP/HTML)

·         Under Recording, select HTML based script.

·         Select HTML Advanced button and select “A script that contains explicit URLs only (e.g.web_url, web_submit_data)”  and “Record in separate steps and use concurrent grops” for Non HTML – generated elements
·         Under Code generation select Encode AMF3 using external parser.And provide the below jar files location under Value column.

o    flex-messaging-common.jar
o    flex-messaging-core.jar
o    (Any application specific jars.The jars are dependent on the transaction and should be verified before recording every transaction)  

·         Under Port-Mapping, click on Options. Under Advanced Port Mapping Settings à Change Log level to Advanced Debug. - This setting would enable to generate flex log in C:\ drive.
  
·         The Advanced tab under HTTP properties is the standard one. 

·         Under Correlation tab, uncheck the “Enable correlation during recording” check box.
 


Post Recording Verification

After recording verify following:

1.    A file by name “flex. log” should be generated in C:\ drive.

2.    flex_amf_call should be generated with readable XML’s and not the binary format for all requests.


Correlation in Flex Scripts

Flex applications often contain dynamic data, data that changes each time you run the script. For example, the object name may change from run to run.

When you record a Vuser script, VuGen records a set of data and argument values. When you replay the script, however, the server may reject these arguments and issue an error. This error could be the result of dynamic data that is outdated and no longer accepted by the server.
To overcome this, you apply correlation to your script:

➤ Save the server response in preparation for extracting the required values.
➤ Extract the required values from the server response.
➤ Save the values to a parameter.
➤ Use those parameters as input to your Flex requests.

These errors are not always obvious, and you may only detect them by carefully examining Vuser log files. If you encounter an error when running your Vuser, examine the script at the point where the error occurred. Often, correlation will solve the problem by enabling you to use the results of one statement as input for another.
To perform correlation:

Locate the step in your script that failed due to dynamic values that need correlation.

Use the Replay Log to assist you in finding the problematic step.





Identify the server response with the correct value in one of the previous steps.

Double-Click the error in the Replay log to go to the step with the error. Examine the preceding steps in Tree View and look for the value in the Server Response tab.


3 Save the entire server response to a parameter.

Before you extract the value, the entire server response should be saved to a parameter as follows:

➤ Right-click the step node (in the left Action pane) corresponding to the server response containing the value and select Properties.
➤ In the Flex Call Properties dialog box, type a Response parameter name.
➤ Click OK to save the new parameter name.

Save the original server response value to a parameter.

➤ In the Replay Snapshot: Response Data, right-click the node above the value (for example, string), and select Save value in parameter.



 
In the XML Parameter Properties dialog, specify a parameter Name. You will use this name in subsequent steps.

➤ Click OK. The script will now contain a new function, lr_xml_get_values.

Insert the parameter in the subsequent calls.

In VuGen edit view, beginning with the call that failed, replace the value in all subsequent calls to the object with the parameter that you defined:

➤ Right-click the step node (in the Action pane) corresponding to the failed call and select Properties.
➤ Locate the argument that required correlation.
➤ In the Value box, type the parameter name in curly brackets, for example, {ParamValue_string}.



Click OK
 
Run the script.

Make sure that VuGen properly substitutes the argument value with the parameter value that you saved.

Some Important JAR files needed are 


 
We need application JAR files as well along with these JAR files from developer to generate the decoded AMF calls in the scripts else we can’t parse and correlate the requests.

No comments: