11.07.2015 Views

LoadRunner Scripting Best Practices Chase Harris Consultant ...

LoadRunner Scripting Best Practices Chase Harris Consultant ...

LoadRunner Scripting Best Practices Chase Harris Consultant ...

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>LoadRunner</strong> <strong>Scripting</strong> <strong>Best</strong> <strong>Practices</strong><strong>Chase</strong> <strong>Harris</strong><strong>Consultant</strong> Software EngineerEMC© Copyright 2008 EMC Corporation. All rights reserved.1Topics 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.21


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.3Understand 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.42


Think Time and Pacing Recommendations Think time should reflect natural application behavior Pacing should be realistic for the user type (power, regular oroccasional)– 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.5Content 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-sideissues 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 editingapplication 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-sideissues 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.63


General Script <strong>Best</strong> <strong>Practices</strong> 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 logback in, simulating more realistic user activity© Copyright 2008 EMC Corporation. All rights reserved.7 Capture key parameters at the end of each action, and use them at thebeginning 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.84


Simplify navigation by using TreeExpand Folders can be navigated by clicking on the +/- sign or by clicking onthe 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 theobjectlist pane (browsertree.jsp and objectlist.jsp) Folder object ID paths can be found as shown below:&nbsp;Clients To expand the tree, pass the value in the “id” tag totreeExpandNode.jsp asbrowsertree_docbrowser_hidden_focus_0 To open the folder, pass it to the browserTree.jsp asbrowsertree_docbrowser_hidden_focus_0 andbrowsertree_docbrowser_hidden_sel_0© Copyright 2008 EMC Corporation. All rights reserved.9Part 2 – Recording the Tests Setup up correlation Record the scripts Modify scripts for execution© Copyright 2008 EMC Corporation. All rights reserved.105


Recording Options - Correlation Be sure to turn on the correlation rules provided in the <strong>LoadRunner</strong> kitsfrom the developer website (provided in script directory asEMCDocumentum.cor)© Copyright 2008 EMC Corporation. All rights reserved.11Part 3 – Customizing Recorded Scripts forExecution General steps to follow Adding support for content transfer© Copyright 2008 EMC Corporation. All rights reserved.126


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 placesat 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.13After Recording – Initial Script Changes JSESSIONID– Capture at the beginning of the scriptweb_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.147


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.15Simulating the fileselector Applet The fileselectorapplet is used for:– Import– Export– Checkin from File Selection returned as binary string to application server through wdk5-appletresultsink servlet© Copyright 2008 EMC Corporation. All rights reserved.168


