LoadRunner11.00_AjaxTruClient_TipsTricks.pdf

5
HP LoadRunner Software Version: 11.00 Tips and Tricks: Ajax TruClient Object Parameterization Document Release Date: June 2011 Software Release Date: October 2010

description

LoadRunner11.00_AjaxTruClient_TipsTricks

Transcript of LoadRunner11.00_AjaxTruClient_TipsTricks.pdf

Page 1: LoadRunner11.00_AjaxTruClient_TipsTricks.pdf

HP LoadRunner

Software Version: 11.00

Tips and Tricks: Ajax TruClient Object Parameterization

Document Release Date: June 2011

Software Release Date: October 2010

Page 2: LoadRunner11.00_AjaxTruClient_TipsTricks.pdf

Object Parameterization in TruClient

Business need There are cases when the business process you are recording requires selecting a random or specific

object from a list of similar objects.

For example, your business process may include selecting from a list of radio buttons for which you

would like each Vuser to select one at random. Or, your business process might include a selecting an

option from a table for which you would like each Vuser to select based on a pre-defined login.

How can you parameterize the object selection in TruClient?

Sample use case As an example, consider a list of radio buttons you need to choose from, such as a list of care pack

services offered for HP laptops:

Page 3: LoadRunner11.00_AjaxTruClient_TipsTricks.pdf

Step 1 – Record the selection of several options

Record the selection of several of the options. Your script looks something like this:

Navigate to the Object section of each of these steps and change the ID Method from Automatic to XPath and look at the options presented:

Look for the XPath option that is similar in all the steps. In this case, the 2 XPath notations that seems similar. The differences are marked in bold and underline:

o The first: //div[@id="module-options-div"]/div[3]/div[2]/input //div[@id="module-options-div"]/div[5]/div[2]/input //div[@id="module-options-div"]/div[7]/div[2]/input //div[@id="module-options-div"]/div[9]/div[2]/input

o The second: (//input[@id="m_a_10"])[2] (//input[@id="m_a_10"])[3] (//input[@id="m_a_10"])[4] (//input[@id="m_a_10"])[5]

Copy one of the options above as a base for the dynamic identification. In this case use: //div[@id="module-options-div"]/div[3]/div[2]/input

Page 4: LoadRunner11.00_AjaxTruClient_TipsTricks.pdf

Step 2- Create dynamic Javascript based object identification

Select one of the steps and change the ID Method to Javascript and edit the Javascript. You will be

presented with a dialog that looks something like this:

Do one of the following: o Paste the XPath value into the evalXPath step (within the quotes) so it now looks like this:

o Escape the quotes (“) in the XPath expression by preceding them with a backslash (\) so this

now looks like this:

o Because we want to get all the elements (radio buttons) we remove the ordinal ([3]) so we

now get:

o Next we assign this expression to a variable called options (any variable name can be used)

that will become an array containing all the elements matching the XPath we defined:

Parameterize the selection by adding arguments:

o random(options) – the evaluation will return a random element making the selection random

o options[n] – the evaluation will always return the n element in the array. To ensure you do not overrun the number of elements in the array check this using options.length

o options[ArgsContext.item] – the evaluation will be based on a variable called item defined elsewhere in the script.

o options[ArgsContext.LR.getParam(“item”)] – the evaluation will be based on

a parameter called item defined elsewhere in the script.

Page 5: LoadRunner11.00_AjaxTruClient_TipsTricks.pdf

Step 3 – Verify parameterization

Once the Javascript object identification is complete you must verify the step is working as expected

If the Javascript does not contain any reference to a variable or a parameter, such as a random selection, run the step a few times.

If the Javascript contains a reference to a variable run the script from the step in which a value is assigned to the variable.

If the Javascript contains a reference to a parameter (even if indirectly via a variable) perform a full replay in order to initiate the parameters and make sure values are assigned to them.

Some debugging tips

Use window.alert in the Javascript code to check value. For example winow.alert(options.length) will display the number of options found and will help you check that the identification is locating the appropriate elements.

Copy and paste all the XPath values into one document so you can easily see them side by side. Compare the values to validate the XPath that will provide all the elements.

If the JavaScript code does not contain any reference to external variables/parameters, you can use the highlight option to see the matching object(s).

© Copyright 2011 Hewlett-Packard Development Company, L.P.