Loadrunner Batch Scheduler – Excel Version #2

From the previous post, it should be possible to see that the next_tick function which counts the time is our trigger for execution.
Specifically this loop and if combination:

For i = 0 To UBound(ArrTimes)
If [A1].Value = ArrTimes(i) Then
Application.StatusBar = "Running test id: " & Range("A" & i + 6).Value

End If
Next i

Since I first wrote that last week, I’ve added a field to state that a run has been “done”. And I’ve built in a little tolerance by checking if the current time is greater than the execution start time – stored as ArrTime(n).

I’ve also borrowed some code from VBA Express to terminate a running process. Now I’m not terminating the process, I’m just checking if WLRun.exe aka the controller is running.

So the latest code looks like this:

For i = 0 To UBound(ArrTimes)
If [A1].Value >= ArrTimes(i) And Range("F" & i + 6) <> "DONE" Then

'Check if LR is already running
strTerminateThis = "wlrun.exe" 'Process to terminate,

Set objWMIcimv2 = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cimv2") 'Connect to CIMV2 Namespace

Set objList = objWMIcimv2.ExecQuery _
("select * from win32_process where name='" & strTerminateThis & "'") 'Find the process to terminate

If objList.Count = 0 Then 'If 0 then process isn't running
Application.StatusBar = "Running test id: " & Range("A" & i + 6).Value
Range("F" & i + 6) = "DONE"
Call StartTest(Range("B" & i + 6).Value, Range("C" & i + 6).Value)


Application.StatusBar = "Loadrunner Controller is still running"

End If

End If
Next i

I’ve just replaced the existing section with that, but I’ll post the full deliverable at some point (when it’s finished 🙂 )

I’ve also defined the module to call the controller.

Sub StartTest(Scenario_Path, Results_Path)

'Wlrun.exe -Run -TestPath scenario.lrs -ResultName res_folder
strCommand1 = Range("D1").Value 'Path to WLRun.exe
strCommand2 = Scenario_Path
strCommand3 = Results_Path

strCommand = strCommand1 & " -Run - TestPath " & strCommand2 & " -ResultName " & strCommand3
MsgBox (strCommand)
'Shell (strCommand)

End Sub

At the moment it just message_boxes the command string for testing purposes.

So now, we have:

A time-based system within Excel which will run a defined scenario at the appropriate time. I haven’t figured out yet what I’d like to do if WLRun is still running, but it’s coming together and I think that’s the last thing. I think I’ll add a minute on to all future runs to delay the system.

I also added an autoschedule function, mostly for testing purposes. I’ll document that in a future post, it’s not really important.

Leave a Reply

Your email address will not be published. Required fields are marked *