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
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

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

' 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

' close the file
Close iFileNum

Row = Row + 1

End Sub


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s