Set up LoadRunner to run nightly

To get LoadRunner to run nightly required two things. The first was a batch file that would execute LoadRunner and then invoke the analysis and the second was how to schedule the execution on the controller.

The batch file to run LoadRunner at night and to save the results in a specific directory for that nights run is shown below:REM Batch to run nighlty performance test REM REM Thanks to Simon Shepard at http://www.ss64.com for date code REM Calculate today date FOR /f "tokens=6-8 delims=/ " %%G IN ('NET TIME \\%computername%') DO ( SET _mm=%%G SET _dd=%%H SET _yy=%%I ) REM Run LoadRunner "C:\...\bin\Wlrun.exe" -Run -TestPath "P:\Projects\...\PeakHourSmall.lrs" -ResultLocation "P:\...\Results" -ResultCleanName Night-%_dd%-%_mm%-%_yy% REM Run analysis "C:\...\bin\AnalysisUI.exe" -RESULTPATH "P:\...\Night-%_dd%-%_mm%-%_yy%\Night-%_dd%-%_mm%-%_yy%.lrr"

To get the batch file to run as a scheduled task took longer than expected due to some restriction on the PC at work. To overcome this I had to use schtask.exe to schedule the batch.schtasks.exe /create /SC daily /ST 01:50:00 /TR "P:\...\Nightly.bat" /TN RunPerfTest

The nightly LoadRunner test now runs at 1:50 in the morning and the results are waiting when I arrive in the morning.

Saving results of SQL query to a LoadRunner parameter

Here is an example of how to save the results of a query to a loadrunner parameter. In this example I want to know the prod_code for a particular user whos user name is held in the parameter pUserID. To do this you have to add a lrd_ora8_save_col statement BEFORE the fetch statement.

lrd_ora8_handle_alloc(OraEnv1, STMT, &OraStm7, 0);
lrd_ora8_stmt(OraStm7, "select indiv,prod_code,last_up_seq from product_users"
"where indiv_uid = '{pUserID}'", 1, 32, 0);
lrd_ora8_exec(OraSvc1, OraStm7, 0, 0, &uliRowsProcessed, 0, 0, 0, 0, 0);
lrd_ora8_bind_col(OraStm7, &OraDef9, 1, &INDIVD10, 0, 0);
lrd_ora8_attr_set(OraDef9, CHARSET_FORM, "1", -1, 0);
lrd_ora8_bind_col(OraStm7, &OraDef10, 2, &PROD_CODE_D11, 0, 0);
lrd_ora8_attr_set(OraDef10, CHARSET_FORM, "1", -1, 0);
lrd_ora8_bind_col(OraStm7, &OraDef11, 3, &LAST_UPE_SEQ_D12, 0, 0);
lrd_ora8_save_col(OraStm7, 2, 1, 0, "prod_code");
lrd_ora8_fetch(OraStm7, -1, 15, &uliFetchedRows, PrintRow8, 2, 0, 0);

lrd_handle_free(&OraStm7, 0);

lr_message("The users product code is %s",lr_eval_string("{prod_code}"));

The second and third arguementare the column and row number with the 1,1 returns the value in the first column and the first row, The value is stored in the last arguement. Note that if no value is returned the error will be an unhelpful Parameter is not initialized.

LoadRunner Analysis Importing PerfMon Data

I have recently imported some perfmon data into LoadRunner analysis. First of all I had to use perfmon’s relog command to convert the data into a CSV file.

I then imported this using Tools -> External Monitors -> Import Data. Which leads you to the following dialogue box.



I think this is because I had selected the Time Zone as . So I reloged the data to match the start and end time of the LR results and imported again with the Time Zone set to 

Expanding LoadRunner functions

I quickly wanted to get some lr_status message outputted to the console for every LoadRunner transaction in a script, I basically wanted to insert a status message every time the lr_start_transaction was called to output the transaction name to the console. however, it was a large script and I didn’t want to make any code changes to the load runner script. So I wanted to expand the existing function. The code below was added into the vinit section.

void my_start_transaction (char *name)
{
lr_vuser_status_message("Starting Transaction %s",name);
lr_start_transaction(name);
return ;
};
vuser_init()
{

#define lr_start_transaction(x) my_start_transaction(x)

return 0;
}


LoadRunner Function Override

Creating LoadRunner Dynamic Transaction Names

Today I wanted to use parameterized transaction names within a LoadRunner script. As I thought that a particular transaction was failing after a particular number of iterations. Luckily this was pretty simple in LoadRunner. It was just a case of using lr_eval_string in the call to the transaction wrapper.

lr_start_transaction(lr_eval_string("Do Something {pIteration}"));

lr_end_transaction(lr_eval_string("Do Something {pIteration}"), LR_AUTO);

You have to be careful above to make sure that start and end transaction names are the same. To overcome that problem I created a string variable to hold the LoadRunner transaction name.

char sTranName[20];

sprintf(sTranName,lr_eval_string("TransactionA_{pIteration}"));
lr_start_transaction(sTranName);

lr_end_transaction(sTranName,LR_AUTO);

Recording LoadRunner Oracle Forms Object Names

This week I am perforamance testing an Oralce Forms applicaiton. When recording a loadrunner scripts for Oracle forms (NCA protocol) you will want the object / deverlopers name to appear in the scripts to aid readability.

To do this you need to ammend the URL to incude ?play=&record=names. So for the user you need to change the profile. You will need SYSADMIN privileges to do this.

So login and navigate down the tree System Administrator -> Security -> Define



Next select Profile: System



Search for the user you are using for recording and ICX: Forms Launcher



Amend the URL with ?play=&record=names”


