Sei sulla pagina 1di 25

LoadRunner Scripting Best Practices

Chase Harris Consultant Software Engineer EMC

Copyright 2008 EMC Corporation. All rights reserved.

Topics

Part 1 - Planning the Test Suite Part 2 - Recording the Tests Part 3 - Customizing Recorded Scripts for Execution Part 4 - Supporting Multi-User concurrency Part 5 Debugging scripts in single and multi-user mode

Copyright 2008 EMC Corporation. All rights reserved.

Define the Use Cases

What operations should be simulated? What is the relative ratio of operations? How many users perform each type of operation? How often are those operations performed? How much time between operations?

Copyright 2008 EMC Corporation. All rights reserved.

Understand Your User Behavior

Power Users
Use DMS as their primary work tool Log in once and work in the application constantly for a given period of time Infrequently log out or time out

Regular Users
Use DMS as a part of their daily tasks, but not exclusively May log in, checkout a document, work on it for a while, return to DMS later in the day Will often close browser or navigate away, or simply time out, ending their session

Occasional Users
Use DMS to support their work, but not as a primary tool May have short burst of activity, followed by no activity for hours or days

Copyright 2008 EMC Corporation. All rights reserved.

Think Time and Pacing Recommendations

Think time should reflect natural application behavior Pacing should be realistic for the user type (power, regular or occasional)
Power think time as recorded, 4-6 mins between iterations Regular think time as recorded, 8-12 mins between iterations Occasional double think time, 18-22 minutes between iterations

Be careful of timeouts from long think times or pacing between iterations

Copyright 2008 EMC Corporation. All rights reserved.

Content Transfer in Multi-User Scripts


Type of content transfer is important
View vs. Export
View operation downloads document to c:\documentum\viewed then opens file up in viewing application Export just downloads the content Both operations are equivalent from an application server load point of view, but can present client-side issues in a multi-user test

Checkout vs. Edit


Edit locks the document, downloads it to c:\documentum\checkout, then opens the file up in the editing application Checkout locks the document and downloads content to c:\documentum\checkout Both operations are equivalent from an application server load point of view, but can present client-side issues in a multi-user test

Recommendation: always use EXPORT and CHECKOUT for successful script execution

Each user will ideally have their own sandbox


Central location for checkout/checkin means high likelihood of conflicts in multi-user tests

Copyright 2008 EMC Corporation. All rights reserved.

General Script Best Practices

Start and stop each action at the same place


For example, Cabinets, right after login

Allows you to repeat actions without having to log out and log back in, simulating more realistic user activity

Copyright 2008 EMC Corporation. All rights reserved.

Capture key parameters at the end of each action, and use them at the beginning of each action
Objectlist.jsp saveClientRequestId(), saveOldFolderPath(), savePageIndex() Browsertree.jsp saveBrowsertreeRequestId() Menubar.jsp saveMenubarRequestId() Titlebar.jsp saveTitlebarRequestId()

See example scripts for more details

Copyright 2008 EMC Corporation. All rights reserved.

Simplify navigation by using TreeExpand


Folders can be navigated by clicking on the +/- sign or by clicking on the folder name
Clicking the + sign simply expands the folder to the next level (treeExpand.jsp) Clicking the foldername expands the folder and opens the folder contents in the objectlist pane (browsertree.jsp and objectlist.jsp)

Folder object ID paths can be found as shown below:


<div class="treeNodeHeight" id=__x2208._ROOT.USTAX./USTAX.0c00d60b80000303> <nobr><img src="/<appname>/wdk/theme/documentum/images/tree/S.gif" height="16"><img src="/<appname>/wdk/theme/documentum/images/tree/S.gif" height="16"><a href='#' onclick='return false' onmousedown='__x2208Expand(this);' id=73><img src="/<appname>/wdk/theme/documentum/images/tree/Tplus.gif" height="16"></a><a onclick='__x2208Click(this,event);' id=74><img src="/<appname>/wdk/theme/documentum/icons/type/t_dm_cabinet_16.gif" border="0" height="16" width="16">&nbsp;<span class=browserTreeNormal>Clients</span></a></nobr></div>

