LoadRunner Scripting Notes

From PeformIQ Upgrade
Jump to navigation Jump to search

Customizing the Script Configuration File

The .usr file is the primary configuration file for the script.

Sample of the internal format is as follows:

[General]
Type=QTWeb
RecordedProtocol=NoAvailableInfo
DefaultCfg=default.cfg
AppName=
BuildTarget=
ParamRightBrace=]
ParamLeftBrace=[
NewFunctionHeader=1
LastActiveAction=login
CorrInfoReportDir=
LastResultDir=
DevelopTool=Vugen
MajorVersion=8
MinorVersion=1
ParameterFile=Config_DC__01.prm
GlobalParameterFile=
LastModifyVer=8.1.4.0
[TransactionsOrder]
Order=""
[Actions]
vuser_init=vuser_init.c
Recording=Recording.c
login=login.c
logoff=logoff.c
SelectDC=SelectDC.c
vuser_end=vuser_end.c
[Recorded Actions]
vuser_init=0
Recording=1
login=0
logoff=0
SelectDC=0
vuser_end=0
[Replayed Actions]
vuser_init=0
Recording=0
login=0
logoff=0
SelectDC=0
vuser_end=0
[Modified Actions]
vuser_init=0
Recording=0
login=0
logoff=0
SelectDC=0
vuser_end=0
[RunLogicFiles]
Default Profile=default.usp
[StateManagement]
1=1
5=0
6=1
7=0
8=0
9=0
10=0
11=0
12=0
13=0
14=0
15=0
CurrentState=6
VuserStateHistory= 0 1048576
LastReplayStatus=0

Customizations

Parameter Delimiters

Some web pages use '{' and '}' in form data - in which case - to avoid errors being generated during script execution replace thse with another character pair such as, '[' and ']'. This can be done either via the GUI (details...) or by modifying the following lines in the .usr file:

ParamRightBrace=]
ParamLeftBrace=[

Defining the Parameter Definition File

This is done with the following:

ParameterFile=Config_DC__01.prm

Defining Parameters

Parameters are defined in the .prm (i.e. <SCRIPT>.prm) file. The path to this is defined in 'ParameterFile' in the script configuration file (<SCRIPT>.usr).

Its structure is as follows:

[parameter:Password]
Delimiter=","
ParamName="Password"
TableLocation="Local"
ColumnName="Password"
Table="Parameters\Users.dat"
GenerateNewVal="EachIteration"
Type="Table"
value_for_each_vuser=""
OriginalValue="gerra"
auto_allocate_block_size="1"
SelectNextRow="Same line as UserId"
StartRow="1"
OutOfRangePolicy="ContinueWithLast"
[parameter:UserId]
Delimiter=","
ParamName="UserId"
TableLocation="Local"
ColumnName="UserId"
Table="Parameters\Users.dat"
GenerateNewVal="Once"
Type="Table"
value_for_each_vuser=""
OriginalValue="pepperm"
auto_allocate_block_size="1"
SelectNextRow="Unique"
StartRow="1"
OutOfRangePolicy="ContinueWithLast"

Initially, it makes sense to define parameters via the GUI. However, once you begin to cookie cut scripts it is easier to copy this file into the new script directory. Customize it for the new script (if requried) and add a reference to it into the .usr file as described above.

In some cases, where there are many and complex parameters it might make sense to generate this file automatically using a script (see Generating LoadRunner PRM file).

More on this later...

I tend to put all parameter files into a Parameter sub-directory to keep them together and to aid copying them as a block. When you use the GUI to define parameters the full windows pathname of the parameter file will be used in the parameter file. This will cause a proble if you ever change the path of the script directory - as you will likely do if you develop scripts on one machine and then copy them across to the Controller system. It is much better to ensure that the parameter file paths are stored as 'relative' path names (rather than 'absolute' ones).

Relative pathnames are encoded thus:

TableLocation="Local"
Table="Parameters\Users.dat"

While absolute pathnames will be encoded as follows:

TableLocation="C:\lr\XXX\Scripts\XXXX\Parameters"
Table="Users.dat"

If you are automatically generating or customizing the parameter file by script, think about refactoring paths as relative rather than absolute ones.

Ultimately, I aim to have Python scripts which setup the parameters automatically once I have recorded a script.

This entails:

  • make Parameters directory in script directory
  • copy in parameter files (from a standard location for the project) into the Parameters folder.
  • Generate (or copy and modify) the prameter definition file (.prm) into the script directory
  • Link this file into the script configuration file (.usr)