Save and then you are good to record the object names with that use.

Excel Macro to read a LoadRunner scenario file

Doing some performance testing on site this week where there is only one LoadRunner controller. That was in use and I wanted to see the number of virtual users for each script set up in the Loadrunner scenario file (.lrs). So I wrote this Excel Macro to provide the data.

It prompts for the scenario file (.lrs) and then parses the file to list out the group, script name and the vuser count.

This is a bit of quick and dirty code and I am sure it will develop as it sees different scenarios but I thought I would share it with you.

Sub ReadALRScenario()

Dim sFileName As String
Dim iFileNum As Integer
Dim sBuf As String

' edit this to your defaul directory:
sFileName = "C:\Users\pengland\Documents\Projects\"

NewFN = Application.GetOpenFilename(FileFilter:="LoadRunner Scenario, *.lrs", Title:="Please select a file")
If NewFN = False Then
' User Pressed Cancel
MsgBox "You need to select a valid file"
Exit Sub
Else
sFileName = NewFN
End If

' does the file exist? simpleminded test:
If Len(Dir$(sFileName)) = 0 Then
MsgBox ("Can't find file")
Exit Sub
End If

Range("A1").Select
Row = 0

iFileNum = FreeFile()
Open sFileName For Input As iFileNum

Do While Not EOF(iFileNum)
Line Input #iFileNum, sBuf
'Now you have the next line of the file in sBuf
'Capture UiName
If InStr(sBuf, "UiName") > 0 Then
UniName = Mid(sBuf, 8, Len(sBuf) - 7)
End If

If InStr(sBuf, ".usr") > 0 Then
LastOcc = InStrRev(sBuf, "\") + 1
Length = Len(sBuf) - InStrRev(sBuf, "\") - 4
ActiveCell.Offset(Row, 0) = UniName
ActiveCell.Offset(Row, 1) = Mid(sBuf, LastOcc, Length)
ActiveCell.Offset(Row, 2) = -1

Row = Row + 1
End If
Loop

' close the file
Close iFileNum

'For Each Script count number of =script names in thr file

NumOfScripts = Row - 1
Row = 0

Do While Row 0 And (Len(sBuf) - 1) = Len(SearchString) Then
ActiveCell.Offset(Row, 2) = ActiveCell.Offset(Row, 2) + 1
End If
Loop

' close the file
Close iFileNum

Row = Row + 1
Loop

End Sub

Script to delete unwanted LoadRunner vugen files

Today it was quiet on the performance testing front so I had time to create a vbscript to delete unwanted loadrunner vugen files.

The script is run from the cscript command and will be prompted for the folder for your loadrunner vugen script. It deletes .log, .idx and .txt files and make sure you have closed vugen before you run the script.


On Error Resume Next
Const WINDOW_HANDLE = 0
Const BIF_EDITBOX = &H10
Const BIF_NONEWFOLDER = &H0200
Const BIF_RETURNONLYFSDIRS = &H1
Set objShell = CreateObject("Shell.Application")
Set wshShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
'**Browse For Folder To Be Processed
strPrompt = "Please select the folder to process."
intOptions = BIF_RETURNONLYFSDIRS + BIF_NONEWFOLDER + BIF_EDITBOX
strFolderPath = Browse4Folder(strPrompt, intOptions, strTargetPath)

Set fso=CreateObject("Scripting.FileSystemObject")

For Each file In fso.GetFolder(strFolderPath).Files
strExtension = Right(file.Name,4)
If strExtension = ".log" Or strExtension = ".idx" Or strExtension = ".txt" Then
Wscript.Echo file.Name
file.Delete
End If
Next

Function Browse4Folder(strPrompt, intOptions, strRoot)
Dim objFolder, objFolderItem
On Error Resume Next
Set objFolder = objShell.BrowseForFolder(0, strPrompt, intOptions, strRoot)
If (objFolder Is Nothing) Then
Wscript.Quit
End If
Set objFolderItem = objFolder.Self
Browse4Folder = objFolderItem.Path
Set objFolderItem = Nothing
Set objFolder = Nothing
End Function

LoadRunner Unix Time Stamp with milliseconds

I have been working with the SAP WEB protocol this week and needed to generate the windowid which is unix time (time since the 1st January 1970) but including milliseconds. Found this loadrunner function that provides unix time including milliseconds.

web_save_timestamp_param("tstamp", LAST);

lr_output_message("The time is %s", lr_eval_string("{tstamp}"));

Things to correlate in a SAP Web LoadRunner Scipt

I have been doing some SAP web scripting this week and although have been using the SAP Web protocol I have noticed that we still need to do manual correlation.
These are the 3 things I need to correlate:

ClientWindowID e.g WID1339591301202

This is not specifically a parameter that needs correlation but it a value generated in client side JavaScript which is basically the Unix time including milliseconds. Lucky there is a LoadRunner function that generates this. web_save_timestamp_param("pWID",LAST);

sap-wd-secure-id e.g. 30b66c21b9fd11e1bd5f000005ee7aaa5408212193

I have noticed that this parameter does change in some scripts I have written so be careful to extract out appropriately. This is the code I used to extract out the parameter:

web_reg_save_param("pSecureID",
"LB/IC=sap-wd-secure-id=",
"RB/IC=&",
"Ord=1",
"Search=Body",
"RelFrameId=1",
LAST);

wi_id e.g. 000003799238

This parameter appears when a window is spawned.
web_reg_save_param("pWi_id",
"LB/IC=wi_id%3D",
"RB/IC=\"",
"Ord=1",
"Search=Body",
"RelFrameId=1",
LAST);