To expand the tree, pass the value in the id tag to treeExpandNode.jsp as browsertree_docbrowser_hidden_focus_0 To open the folder, pass it to the browserTree.jsp as browsertree_docbrowser_hidden_focus_0 and browsertree_docbrowser_hidden_sel_0
Copyright 2008 EMC Corporation. All rights reserved. 9

Part 2 Recording the Tests

Setup up correlation Record the scripts Modify scripts for execution

Copyright 2008 EMC Corporation. All rights reserved.

10

Recording Options - Correlation

Be sure to turn on the correlation rules provided in the LoadRunner kits from the developer website (provided in script directory as EMCDocumentum.cor)
Copyright 2008 EMC Corporation. All rights reserved. 11

Part 3 Customizing Recorded Scripts for Execution

General steps to follow Adding support for content transfer

Copyright 2008 EMC Corporation. All rights reserved.

12

Steps to Generate Load Scripts


Enable correlation in VuGen to collect WDK Clear all cookies on recording machine Record actions
Add comments at key points to help when defining transactions Do not select do not show me again in web pages if prompted

Add Username parameter to enable multi-user testing Add UCF capability where needed
Vuser_init:
Add extern

Add setUID function to lr_utils


Modify hostname to match test environment

Add setUID calls before each URL with dmfUcfClientId in the URL or POST data Replace hard-coded UID with {UID} in URL or POST data Modify wdk5-appletresultsink for import and export actions Add code to delete the file from before performing an export operation Add function to create per-user export directory

If you want to be able to repeat actions between login/logout


Add functions to save requestIds, serial numbers, page index and old folder path information to appropriate places at the end of each action

Add randomization and parameterization for hard-coded r_object_id values Add custom transactions to aid in monitoring
Copyright 2008 EMC Corporation. All rights reserved. 13

After Recording Initial Script Changes

JSESSIONID
Capture at the beginning of the script
web_reg_save_param("jsess", "LB/IC=JSESSIONID=", "RB/IC=;", "Ord=1", "Search=headers", "RelFrameId=1", "Notfound=warning", LAST);

Replace all occurrences of recorded JSESSIONID with {jsess} in the script


Most URLs for content transfer pass the JSESSIONID parameter

Copyright 2008 EMC Corporation. All rights reserved.

14

Cookies (web_add_cookie)
Remove or comment them out

Find any URLs with hard-coded object ID values and parameterize them
BrowserTree and navigation use ID values extensively

Parameterize login information

Copyright 2008 EMC Corporation. All rights reserved.

15

Simulating the fileselector Applet

The fileselector applet is used for:


Import Export Checkin from File

Selection returned as binary string to application server through wdk5appletresultsink servlet

Copyright 2008 EMC Corporation. All rights reserved.

16

wdk5-appletresultsink
web_custom_request("wdk5-appletresultsink",

Original "URL=http://{Hostname}:{PortNum}/{Context}/wdk5-appletresultsink", recorded values "Method=POST", "Resource=1", Special "RecContentType=application/x-java-serialized-object", parameters to "EncType=application/x-deflated-java-serialized-object", be used to "BodyBinary=x\\x9C\\x8DR;N\\xC3@\\x10\\.............................", simulate LAST); applet from LoadRunner web_submit_data("wdk5-appletresultsink",
"Action=http://{Hostname}:{PortNum}/{Context}/wdk5-appletresultsink", "Method=POST", "RecContentType=text/html", "Mode=HTML", ITEMDATA, "Name=key", "Value=UcfImportContainer_fileselector_0", ENDITEM, "Name=value", "Value={ImportFile}", ENDITEM, LAST);

Copyright 2008 EMC Corporation. All rights reserved.

17

wdk5-appletresultsink

Valid keys for out of the box Webtop are:


UcfImportContainer_fileselector_0
Must be a filename, not a folder

UcfExportContainer_selectdestfolder_0
Folderpath must end in a slash

If the Import or Export component has been modified, the name will change
web_submit_data("wdk5-appletresultsink", "Action=https://{Hostname}/<appname>/wdk5-appletresultsink", "Method=POST", "Referer=https://{Hostname}/<appname>/wdk/system/ucf/invoker.jsp", "RecContentType=text/html", "Snapshot=t9.inf", "Mode=HTML", ITEMDATA, "Name=key", "Value=TlsImportContainer_fileselector_0", ENDITEM, "Name=value", "Value={ImportFile}", ENDITEM, LAST)
Copyright 2008 EMC Corporation. All rights reserved. 18

