Forum Discussion

jimmykilleen's avatar
jimmykilleen
New Contributor
6 years ago

Get VB Script Unit Name from Distributed Testing setup

Hi,

 

I am currently running distributed tests with the following hierarchy

  1. Individual VB Scripts with a list of sub routines
  2. A Driver VB Script which runs all the sub routines from 1.
  3. A Job which contains a Task to run the Driver VB Script
  4. This Job is then added to the project explorer as a test item
  5. A Scheduled Task runs the Project 

 

I have a function that will output the CPU & Memory usage for 2 exes as to a csv file.

I want to call this function from each individual sub routine (in 1. above) as i want output the CPU & Mem usage.

I have tried the "Project.TestItems.Current.ElementToBeRun.Caption"  but with no luck. I get :

 
VBScript runtime error.
Object required: 'Project.TestItems.Current'

 

My code is below. My question is how can i get down to unit level in order to get the sub routine name to log to the file.

 

Sub CPU_Mem_Usage

Dim VerFileName, VerInfo, TestItems, tName
VerFileName = "\\MyPC1\c\program files\MyExe\MyExe.exe"
Set VerInfo = aqFileSystem.GetFileInfo(VerFileName).VersionInfo

sFolder = "\\Server1\TestComplete\FutaTill\Results\"
aqFileSystem.CreateFolder(sFolder)
sPath = sFolder & "\Build_"&VerInfo.FileFullVersion&"\Build_"&VerInfo.FileFullVersion&".csv"
tName = Project.TestItems.Current.ElementToBeRun.Caption

 

If Not aqFile.Exists(sPath) Then
Call aqFile.Create(sPath)
Call aqFile.WriteToTextFile(sPath, "CPU & Memory Usage Statistics for My Exe Build Version " & VerInfo & vbCrlf , aqFile.ctANSI, False)
Call aqFile.WriteToTextFile(sPath, "Test Date & Time: " & aqDateTime.Now & vbCrlf , aqFile.ctANSI, False)
Call aqFile.WriteToTextFile(sPath, "" & vbCrlf , aqFile.ctANSI, False)
Call aqFile.WriteToTextFile(sPath, "Time, Script Name,,,,,,,MyExe, CPU (%), Mem Usage (K),, MyExe2, CPU (%), Mem Usage (K)" & vbCrlf , aqFile.ctANSI, False)
Call aqFile.WriteToTextFile(sPath, "*****************************************************************************************************************************************" & vbCrlf , aqFile.ctANSI, False)
End If

Call aqFile.WriteToTextFile(sPath, aqDateTime.Time & "," & tName & ",,,,,,,," & Sys.Process("MyExe").CPUUsage & "," & Sys.Process("MyExe").MemUsage & "," & ",," & Sys.Process("MyExe2").CPUUsage & "," & Sys.Process("MyExe2").MemUsage & vbCrlf , aqFile.ctANSI, False)
End Sub

 

All help greatly appreciated

 

Thanks,

Jimmy

 

  • Hi jimmykilleen,

     

    I'm not sure about the name of the script unit. I'll give you some sources that may help you. 

     

    It's possible to get the name of the currently running script routine. There is a sample script - you can find it here.

    It's written in JavaScript. To use it in VBScript, you can add it to TestComplete's Script Extensions.

     

    Community, any more thoughts?

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi jimmykilleen,

     

    I'm not sure about the name of the script unit. I'll give you some sources that may help you. 

     

    It's possible to get the name of the currently running script routine. There is a sample script - you can find it here.

    It's written in JavaScript. To use it in VBScript, you can add it to TestComplete's Script Extensions.

     

    Community, any more thoughts?