wdk5-appletresultsinkweb_custom_request("wdk5-appletresultsink",Original "URL=http://{Hostname}:{PortNum}/{Context}/wdk5-appletresultsink",recorded values "Method=POST","Resource=1","RecContentType=application/x-java-serialized-object","EncType=application/x-deflated-java-serialized-object","BodyBinary=x\\x9C\\x8DR;N\\xC3@\\x10\\.............................",LAST);Specialparameters tobe used to“simulate”applet from<strong>LoadRunner</strong>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.17wdk5-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 willchangeweb_submit_data("wdk5-appletresultsink","Action=https://{Hostname}//wdk5-appletresultsink","Method=POST","Referer=https://{Hostname}//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.189


Importing Multiple Filesweb_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.19Using the UCF Client Invoker in Your Own Scripts1. Ensure that the UCF Invoker is installed and running on each of the drivermachines2. Be sure to install the SSL certificates (if used) on development and drivermachines into the JDK and/or JRE cacerts file using keytoolFor 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.2010


3. In vuser_init section define getUID function and load the clientDLLextern 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 samplescripts into your script.© Copyright 2008 EMC Corporation. All rights reserved.21Using the UCF Client Invoker in Your Own Scripts (ctd)4. Call “setUID” just before any request that contains __dmfUcfClientId in theURL or the POST datasetUID("UID");web_url("invoker.jsp;jsessionid={jsess}_2","URL={Protocol}://{Hostname}:{Port}/{Context}/wdk/system/ucf/invoker.jsp;jsessionid={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.2211


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.25Preventing the Download of Applet Files In normal operation, the applet jar files are downloaded and installedon first request in session– ucfinit.cab– fileselection.cab Simulation will force download each time To reduce the overhead, these can be commented out in scriptsweb_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.2613


Classic View - Checked Out By You© Copyright 2008 EMC Corporation. All rights reserved.29Classic View - Checked Out By Others© Copyright 2008 EMC Corporation. All rights reserved.3015


Selection Lists When performing an action against an object, a selection list is sent thatindicates 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 positionMUST 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 toperforming the checkout/checkin action (getLockedCount)© Copyright 2008 EMC Corporation. All rights reserved.31<strong>Best</strong> <strong>Practices</strong> 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 separatethem– Different document name for each user– Different document in list– Ensure that list size is large enough for all users performing operation or performsearch to identify document to checkout/checkin As checked out files will be downloaded to the disk on the loadgenerator machine, be sure to assign specific vusers to specificcontrollers to ensure that a checked out file can be found whereexpected© Copyright 2008 EMC Corporation. All rights reserved.3216


Part 5 – Debugging scripts in single and multi-usermode <strong>LoadRunner</strong> scripts will continue to execute even when a previous pagecontained an error Instead of getting the page you requested, you might get:– “An error has occurred”– “History released” How do you figure out what’s wrong?© Copyright 2008 EMC Corporation. All rights reserved.33An error has occurred… WDK applications will force you to click to a new page to get the full error– <strong>LoadRunner</strong> scripts can’t 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.3417


History Released An invalid dmfRequestId has been sent to the WDK server Causes:– Hard-coded dmfRequestId values in script shouldn’t 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.35Steps 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 indebugging 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.3618


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.37Sample Error Trapping FunctionsgetErrorMessageCount() {lr_continue_on_error (1);web_reg_find("Text=/component/errormessage","SaveCount=errorcount",LAST);}getErrorPage() {web_url("errorMessage.jsp","URL=https://{Hostname}//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.3819


Instrumenting Scripts to Trap ErrorsgetErrorMessageCount();saveBrowsertreeRequestId();web_submit_data("browsertree.jsp_2","Action=https://{Hostname}//webtop/classic/browsertree/browsertree.jsp","Method=POST","RecContentType=text/html","Referer=https://{Hostname}//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.39Locating 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.4020


DMCL Tracing for Deep Analysis To get application logs outlining APIs sent, data received and show APIlevelerrors, turn on DMCL tracing Should only be run in single-user mode unless problem is only visible inmulti-user tests To turn on:– https://://wdk/dmclTrace.jsp?level=10 To turn off:– https://://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.41Content 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 tothe 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.4221


Problem #1: Script Fails Due to RepositoryChange 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.43Problem #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.4422


Problem #3 – Script Runs Fine in Single-User, butFails in Multi-User Problem:– The script runs without fail in a single user environment, but many users fail in multiuserruns Cause:– It is likely that there is some contention in a shared area, and multiple users are tryingto 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 fileswill be available for checkin operations© Copyright 2008 EMC Corporation. All rights reserved.45Problem #4 – Export Operations Fail Problem:– When the user exports the file to disk, it works the first time, but fails in subsequenttests Cause:– A file with the same name already exists in the export folder, and WDK prompts youto 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.4623


Problem #5 – Modular Script Does Not IterateProperly Problem:– A script recorded in one step has been broken down into multiple actions to allowfor 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 frame’s dmfRequestId, SerialNumber,OldFolderPath and PageIndex and replace them at the beginning of the action© Copyright 2008 EMC Corporation. All rights reserved.47Problem #6: Users fail with long pacing times Problem:– When simulating occasional users with long pacing times, users fail when beginning anew 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 toincrease the session timeout located in WEB-INF/web.xml as well as in applicationserver© Copyright 2008 EMC Corporation. All rights reserved.4824


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, SSLcertificates 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.49Problem #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 noneavailable for checkout. Solution:– Capture information before checkout to make sure that checkout is possible beforeinvoking step– Unlock all documents between tests to clean up any locked docs to start “clean”© Copyright 2008 EMC Corporation. All rights reserved.5025

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!