Importing Multiple Files

web_submit_data("wdk5-appletresultsink", "Action={Protocol}://{Hostname}:{Port}/{Context}/wdk5-appletresultsink", "Method=POST", "Referer={Protocol}://{Hostname}:{Port}/{Context}/wdk/system/ucf/invoker.jsp", "RecContentType=text/plain", "Snapshot=t9.inf", "Mode=HTML", ITEMDATA, "Name=key", "Value=TlsImportContainer_fileselector_0", ENDITEM, "Name=value", "Value=c:\\ucf\\import\\0010\\1.zip", ENDITEM, "Name=value", "Value=c:\\ucf\\import\\0010\\2.zip", ENDITEM, "Name=value", "Value=c:\\ucf\\import\\0010\\3.zip", ENDITEM, "Name=value", "Value=c:\\ucf\\import\\0010\\4.zip", ENDITEM, "Name=value", "Value=c:\\ucf\\import\\0010\\5.zip", ENDITEM, LAST);

Copyright 2008 EMC Corporation. All rights reserved.

19

Using the UCF Client Invoker in Your Own Scripts


1. 2. Ensure that the UCF Invoker is installed and running on each of the driver machines Be sure to install the SSL certificates (if used) on development and driver machines into the JDK and/or JRE cacerts file using keytool
For example install_certificates.bat: c:\progra~1\java\jdk1.6.0_04\bin\keytool -import -trustcacerts -alias ucf -file ca.crt -keystore "c:\program files\java\jdk1.6.0_04\jre\lib\security\cacerts" c:\progra~1\java\jdk1.6.0_04\bin\keytool -import -trustcacerts -alias ucf -file ca.crt -keystore "C:\Program Files\Java\jre1.6.0_04\lib\security\cacerts

Copyright 2008 EMC Corporation. All rights reserved.

20

10

3. In vuser_init section define getUID function and load the client DLL
extern int getUID(int invokerPort, char* ucfMode, char* host, int port, char* approot, char* jsessid, char *msg); vuser_init () { lr_load_dll(c:\\UCFInvoker\\TDfUCFInvokerClient.dll");

4. Copy the setUID function from the lr_utils Action in the sample scripts into your script.

Copyright 2008 EMC Corporation. All rights reserved.

21

Using the UCF Client Invoker in Your Own Scripts (ctd)

4.

Call setUID just before any request that contains __dmfUcfClientId in the URL or the POST data
setUID("UID"); web_url("invoker.jsp;jsessionid={jsess}_2", "URL={Protocol}://{Hostname}:{Port}/{Context}/wdk/system/ucf/invoker.jsp;jsessi onid={jsess}?__dmfRequestId={ReqId1_113}&__dmfHandler=UcfInvoker_0&__dmfAction= onInvokeUcfDone&__dmfUcfClientId=12%3B{UcfKey_112}&__dmfUcfClientReqKey={UcfKey _112}&__dmfHandlerArgs=&Reload=109884e9089",

setUID should NOT be called if the dmfUcfClientId is in the Referer section only

Copyright 2008 EMC Corporation. All rights reserved.

22

11

Using the UCF Client Invoker in Your Own Scripts (ctd)

5. Replace the UID URL or POST Data


web_url("invoker.jsp;jsessionid={jsess}_2", "URL={Protocol}://{Hostname}:{Port}/{Context}/wdk/system/ucf/invoker.jsp;jsess ionid={jsess}?__dmfRequestId={ReqId1_113}&__dmfHandler=UcfInvoker_0&__dmfActio n=onInvokeUcfDone&__dmfUcfClientId={UID}%3B{UcfKey_112}&__dmfUcfClientReqKey={ UcfKey_112}&__dmfHandlerArgs=&Reload=109884e9089",
web_submit_data("fileselection.jsp", "Action={Protocol}://{Hostname}:{Port}/{Context}/webcomponent/library/contenttransfer/impor tcontent/fileselection.jsp", "Method=POST", ITEMDATA, "Name=__dmfFormId", "Value=UcfImportContainer_0", ENDITEM, "Name=__dmfAction", "Value=UcfImportContainer_0_onNext", ENDITEM, "Name=__dmfHandler", "Value=UcfImportContainer_0_UcfImportContainer_0", ENDITEM, "Name=__dmfUcfClientReqKey", "Value={UcfKey_21}", ENDITEM, // "Name=__dmfUcfClientId", "Value=2626;{UcfKey_21}", ENDITEM, "Name=__dmfUcfClientId", "Value={UID};{UcfKey_21}", ENDITEM,

Copyright 2008 EMC Corporation. All rights reserved.

23

Export File Already Exists

If file exists already, then WDK will prompt you to overwrite


causes script failure!

Delete the file before performing export void deleteFile() { char buf[100]; int errno; strcpy(buf,lr_eval_string("{ExportFile}")); lr_output_message("DEBUG: Deleting document %s",buf); if (remove(lr_eval_string("{ExportFile}")) == 0) lr_output_message("Removed new file %s", lr_eval_string("{ExportFile}")); else lr_output_message("Unable to remove %s error %d", lr_eval_string("{ExportFile}"), errno); }

Copyright 2008 EMC Corporation. All rights reserved.

24

12

Remove all UCF Communication URLs

UCF communication is also over HTTP, therefore gets recorded UCF requests will be now managed by UCF Invoker Comment out or delete any URL requests with:
InitGAIRConnector GAIRConnector Notification ACS

Copyright 2008 EMC Corporation. All rights reserved.

25

Preventing the Download of Applet Files

In normal operation, the applet jar files are downloaded and installed on first request in session
ucfinit.cab fileselection.cab

Simulation will force download each time To reduce the overhead, these can be commented out in scripts

web_url("invoker.jsp", "URL={Protocol}://{Hostname}:{Port}/{Context}/wdk/system/ucf/invoker.jsp?__dmf .. EXTRARES, //"Url=../ucfinit.cab", "Referer=", ENDITEM, //"Url=/{Context}/wdk/contentXfer/ucf.installer.config.xml", "Referer=", ENDITEM, LAST);
Copyright 2008 EMC Corporation. All rights reserved. 26

13

Part 4 Supporting Multi-User Concurrency

Checkout/Checkin
Locked by you, locked by others

Copyright 2008 EMC Corporation. All rights reserved.

27

Classic View Unlocked Document

<input type=checkbox id=actionmultiselectcheckbox_3 value='' class=actions onclick='onActionMultiselectCheckboxClick(this)'> </td> <td nowrap class="doclistlocicon"> <div class='lockiconemptyspace'/> </td>

Copyright 2008 EMC Corporation. All rights reserved.

28

14

Classic View - Checked Out By You

<input type=checkbox id=actionmultiselectcheckbox_2 value='' class=actions onclick='onActionMultiselectCheckboxClick(this)'> </td> <td nowrap class="doclistlocicon"> <span title=''><img width=16 height=16 class=defaultRepositoryLockIconStyle src='/webtop/wdk/theme/documentum/icons/indicator/ i_locked_by_you_16.gif' border=0 alt=''></span> </td>
Copyright 2008 EMC Corporation. All rights reserved. 29

Classic View - Checked Out By Others

<input type=checkbox id=actionmultiselectcheckbox_4 value='' class=actions onclick='onActionMultiselectCheckboxClick(this)'> </td> <td nowrap class="doclistlocicon"> <span title=''><img width=16 height=16 class=defaultRepositoryLockIconStyle src='/webtop/wdk/theme/documentum/icons/indicator/ i_locked_by_another_16.gif' border=0 alt=''></span> </td>
Copyright 2008 EMC Corporation. All rights reserved. 30

15

Selection Lists

When performing an action against an object, a selection list is sent that indicates which object on the page the action is to be performed against For example, this selection list indicates:
There are twenty objects on the page The twelfth one will be the target of the action The action is checkout "Name=__dmfHandlerArgs", "Value=HomeCabinet_0_action=checkout&selection=00000000000100000000", ENDITEM,

In order for this checkout to be successful, the object at that position MUST be in the correct state
Must be a document, not a folder Must be unlocked

Sample scripts check to see if that document is in the right state prior to performing the checkout/checkin action (getLockedCount)
Copyright 2008 EMC Corporation. All rights reserved. 31

Best Practices for Checkout/Checkin

Have each user checkout documents in their own sandbox


Home cabinet or custom folder is best

If users are checking out from a common area, find a way to separate them
Different document name for each user Different document in list Ensure that list size is large enough for all users performing operation or perform search to identify document to checkout/checkin

As checked out files will be downloaded to the disk on the load generator machine, be sure to assign specific vusers to specific controllers to ensure that a checked out file can be found where expected

Copyright 2008 EMC Corporation. All rights reserved.

32

16

Part 5 Debugging scripts in single and multi-user mode

LoadRunner scripts will continue to execute even when a previous page contained an error Instead of getting the page you requested, you might get:
An error has occurred History released

How do you figure out whats wrong?

Copyright 2008 EMC Corporation. All rights reserved.

33

An error has occurred

WDK applications will force you to click to a new page to get the full error
LoadRunner scripts cant do that unless you explicitly code it!

To see the stack trace, look at the wdk.log file on the application server Common causes:
Passing invalid or null data to a component Two users colliding on a single object

Check your extended logs for


is not a parameter Changes to oldFolderPath or dmfArgsId

Copyright 2008 EMC Corporation. All rights reserved.

34

17

History Released

An invalid dmfRequestId has been sent to the WDK server Causes:


Hard-coded dmfRequestId values in script
shouldnt happen if correlation rules were used on recording

Previous attempt to store the dmfRequestId failed, so invalid data is sent on next URL

Solution:
Verify in the extended logs that the dmfRequestId being sent is valid

Copyright 2008 EMC Corporation. All rights reserved.

35

Steps to Debug in Single-User Mode

Turn on extended logging, with client request and server response Open output.txt from script directory in an external editor to aid in debugging Search for strings that indicate what the problem is
is not a parameter An error has occurred backdetector.jsp prompt.jsp

Copyright 2008 EMC Corporation. All rights reserved.

36

18

Steps to Debug Multi-User Errors

If possible, enable just-in-time logging, max size 100 Search for same phrases in user logs Investigate errors in wdk log files

Copyright 2008 EMC Corporation. All rights reserved.

37

Sample Error Trapping Functions


getErrorMessageCount() { lr_continue_on_error (1); web_reg_find("Text=/component/errormessage","SaveCount=errorcount",LAST); } getErrorPage() { web_url("errorMessage.jsp", "URL=https://{Hostname}/<appname>/component/errormessage", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Mode=HTML", LAST); } processError () { if (strcmp(lr_eval_string("{errorcount}"),"0") != 0){ getErrorPage(); lr_exit(LR_EXIT_VUSER,LR_FAIL); } lr_continue_on_error(4); }
Copyright 2008 EMC Corporation. All rights reserved. 38

19

Instrumenting Scripts to Trap Errors


getErrorMessageCount(); saveBrowsertreeRequestId(); web_submit_data("browsertree.jsp_2", "Action=https://{Hostname}/<appname>/webtop/classic/browsertree/browsertree.jsp", "Method=POST", "RecContentType=text/html", "Referer=https://{Hostname}/<appname>/webtop/classic/browsertree/browsertree.jsp", "Snapshot=t191.inf", "Mode=HTML", ITEMDATA, "Name=__dmfFormId", "Value=BrowserTree_0", ENDITEM, "Name=__dmfAction", "Value=BrowserTree_0_refreshTreeFromAbsolutePath", ENDITEM, .. .. "Name=__dmfInitDocbasePassword", "Value=", ENDITEM, "Name=__dmfInitDocbaseDomain", "Value=", ENDITEM, "Name=__dmfInitLocale", "Value=", ENDITEM, "Name=__dmfSerialNumber", "Value={SerialNumber_57}", ENDITEM, "Name=__dmfClientId", "Value=1202566327209", ENDITEM, LAST); processError();
Copyright 2008 EMC Corporation. All rights reserved. 39

Locating Errors in Extended Output

This information is something you should pass on to the application team


It is usually not an issue with the load test

Copyright 2008 EMC Corporation. All rights reserved.

40

20

DMCL Tracing for Deep Analysis

To get application logs outlining APIs sent, data received and show APIlevel errors, turn on DMCL tracing Should only be run in single-user mode unless problem is only visible in multi-user tests To turn on:
https://<hostname>:<port>/<appname>/wdk/dmclTrace.jsp?level=10

To turn off:
https://<hostname>:<port>/<appname>/wdk/dmclTrace.jsp?level=0

File is created on application server at path shown in response Developers can analyze the trace file for issues and errors

Copyright 2008 EMC Corporation. All rights reserved.

41

Content Transfer Hangs or Fails

The UCF invoker must be running and return a UID value >= 0, otherwise it will hang or return an error Causes:
UCF invoker is not running Path to TdfUCFInvokerClient.dll is not correct in vuser_init section UCFWin32JNI.dll is not in search PATH (copy it from the UCF client bin directory to the UCF Invoker directory if it does not exist) Incorrect JSESSIONID is passed as argument to getUID function

Check UCF Invoker logs for errors indicating the source of the problem

Copyright 2008 EMC Corporation. All rights reserved.

42

21

Problem #1: Script Fails Due to Repository Change

Issue:
Script recorded against one docbase, and played back against another, OR Repository structure has been changed or rebuilt

Cause:
Script will have hard-coded r_object_id values that are no longer valid

Solution:
Parameterize all r_object_id values in the script

Copyright 2008 EMC Corporation. All rights reserved.

43

Problem #2 Script Fails After Application Change

Issue:
Script worked fine until a small change was made in the application code

Cause:
Application code has introduced new or modified URLs that are not in original script, or Application code has modified a pattern that is parameterized and used elsewhere

Solution:
Identify the source of the change and update the script to reflect it

Copyright 2008 EMC Corporation. All rights reserved.

44

22

Problem #3 Script Runs Fine in Single-User, but Fails in Multi-User

Problem:
The script runs without fail in a single user environment, but many users fail in multiuser runs

Cause:
It is likely that there is some contention in a shared area, and multiple users are trying to work on the same item

Solution:
Wherever possible, architect the tests so that each user has their own sandbox Ensure that vusers run on specific load generators to ensure that checked out files will be available for checkin operations

Copyright 2008 EMC Corporation. All rights reserved.

45

Problem #4 Export Operations Fail

Problem:
When the user exports the file to disk, it works the first time, but fails in subsequent tests

Cause:
A file with the same name already exists in the export folder, and WDK prompts you to overwrite the file
Search extended logs for prompt.jsp

Solution:
Before exporting a file, have the virtual user try to delete it first

Copyright 2008 EMC Corporation. All rights reserved.

46

23

Problem #5 Modular Script Does Not Iterate Properly

Problem:
A script recorded in one step has been broken down into multiple actions to allow for a single login/logout and repeated iterations of the core activity

Cause:
1. The core activity does not start and end from the same WDK location. 2. The dmfRequestId and SerialNumber values are not valid 3. OldFolderPath or PageIndex have not been updated properly

Solution:
Ensure that the starting and ending location is the same (ie. Cabinets view or Inbox) Record the last values of each frames dmfRequestId, SerialNumber, OldFolderPath and PageIndex and replace them at the beginning of the action

Copyright 2008 EMC Corporation. All rights reserved.

47

Problem #6: Users fail with long pacing times

Problem:
When simulating occasional users with long pacing times, users fail when beginning a new iteration

Cause:
User sessions may be released due to session timeout.

Solution:
Depending on transaction pacing and think time used in the scripts, you might have to increase the session timeout located in WEB-INF/web.xml as well as in application server

Copyright 2008 EMC Corporation. All rights reserved.

48

24

Problem #7: Scripts Fail When Run from Controller

Problem:
Load Runner script works using VuGen but fails in controller.

Cause:
Wrong protocol for replay, or Load Generator not properly configured with files, folders, UCF invoker, SSL certificates

Solution:
Make sure "WinInet replay instead of Sockets (Windows only)" is turned off. Make sure UCF Invoker is running and configured properly on all load generators Be sure to run createsourcefiles.bat if running the kit

Copyright 2008 EMC Corporation. All rights reserved.

49

Problem #8: Checkout Fails Under Load

Problem:
After a number of tests have been run, checkouts start to fail.

Cause:
It could be that all the documents are already checked out and there are none available for checkout.

Solution:
Capture information before checkout to make sure that checkout is possible before invoking step Unlock all documents between tests to clean up any locked docs to start clean

Copyright 2008 EMC Corporation. All rights reserved.

50

25

Potrebbero piacerti anche