Gen Functions
'########################################################################################################################################################################
'#Function Description: Double-Click on the specific link for the object
'#Input Parameters: (e.g. Browser("cabutars Wealth Online").Page("View/change payments").Link("Confirm")
'# Browser("cabutars Wealth Online").Page("Make a payment/transfer").WebButton("Confirm"))
'#Return Values: True/False
'#######################################################################################################################################################################
Public Function Object_DoubleClick(Obj)
Object_Text = Obj.ToString
Select Case True
Case Not Obj.Exist
ReportStepResult Test_Step_Id, "Failed", Object_Text & " does not exist on current page"
Object_DoubleClick = False
Case Obj.GetROProperty("visible") = False
ReportStepResult Test_Step_Id, "Failed", Object_Text & " is not visible"
Object_DoubleClick = False
Case Obj.Object.isDisabled
ReportStepResult Test_Step_Id, "Failed", Object_Text & " is disabled"
Object_DoubleClick = False
Case Else
Obj.Click
Obj.FireEvent "ondblclick"
Object_DoubleClick = True
End Select
End Function
'########################################################################################################################################################################
'#Function Description: The function sets the given radio button object
'#Input Parameters:Radio button object (e.g. Set Obj = Browser("cabutars Wealth Online").Page("Make a payment/transfer").WebRadioGroup("PaymentTransferType"))
'#Return Values: True/Error Message
'#######################################################################################################################################################################
Public Function Set_Radio_Group_Button(BtnObj,GrpId)
If Left(GrpId, 1) = "#" Then
GrpId = Right(GrpId, Len(GrpId) -1)
End If
Select Case True
Case Not BtnObj.Exist
ReportStepResult Test_Step_Id, "Failed", BtnObj.ToString & " doesn't exist"
Set_Radio_Group_Button=False
Case BtnObj.Object.isDisabled
ReportStepResult Test_Step_Id, "Failed", BtnObj.ToString & " is disabled"
Set_Radio_Group_Button=False
Case BtnObj.GetROProperty("visible") <> True
ReportStepResult Test_Step_Id, "Failed", BtnObj.ToString & " is not visible"
Set_Radio_Group_Button=False
Case Else
BtnObj.Select "#" & GrpId
Set_Radio_Group_Button = True
End Select
End Function
'########################################################################################################################################################################
'#Function Description: Verify the combo exists and select based on Item no
'#Input Parameters: (e.g. Browser("cabutars Wealth Online").Page("Make a payment/transfer").WebList("PaymentDate"),"#3")
'#Return Values: True/False
'#######################################################################################################################################################################
Public Function Combo_Select_Item(ObjCombo,Exp_Item_No)
Combo_Text = ObjCombo.ToString
If ObjCombo.Exist Then
Prty = ObjCombo.GetROProperty("visible")
If Prty =True Then
If instr(Exp_Item_No,"#") > 0 Then
Item_No = Cint(Replace(Exp_Item_No,"#",""))
Else
Item_No = Cint(Exp_Item_No)
End If
Item_ = ObjCombo.GetItem(Item_No + 1)
ObjCombo.Select Item_
Combo_Select_Item = True
Else
ReportStepResult Test_Step_Id, "Failed", Combo_Text & " combo box is not visible"
Combo_Select_Item = False
End If
Else
ReportStepResult Test_Step_Id, "Failed", Combo_Text & " combo box does not exist on current page"
Combo_Select_Item = False
End If
End Function
'########################################################################################################################################################################
'#Function Description: The function is a generic fucntion is used to set value to checkbox
'#Input Parameters:: Check box Object, value to be verified
'#Return Values: True/Error message
'#Ex: Checkbox_Select(ObjCheckbox,"ON")
'#######################################################################################################################################################################
Public Function Checkbox_Select(ObjCheckbox, Value_)
Checkbox_Text = ObjCheckbox.ToString 'Capture Name of the Test Object
Select Case True
Case Not ObjCheckbox.Exist
ReportStepResult Test_Step_Id, "Failed", Checkbox_Text &" does not exist on current screen"
Checkbox_Select = False
Case ObjCheckbox.GetROProperty("visible") = False
ReportStepResult Test_Step_Id, "Failed", Checkbox_Text &" is not visible"
Checkbox_Select = False
Case ObjCheckbox.Object.isDisabled
ReportStepResult Test_Step_Id, "Failed", Checkbox_Text &" is disabled"
Checkbox_Select = False
Case Else
ObjCheckbox.Set Value_ 'Set Value to Check Box
Checkbox_Select = True
End Select
End Function
'#################################################################################################################################
'#Function Description: Get the number of Table Row Count
'#Input Parameters: Local Sheet Location and Field to be Verified
'#Return Values: True
'#################################################################################################################################
Public Function ScreenShotToQC(filename)
If Not (sCurrentRun Is Nothing) Then
filename = Replace(filename,"C:\","H:\")
Browser("micclass:=Browser", "index:=0").CaptureBitmap filename,True
Set objCurrentRun = sCurrentRun.Attachments
Set ObjAttch = objCurrentRun.AddItem(Null)
ObjAttch.FileName = filename
ObjAttch.Type = 1
ObjAttch.Post
ObjAttch.Refresh
Set fso=CreateObject("Scripting.FileSystemObject")
fso.DeleteFile(filename)
Set fso = Nothing
End If
End Function
'#################################################################################################################################
'Public Function ReportStepResult(StepNo, Status, Actual)
'
'Description: This reports the results in QC, populating the "actual" and "expected" fields
'
'Parameters: StepNo - The step number to report
' Status - Passed / Failed
' Actual - The description to be populated in the actual field
'
'Return: N/A
'#################################################################################################################################
Public Function ReportStepResult(StepNo, Status, Actual)
If sResultsSheet Is Nothing Then
Select Case UCase(Left(Status, 4))
Case "PASS"
Reporter.ReportEvent micPass, "Step " & StepNo, Actual
Case "FAIL"
Reporter.ReportEvent micFail, "Step " & StepNo, Actual
End Select
Exit Function
End If
ReportRow = sResultsSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row + 1
If sLastIterationNo <> sIterationCount Then
sLastIterationNo = sIterationCount
sResultsSheet.Cells(ReportRow, sIterationCol) = sIterationCount
End If
If sLastStepNo <> StepNo Then
sLastStepNo = StepNo
sResultsSheet.Cells(ReportRow, sTestStepCol) = StepNo
End If
sResultsSheet.Cells(ReportRow, sResultCol) = UCase(Status)
Select Case UCase(Left(Status, 4))
Case "PASS"
sResultsSheet.Cells(ReportRow, sResultCol).Font.ColorIndex = 10 'green
Case "FAIL"
sResultsSheet.Cells(ReportRow, sResultCol).Font.ColorIndex = 3 'red
End Select
sResultsSheet.Cells(ReportRow, sResultDescCol) = Actual
End Function
'#################################################################################################################################
'Public Function DayofTheWeek(offset)
'
'Description: This returns the name of the day representing today
'
'Parameters: offset - number of days after today
'
'Return: String
'
'#################################################################################################################################
Public Function DayofTheWeek(offset)
TodaysDate = WeekDay(Now + offset)
Select Case TodaysDate
Case 1
DayofTheWeek = "Sunday"
Case 2
DayofTheWeek = "Monday"
Case 3
DayofTheWeek = "Tuesday"
Case 4
DayofTheWeek = "Wednesday"
Case 5
DayofTheWeek = "Thursday"
Case 6
DayofTheWeek = "Friday"
Case 7
DayofTheWeek = "Saturday"
End Select
End Function
'#################################################################################################################################
'Public Function DateFormatYYYYMMDD(offset)
'
'Description: This returns todays date in the format YYYYMMDD
'
'Parameters: offset - number of days after today
'
'Return: String
'
'#################################################################################################################################
Public Function DateFormatYYYYMMDD(offset)
TheYear = Year(Now + offset)
TheMonth = Month(Now + offset)
If Len(TheMonth) = 1 Then
TheMonth = "0" & TheMonth
End If
TheDay = Day(Now + offset)
If Len(TheDay) = 1 Then
TheDay = "0" & TheDay
End If
DateFormatYYYYMMDD = TheYear & TheMonth & TheDay
End Function
'#################################################################################################################################
'Public Function DateFormatYYYYMMDD(offset)
'
'Description: This returns todays date in the format YYYYMMDD
'
'Parameters: offset - number of days after today
'
'Return: String
'
'#################################################################################################################################
Public Function DateFormatQQYYYY(Offset)
TheYear = Year(Now) + (Offset \ 4)
MonthAdjust = Offset Mod 4
Select Case Month(Now)
Case 1,2,3
QQ = 1 + MonthAdjust
Case 4,5,6
QQ = 2 + MonthAdjust
Case 7,8,9
QQ = 3 + MonthAdjust
Case 10,11,12
QQ = 4 + MonthAdjust
End Select
TheYear = TheYear + (QQ \ 4)
QQ = QQ Mod 4
If QQ = 0 Then
QQ = 4
If Offset <> 0 Then
TheYear = TheYear - 1
End If
ElseIf QQ < 0 Then
QQ = QQ + 4
TheYear = TheYear - 1
End If
DateFormatQQYYYY = "Q" & QQ & " " & TheYear
End Function
'#################################################################################################################################
'Public Function DateFormatYYMMDDhhmmss(offset)
'
'Description: This returns todays date in the format YYMMDDhhmmss
'
'Parameters: offset - number of days after today
'
'Return: String
'
'#################################################################################################################################
Public Function DateFormatYYMMDDhhmmss(offset)
TheYear = Right(Year(Now + offset), 2)
TheMonth = Month(Now + offset)
If Len(TheMonth) = 1 Then
TheMonth = "0" & TheMonth
End If
TheDay = Day(Now + offset)
If Len(TheDay) = 1 Then
TheDay = "0" & TheDay
End If
TheHour = Hour(Now + offset)
If Len(TheHour) = 1 Then
TheHour = "0" & TheHour
End If
TheMinute = Minute(Now + offset)
If Len(TheMinute) = 1 Then
TheMinute = "0" & TheMinute
End If
TheSecond = Second(Now + offset)
If Len(TheSecond) = 1 Then
TheSecond = "0" & TheSecond
End If
DateFormatYYMMDDhhmmss = TheYear & TheMonth & TheDay & TheHour & TheMinute & TheSecond
End Function
'#################################################################################################################################
'Public Function DateFormatYYMMDDhhmmss(offset)
'
'Description: This returns todays date in the format YYMMDDhhmmss
'
'Parameters: offset - number of days after today
'
'Return: String
'
'#################################################################################################################################
Public Function TimeFormathhmm(offset)
TheHour = Hour(Now + offset)
If Len(TheHour) = 1 Then
TheHour = "0" & TheHour
End If
TheMinute = Minute(Now + offset)
If Len(TheMinute) = 1 Then
TheMinute = "0" & TheMinute
End If
TimeFormathhmm = TheHour &":" &TheMinute
End Function
'#################################################################################################################################
'Public Function DateFormatDD_MMM_YYYY(offset)
'
'Description: This returns todays date in the format DD_MMM_YYYY
'
'Parameters: offset - number of days after today
'
'Return: String
'
'#################################################################################################################################
Public Function DateFormatDD_MMM_YYYY(offset)
TheYear = Year(Now + offset)
TheMonth = MonthName(Month(Now + offset), True)
TheDay = Day(Now + offset)
If Len(TheDay) = 1 Then
TheDay = "0" & TheDay
End If
DateFormatDD_MMM_YYYY = TheDay & " " & TheMonth & " " & TheYear
End Function
'#################################################################################################################################
'Public Function DateFormatDDMMYY(offset)
'
'Description: This returns todays date in the format DD/MM/YY
'
'Parameters: offset - number of days after today
'
'Return: String
'
'#################################################################################################################################
Public Function DateFormatDDMMYY(offset)
TheYear = Right(Year(Now + offset), 2)
TheMonth = Month(Now + offset)
If Len(TheMonth) = 1 Then
TheMonth = "0" & TheMonth
End If
TheDay = Day(Now + offset)
If Len(TheDay) = 1 Then
TheDay = "0" & TheDay
End If
DateFormatDDMMYY = TheDay & "/" & TheMonth & "/" & TheYear
End Function
'#################################################################################################################################
'Public Function DateFormatDDMMYYYY(offset)
'
'Description: This returns todays date in the format DD/MM/YYYY
'
'Parameters: offset - number of days after today
'
'Return: String
'
'#################################################################################################################################
Public Function DateFormatDDMMYYYY(offset)
TheYear = Year(Now + offset)
TheMonth = Month(Now + offset)
If Len(TheMonth) = 1 Then
TheMonth = "0" & TheMonth
End If
TheDay = Day(Now + offset)
If Len(TheDay) = 1 Then
TheDay = "0" & TheDay
End If
DateFormatDDMMYYYY = TheDay & "/" & TheMonth & "/" & TheYear
End Function
'#################################################################################################################################
'Public Function ConvertDateFormatDDmonYYYY(dateToBeConverted)
'
'Description: This returns a date in the format DD/MM/YYYY
'
'Parameters: dateToBeConverted
'
'Return: String in format dd/mm/yyyy
'
'#################################################################################################################################
Public Function ConvertDateFormatDDmonYYYY(dateToBeConverted)
' Convert payment date from dd mmm yyyy to dd/mm/yyyy
DateArray = Split(dateToBeConverted)
If UBound(DateArray ) <> 2 Then
Reporter.ReportEvent micFail, "ConvertDateFormatDDmonYYYY", "Invalid parameter: " & dateToBeConverted
ExitTest
End If
TheDay = DateArray(0)
TheYear = DateArray(2)
sMonth = DateArray(1)
Select Case sMonth
Case "Jan"
TheMonth = "01"
Case "Feb"
TheMonth = "02"
Case "Mar"
TheMonth = "03"
Case "Apr"
TheMonth = "04"
Case "May"
TheMonth = "05"
Case "Jun"
TheMonth = "06"
Case "Jul"
TheMonth = "07"
Case "Aug"
TheMonth = "08"
Case "Sep"
TheMonth = "09"
Case "Oct"
TheMonth = "10"
Case "Nov"
TheMonth = "11"
Case "Dec"
TheMonth = "12"
End Select
ConvertDateFormatDDmonYYYY = TheDay & "/" & TheMonth & "/" & TheYear
End Function
'#################################################################################################################################
'Public Function DDMMYYYYToDDmonYYYY(dateToBeConverted)
'
'Description: This returns a date in the format DD/MM/YYYY into dd mon yyyy
'
'Parameters: dateToBeConverted
'
'Return: String in format dd/mm/yyyy
'
'#################################################################################################################################
Public Function DDMMYYYYToDDmonYYYY(dateToBeConverted)
DateArray = Split(dateToBeConverted, "/")
If UBound(DateArray ) <> 2 Then
Reporter.ReportEvent micFail, "DDMMYYYYToDDmonYYYY", "Invalid parameter: " & dateToBeConverted
ExitTest
End If
TheDay = DateArray(0)
TheYear = DateArray(2)
sMonth = DateArray(1)
Select Case sMonth
Case "01"
TheMonth = "Jan"
Case "02"
TheMonth = "Feb"
Case "03"
TheMonth = "Mar"
Case "04"
TheMonth = "Apr"
Case "05"
TheMonth = "May"
Case "06"
TheMonth = "Jun"
Case "07"
TheMonth = "Jul"
Case "08"
TheMonth = "Aug"
Case "09"
TheMonth = "Sep"
Case "10"
TheMonth = "Oct"
Case "11"
TheMonth = "Nov"
Case "12"
TheMonth = "Dec"
End Select
DDMMYYYYToDDmonYYYY = TheDay & " " & TheMonth & " " & TheYear
End Function
'#################################################################################################################################
'Public Function ConvertDateFormatDDmmmYYYY(dateToBeConverted)
'
'Description: This returns a date in the format dd mmm yyyyy
'
'Parameters: dateToBeConverted dd/mm/yyyy format
'
'Return: String in format dd mmm yyyyy
'
'#################################################################################################################################
Public Function ConvertDateFormatDDmmmYYYY(dateToBeConverted)
' Convert payment date from dd mmm yyyy to dd/mm/yyyy
DateArray = Split(dateToBeConverted, "/")
If UBound(DateArray ) <> 2 Then
Reporter.ReportEvent micFail, "ConvertDateFormatDDmmmYYYY", "Invalid parameter: " & dateToBeConverted
ExitTest
End If
TheDay = DateArray(0)
If Len(TheDay) = 1 Then
TheDay = "0" & TheDay
End If
TheYear = DateArray(2)
sMonth = DateArray(1)
Select Case sMonth
Case "1"
TheMonth = "Jan"
Case "01"
TheMonth = "Jan"
Case "2"
TheMonth = "Feb"
Case "02"
TheMonth = "Feb"
Case "02"
TheMonth = "Feb"
Case "3"
TheMonth = "Mar"
Case "03"
TheMonth = "Mar"
Case "4"
TheMonth = "Apr"
Case "04"
TheMonth = "Apr"
Case "04"
TheMonth = "Apr"
Case "5"
TheMonth = "May"
Case "05"
TheMonth = "May"
Case "6"
TheMonth = "Jun"
Case "06"
TheMonth = "Jun"
Case "7"
TheMonth = "Jul"
Case "07"
TheMonth = "Jul"
Case "8"
TheMonth = "Aug"
Case "08"
TheMonth = "Aug"
Case "9"
TheMonth = "Sep"
Case "09"
TheMonth = "Sep"
Case "10"
TheMonth = "Oct"
Case "11"
TheMonth = "Nov"
Case "12"
TheMonth = "Dec"
End Select
ConvertDateFormatDDmmmYYYY = TheDay & " " & TheMonth & " " & TheYear
End Function
'#################################################################################################################################
'Public Function ReformatDateDDMMYYYY(inputdate)
'
'Description: Reformat the date after the dateadd to bring it back to format DD/MM/YYYY
'
'Parameters: DD/MM/YYYY
'
'Return: Reformatted date in DD/MM/YYYY
'
'#################################################################################################################################
Public Function ReformatDateDDMMYYYY(inputdate)
TheYear = Year(inputdate)
TheMonth = Month(inputdate)
TheDay = Day(inputdate)
If Len(TheMonth) = 1 Then
TheMonth = "0" & TheMonth
End If
If Len(TheDay) = 1 Then
TheDay = "0" & TheDay
End If
ReformatDateDDMMYYYY = TheDay & "/" & TheMonth & "/" & TheYear
End Function
'#################################################################################################################################
'Public Function UpLoadAttachmentToQC(FilePath)
'
'Description: This copies a specified file to the attachments tab in QC.
' NOTE - the script you are calling this from MUST be stored in QC
'
'Parameters: offset - number of days after today
'
'Return: String
'
'#################################################################################################################################
Public Function UpLoadAttachmentToQC(FilePath)
Set ObjCurrentTest = sCurrentTest.Attachments
Set ObjAttch = ObjCurrentTest.AddItem(Null)
ObjAttch.FileName = FilePath
ObjAttch.Type = 1
ObjAttch.Post
ObjAttch.Refresh
End Function
'#################################################################################################################################
'Public Function RandStr(vLength)
'
'Description: return a random string
'
'Parameters: vLength - the length of string
'
'Return: String
'
'#################################################################################################################################
Public Function RandStr(vLength)
vString = "abcdefghijklmnopqrstuvwxyz"
If vLength > Len(vString) Then
vLen = Len(vString)
Else
vLen = Cint(vLength)
End If
Do Until Len(vTemp) = vLen
Randomize ' Initialize random-number generator.
vNum = Int((Len(vString) * Rnd) + 1)
If Not Instr(vTemp, Mid(vString,vNum,1)) Then
vTemp = vTemp & Mid(vString,vNum,1)
End If
Loop
RandStr = vTemp
End Function
'#################################################################################################################################
'Public Function RandInt(vLength)
'
'Description: return a random number (string)
'
'Parameters: vLength - the length of string
'
'Return: String
'
'#################################################################################################################################
Public Function RandInt(vLength)
vString = "0123456789"
If vLength > Len(vString) Then
vLen = Len(vString)
Else
vLen = Cint(vLength)
End If
Do Until Len(vTemp) = vLen
Randomize ' Initialize random-number generator.
vNum = Int((Len(vString) * Rnd) + 1)
If Not Instr(vTemp, Mid(vString,vNum,1)) Then
vTemp = vTemp & Mid(vString,vNum,1)
End If
Loop
RandInt = vTemp
End Function
'#################################################################################################################################
'Public Function RemoveExtraSpaces(Text)
'
'Description: return a string with any double-spaces between words removed
'
'Parameters: Text - the string
'
'Return: String
'
'#################################################################################################################################
Public Function RemoveExtraSpaces(Text)
If (IsNull(Text)) Or (Text = "") Then
RemoveExtraSpaces = ""
Exit Function
End If
tmpArray = Split(Text)
newstring = tmpArray(0)
For i = 1 to UBound(tmpArray)
If tmpArray(i) <> "" Then
newstring = newstring & " " & tmpArray(i)
End If
Next
RemoveExtraSpaces = newstring
End Function
'#################################################################################################################################
'Public Function InitDB(DBName, objConn, objRecordset)
'
'Description: Initialises DB Connection
'
'Parameters: DBName - the database to connect to
' objConn - the connection object
' objRecordset - the record set object
'
'Return: objConn, objRecordset
'
'#################################################################################################################################
Public Function InitDB(DBName, objConn, objRecordset)
Set objConn = CreateObject("ADODB.Connection")
objConn.CursorLocation = 3
Set objRecordset = CreateObject("ADODB.recordset")
objRecordset.CursorType = 3
On Error Resume Next
objConn.Open(DBName)
On Error Goto 0
If objConn.State = 0 Then
ReportStepResult Test_Step_Id, "Failed", "InitDB: Unable to establish connection to " & DBName
ExitTest
InitDB = False
End If
InitDB = True
End Function
'#################################################################################################################################
'Public Function GetEnv()
'
'Description: Gets the environment being tested, either ftom QC or the env vars
'
'Parameters: N/A
'
'Return: the environment being tested
'
'#################################################################################################################################
Public Function GetEnv()
If sCurrentRun Is Nothing Then
GetEnv = Environment("Env")
Else
QCUtil.CurrentTestSet.Refresh
GetEnv = UCase(QCUtil.CurrentTestSet.Field("CY_USER_06"))
'only use field value if it's valid
If (Trim(GetEnv) <> "ST1") And (Trim(GetEnv) <> "ST2") And (Trim(GetEnv) <> "UAT") Then
GetEnv = Environment("Env")
End If
End If
End Function
'#################################################################################################################################
'Public Function CalcSecsFromTime(Timestamp)
'
'Description: calculates the number of seconds from a given timestamp
'
'Parameters: Timestamp, format HH:MM:SS
'
'Return: the value in seconds
'
'#################################################################################################################################
Public Function CalcSecsFromTime(Timestamp)
tmpArray = Split(Timestamp, ":")
If UBound(tmpArray) <> 2 Then
Reporter.ReportEvent micFail, "CalcSecsFromTime", "Invalid parameter: " & Timestamp
ExitTest
End If
hh = tmpArray(0) * 3600
mm = tmpArray(1) * 60
CalcSecsFromTime = hh + mm + tmpArray(2)
End Function
'#################################################################################################################################
'Public Function MonetaryAmount(Amount)
'
'Description: ensures a given value is pounds and pence
'
'Parameters: Amount
'
'Return: monetary amount
'
'#################################################################################################################################
Public Function MonetaryAmount(Amount)
If Instr(Amount, ".") Then
MonetaryAmount = Amount
Else
MonetaryAmount = Amount & ".00"
End If
End Function
'#################################################################################################################################
'Public Function RunJarFile
'
'Description: RunJarFile
'
'Parameters: jarLocation
'
'Return: N/A
'
'#################################################################################################################################
Public Function RunJarFile(jarLocation)
Dim oShell
Set oShell = CreateObject ("Wscript.shell")
jarFile = "eDocsTestStub.jar"
oShell.run jarLocation &"\" &jarFile
ReportStepResult Test_Step_Id, "Passed", "Launched jar file: '" & jarFile & "' from: '" & jarLocation & "'"
Set oShell = Nothing
End Function
'#################################################################################################################################
'GetFolderAttachmentPath(TDAttachmentName, TDFolderPath)
'
'Description: Extracts a named file from QC to the temp QTP folder
'
'Parameters: TDAttachmentName, TDFolderPath
'
'Return: the path to the downloaded file
'
'#################################################################################################################################
Public Function GetFolderAttachmentPath(TDAttachmentName, TDFolderPath)
Set otaTreeManager = QCUtil.TDConnection.TreeManager
Set otaSysTreeNode = otaTreeManager.NodeByPath(TDFolderPath)
Set otaAttachmentFactory = otaSysTreeNode.Attachments
Set otaAttachmentFilter = otaAttachmentFactory.Filter
intNdId = otaSysTreeNode.NodeID
otaAttachmentFilter.Filter("CR_REFERENCE") = "'ALL_LISTS_" & intNdId & "_" & TDAttachmentName & "'"
Set otaAttachmentList = otaAttachmentFilter.NewList
If otaAttachmentList.Count > 0 Then
Set otaAttachment = otaAttachmentList.Item(1)
otaAttachment.Load True, ""
strPath = otaAttachment.FileName
Else
Reporter.ReportEvent micFail,"Failure in library function 'GetFolderAttachmentPath'", _
"Failed to find attachment '" & TDAttachmentName & "' in folder '" & TDFolderPath & "'."
End If
GetFolderAttachmentPath = strPath
Set otaAttachmentFactory = Nothing
Set otaAttachment = Nothing
Set otaAttachmentList = Nothing
Set otaAttachmentFilter = Nothing
Set otaTreeManager = Nothing
Set otaSysTreeNode = Nothing
End Function
'########################################################################################################################################################################
'#Function Description: The function terminates all the active caffeine processes and relaunches the app, for the duration indicated by the parameter
'#Input Parameters: Duration
'#Return Values: N/A
'#######################################################################################################################################################################
Public Function Launch_Caffeine(Duration)
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'caffeine.exe'") 'Capture the active windows Excel Processes
If colProcesses.Count > 0 Then
Set oShell = CreateObject("WScript.shell")
cmd = "c:\caffeine.exe -appexit"
On Error Resume Next
For Each objProcess in colProcesses 'Terminate Caffeine Processes one by one
oShell.Run(cmd)
Next
If err.number <> 0 Then
Reporter.ReportEvent micPass, "Caffeine", "Caffeine was already running, but not from the root c: drive, so unable to terminate it"
End If
On Error GoTo 0
Set oShell = Nothing
End If
On Error Resume Next
Set oShell = CreateObject("WScript.shell")
cmd = "c:\caffeine.exe -exitafter:" & Duration
oShell.Run(cmd)
If err.number <> 0 Then 'caffeine app not found; install it from QC
DownloadFileFromQC "Subject\Automated Testing - Shared Files", "caffeine.exe", "c:\caffeine.exe"
oShell.Run(cmd)
End If
On Error GoTo 0
Set objWMIService = Nothing
Set colProcesses = Nothing
Set oShell = Nothing
End Function
'#################################################################################################################################
'Generate_NI_No()
'
'Description: Create a random, valid national Insurance number
'
'Parameters: None
'
'Return: NI no.
'
'#################################################################################################################################
Public Function Generate_NI_No()
tmp = RandomNumber(0,3)
tmpArray = Array("A", "B", "C", "D")
Generate_NI_No = UCase(RandStr(2)) & RandInt(6) & tmpArray(tmp)
End Function
'########################################################################################################################################################################
'#Function Description:
'#Input Parameters:
'#Return Values:
'#######################################################################################################################################################################
Public Function UploadFileToResources(FileName, ResourceFolder)
Set RootResourceFolder = QCUtil.QCConnection.QCResourceFolderFactory.Root
Set RootResourceFolderFactory= RootResourceFolder.QCResourceFolderFactory
Set theFilter = RootResourceFolderFactory.Filter
theFilter("RFO_NAME") = "'" & ResourceFolder & "'"
NumAutoFolders = theFilter.NewList.count
If NumAutoFolders = 0 Then 'create the folder
Set NewFolder = RootResourceFolderFactory.AddItem(Null)
NewFolder.Name = CStr(ResourceFolder)
NewFolder.Post
MsgBox "'" & ResourceFolder & "' folder did not exist and has now been created. Please re-run this script"
wscript.quit
End If
tmpArray = Split(FileName, "\")
FullPath = ""
For i = 0 to UBound(tmpArray) - 1
FullPath = FullPath & tmpArray(i) & "\"
Next
LongFileName = tmpArray(UBound(tmpArray))
tmpArray = Split(LongFileName, ".")
ShortFileName = tmpArray(0)
FileExtension = tmpArray(UBound(tmpArray))
Set AutoFolder = theFilter.NewList(1)
Set resourceFactory = AutoFolder.QCResourceFactory
Set theFilter = resourceFactory.Filter
theFilter("RSC_NAME") = "'" & CStr(ShortFileName) & "'"
Set tmpResource = theFilter.NewList
For Each Resource in tmpResource
resourceFactory.RemoveItem Resource
Next
Set theResource = resourceFactory.AddItem(CStr(ShortFileName))
theResource.FileName = LongFileName
Select Case LCase(FileExtension)
Case "tsr"
theResource.ResourceType ="Shared object repository"
Case "xls"
theResource.ResourceType ="Data table"
Case "qfl", "vbs"
theResource.ResourceType ="Function library"
End Select
theResource.Post
Set resourceStorage = theResource
resourceStorage.UploadResource CStr(FullPath), True
End Function
'########################################################################################################################################################################
'#Function Description:
'#Input Parameters:
'#Return Values:
'#######################################################################################################################################################################
Public Function DownloadFileFromResources(ResourceName, ResourceFolder, Destination)
Set RootResourceFolder = QCUtil.QCConnection.QCResourceFolderFactory.Root
Set RootResourceFolderFactory= RootResourceFolder.QCResourceFolderFactory
Set theFilter = RootResourceFolderFactory.Filter
theFilter("RFO_NAME") = "'" & ResourceFolder & "'"
NumAutoFolders = theFilter.NewList.count
If NumAutoFolders = 0 Then
MsgBox "ERROR - '" & ResourceFolder & "' folder does not exist. "
ExitTest
End If
Set AutoFolder = theFilter.NewList(1)
Set resourceFactory = AutoFolder.QCResourceFactory
Set theFilter = resourceFactory.Filter
theFilter("RSC_NAME") = "'" & CStr(ResourceName) & "'"
Set tmpResource = theFilter.NewList
If tmpResource.Count = 0 Then
MsgBox "ERROR - '" & ResourceName & "' resource not found in '" & ResourceFolder & "'"
ExiTest
End If
Set resourceStorage = tmpResource(1)
resourceStorage.DownloadResource CStr(Destination), True
End Function
'#######################################
Public Function Generate_Random_Name()
vowels = Array("a", "e", "i", "o", "u")
hh =hour(now)
mm = minute(now)
ss = second(now)
Generate_Random_Name = UCase(RandStr(1)) & vowels(RandomNumber(0,4)) & Randstr(2) & vowels(RandomNumber(0,4)) & Randstr(1) & hh & mm & ss
End Function
'#######################################
Public Function GenerateTestData()
On Error Resume Next
tmpstr = "Set objExcel = GetObject( ,""Excel.Application"")"
Execute tmpstr
If err.number <> 0 Then ' excel not running; cannot proceed as this test is run from Excel
MsgBox "This test must be run from Excel; closing"
ExitTest
ElseIf TestArgs("XLSheet") <> "" Then
Set objWorkBook = GetObject(TestArgs("XLSheet")) 'will open it if not already running
Set sResultsSheet = objWorkBook.Sheets(TestArgs("ResultsSheet"))
Else'included hard-coded sheet for debugging
Set objWorkBook = GetObject("F:\Condeco\Condeco Test Automation.xlsm")
Set sResultsSheet = objWorkBook.Sheets("testresults")
End If
objExcel.DisplayAlerts = False
Set objSheet = objWorkBook.ActiveSheet
With objSheet
If .AutoFilterMode Then
If .FilterMode Then
.ShowAllData
End If
Else
If .FilterMode Then
.ShowAllData
End If
End If
End With
On Error GoTo 0
'dynamically declare all public variables from spreadsheet
Set c = objSheet.Columns(1).Find(TestName,,,1) 'just find instances where it matches the whole cell
If c is nothing Then
ReportStepResult Test_Step_Id, "Failed", "No data found for '" & TestName & "' in sheet '" & Environment("TestDataSheet") & "'"
ExitTest
End If
PubVarRow = c.Row
LastCol = objSheet.Cells(PubVarRow, objSheet.Columns.count).end(xlToLeft).Column
Set NextPubVar = objSheet.Columns(1).Find("*",c,,1) 'finds the next non-blank cell in column 1
If (NextPubVar Is Nothing) or (NextPubVar.Row <= c.Row) Then
LastRow = objSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row 'this is the last set of data in the sheet
else
LastRow = NextPubVar.Row - 1 'just get the rows before the next set of data
End If
'build a custom dictionary of data to be used
For i = PubVarRow + 1 To LastRow
If UCase(Left(objSheet.Cells(i,2), 1)) = "Y" Then 'data is to be included
sNumIterations = sNumIterations + 1
For j = 3 To LastCol
key = objSheet.Cells(PubVarRow, j)
CustDict.Item(key) = CustDict.Item(key) & objSheet.Cells(i,j) & Chr(10)
Next
End If
Next
pubItems = CustDict.Items
'Clean Items - remove trailing separator
For i = 0 To UBound(pubItems)
pubItems(i) = Left(pubItems(i), len(pubItems(i)) - 1)
Next
'add test name to test results
ReportRow = sResultsSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row + 1
sResultsSheet.Cells(ReportRow, sTestNameCol) = TestName
sResultsSheet.Cells(ReportRow, sTestNameCol).Font.Bold = True
End Function
'#######################################
Sub DeclareIterationData(iteration)
pubKeys = CustDict.Keys
pubItems = CustDict.Items
For i = 0 To UBound(pubKeys)
tmpArr = Split(pubItems(i), Chr(10))
If IsNumeric(tmpArr(iteration - 1)) Then
tmpstr = pubKeys(i) & " = " & tmpArr(iteration - 1)
Else
tmpstr = pubKeys(i) & " = """ & tmpArr(iteration - 1) & """"
End If
Execute tmpstr
Next
End Sub
'########################################################################################################################################################################
'#Function Description: Double-Click on the specific link for the object
'#Input Parameters: (e.g. Browser("cabutars Wealth Online").Page("View/change payments").Link("Confirm")
'# Browser("cabutars Wealth Online").Page("Make a payment/transfer").WebButton("Confirm"))
'#Return Values: True/False
'#######################################################################################################################################################################
Public Function Object_DoubleClick(Obj)
Object_Text = Obj.ToString
Select Case True
Case Not Obj.Exist
ReportStepResult Test_Step_Id, "Failed", Object_Text & " does not exist on current page"
Object_DoubleClick = False
Case Obj.GetROProperty("visible") = False
ReportStepResult Test_Step_Id, "Failed", Object_Text & " is not visible"
Object_DoubleClick = False
Case Obj.Object.isDisabled
ReportStepResult Test_Step_Id, "Failed", Object_Text & " is disabled"
Object_DoubleClick = False
Case Else
Obj.Click
Obj.FireEvent "ondblclick"
Object_DoubleClick = True
End Select
End Function
'########################################################################################################################################################################
'#Function Description: The function sets the given radio button object
'#Input Parameters:Radio button object (e.g. Set Obj = Browser("cabutars Wealth Online").Page("Make a payment/transfer").WebRadioGroup("PaymentTransferType"))
'#Return Values: True/Error Message
'#######################################################################################################################################################################
Public Function Set_Radio_Group_Button(BtnObj,GrpId)
If Left(GrpId, 1) = "#" Then
GrpId = Right(GrpId, Len(GrpId) -1)
End If
Select Case True
Case Not BtnObj.Exist
ReportStepResult Test_Step_Id, "Failed", BtnObj.ToString & " doesn't exist"
Set_Radio_Group_Button=False
Case BtnObj.Object.isDisabled
ReportStepResult Test_Step_Id, "Failed", BtnObj.ToString & " is disabled"
Set_Radio_Group_Button=False
Case BtnObj.GetROProperty("visible") <> True
ReportStepResult Test_Step_Id, "Failed", BtnObj.ToString & " is not visible"
Set_Radio_Group_Button=False
Case Else
BtnObj.Select "#" & GrpId
Set_Radio_Group_Button = True
End Select
End Function
'########################################################################################################################################################################
'#Function Description: Verify the combo exists and select based on Item no
'#Input Parameters: (e.g. Browser("cabutars Wealth Online").Page("Make a payment/transfer").WebList("PaymentDate"),"#3")
'#Return Values: True/False
'#######################################################################################################################################################################
Public Function Combo_Select_Item(ObjCombo,Exp_Item_No)
Combo_Text = ObjCombo.ToString
If ObjCombo.Exist Then
Prty = ObjCombo.GetROProperty("visible")
If Prty =True Then
If instr(Exp_Item_No,"#") > 0 Then
Item_No = Cint(Replace(Exp_Item_No,"#",""))
Else
Item_No = Cint(Exp_Item_No)
End If
Item_ = ObjCombo.GetItem(Item_No + 1)
ObjCombo.Select Item_
Combo_Select_Item = True
Else
ReportStepResult Test_Step_Id, "Failed", Combo_Text & " combo box is not visible"
Combo_Select_Item = False
End If
Else
ReportStepResult Test_Step_Id, "Failed", Combo_Text & " combo box does not exist on current page"
Combo_Select_Item = False
End If
End Function
'########################################################################################################################################################################
'#Function Description: The function is a generic fucntion is used to set value to checkbox
'#Input Parameters:: Check box Object, value to be verified
'#Return Values: True/Error message
'#Ex: Checkbox_Select(ObjCheckbox,"ON")
'#######################################################################################################################################################################
Public Function Checkbox_Select(ObjCheckbox, Value_)
Checkbox_Text = ObjCheckbox.ToString 'Capture Name of the Test Object
Select Case True
Case Not ObjCheckbox.Exist
ReportStepResult Test_Step_Id, "Failed", Checkbox_Text &" does not exist on current screen"
Checkbox_Select = False
Case ObjCheckbox.GetROProperty("visible") = False
ReportStepResult Test_Step_Id, "Failed", Checkbox_Text &" is not visible"
Checkbox_Select = False
Case ObjCheckbox.Object.isDisabled
ReportStepResult Test_Step_Id, "Failed", Checkbox_Text &" is disabled"
Checkbox_Select = False
Case Else
ObjCheckbox.Set Value_ 'Set Value to Check Box
Checkbox_Select = True
End Select
End Function
'#################################################################################################################################
'#Function Description: Get the number of Table Row Count
'#Input Parameters: Local Sheet Location and Field to be Verified
'#Return Values: True
'#################################################################################################################################
Public Function ScreenShotToQC(filename)
If Not (sCurrentRun Is Nothing) Then
filename = Replace(filename,"C:\","H:\")
Browser("micclass:=Browser", "index:=0").CaptureBitmap filename,True
Set objCurrentRun = sCurrentRun.Attachments
Set ObjAttch = objCurrentRun.AddItem(Null)
ObjAttch.FileName = filename
ObjAttch.Type = 1
ObjAttch.Post
ObjAttch.Refresh
Set fso=CreateObject("Scripting.FileSystemObject")
fso.DeleteFile(filename)
Set fso = Nothing
End If
End Function
'#################################################################################################################################
'Public Function ReportStepResult(StepNo, Status, Actual)
'
'Description: This reports the results in QC, populating the "actual" and "expected" fields
'
'Parameters: StepNo - The step number to report
' Status - Passed / Failed
' Actual - The description to be populated in the actual field
'
'Return: N/A
'#################################################################################################################################
Public Function ReportStepResult(StepNo, Status, Actual)
If sResultsSheet Is Nothing Then
Select Case UCase(Left(Status, 4))
Case "PASS"
Reporter.ReportEvent micPass, "Step " & StepNo, Actual
Case "FAIL"
Reporter.ReportEvent micFail, "Step " & StepNo, Actual
End Select
Exit Function
End If
ReportRow = sResultsSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row + 1
If sLastIterationNo <> sIterationCount Then
sLastIterationNo = sIterationCount
sResultsSheet.Cells(ReportRow, sIterationCol) = sIterationCount
End If
If sLastStepNo <> StepNo Then
sLastStepNo = StepNo
sResultsSheet.Cells(ReportRow, sTestStepCol) = StepNo
End If
sResultsSheet.Cells(ReportRow, sResultCol) = UCase(Status)
Select Case UCase(Left(Status, 4))
Case "PASS"
sResultsSheet.Cells(ReportRow, sResultCol).Font.ColorIndex = 10 'green
Case "FAIL"
sResultsSheet.Cells(ReportRow, sResultCol).Font.ColorIndex = 3 'red
End Select
sResultsSheet.Cells(ReportRow, sResultDescCol) = Actual
End Function
'#################################################################################################################################
'Public Function DayofTheWeek(offset)
'
'Description: This returns the name of the day representing today
'
'Parameters: offset - number of days after today
'
'Return: String
'
'#################################################################################################################################
Public Function DayofTheWeek(offset)
TodaysDate = WeekDay(Now + offset)
Select Case TodaysDate
Case 1
DayofTheWeek = "Sunday"
Case 2
DayofTheWeek = "Monday"
Case 3
DayofTheWeek = "Tuesday"
Case 4
DayofTheWeek = "Wednesday"
Case 5
DayofTheWeek = "Thursday"
Case 6
DayofTheWeek = "Friday"
Case 7
DayofTheWeek = "Saturday"
End Select
End Function
'#################################################################################################################################
'Public Function DateFormatYYYYMMDD(offset)
'
'Description: This returns todays date in the format YYYYMMDD
'
'Parameters: offset - number of days after today
'
'Return: String
'
'#################################################################################################################################
Public Function DateFormatYYYYMMDD(offset)
TheYear = Year(Now + offset)
TheMonth = Month(Now + offset)
If Len(TheMonth) = 1 Then
TheMonth = "0" & TheMonth
End If
TheDay = Day(Now + offset)
If Len(TheDay) = 1 Then
TheDay = "0" & TheDay
End If
DateFormatYYYYMMDD = TheYear & TheMonth & TheDay
End Function
'#################################################################################################################################
'Public Function DateFormatYYYYMMDD(offset)
'
'Description: This returns todays date in the format YYYYMMDD
'
'Parameters: offset - number of days after today
'
'Return: String
'
'#################################################################################################################################
Public Function DateFormatQQYYYY(Offset)
TheYear = Year(Now) + (Offset \ 4)
MonthAdjust = Offset Mod 4
Select Case Month(Now)
Case 1,2,3
QQ = 1 + MonthAdjust
Case 4,5,6
QQ = 2 + MonthAdjust
Case 7,8,9
QQ = 3 + MonthAdjust
Case 10,11,12
QQ = 4 + MonthAdjust
End Select
TheYear = TheYear + (QQ \ 4)
QQ = QQ Mod 4
If QQ = 0 Then
QQ = 4
If Offset <> 0 Then
TheYear = TheYear - 1
End If
ElseIf QQ < 0 Then
QQ = QQ + 4
TheYear = TheYear - 1
End If
DateFormatQQYYYY = "Q" & QQ & " " & TheYear
End Function
'#################################################################################################################################
'Public Function DateFormatYYMMDDhhmmss(offset)
'
'Description: This returns todays date in the format YYMMDDhhmmss
'
'Parameters: offset - number of days after today
'
'Return: String
'
'#################################################################################################################################
Public Function DateFormatYYMMDDhhmmss(offset)
TheYear = Right(Year(Now + offset), 2)
TheMonth = Month(Now + offset)
If Len(TheMonth) = 1 Then
TheMonth = "0" & TheMonth
End If
TheDay = Day(Now + offset)
If Len(TheDay) = 1 Then
TheDay = "0" & TheDay
End If
TheHour = Hour(Now + offset)
If Len(TheHour) = 1 Then
TheHour = "0" & TheHour
End If
TheMinute = Minute(Now + offset)
If Len(TheMinute) = 1 Then
TheMinute = "0" & TheMinute
End If
TheSecond = Second(Now + offset)
If Len(TheSecond) = 1 Then
TheSecond = "0" & TheSecond
End If
DateFormatYYMMDDhhmmss = TheYear & TheMonth & TheDay & TheHour & TheMinute & TheSecond
End Function
'#################################################################################################################################
'Public Function DateFormatYYMMDDhhmmss(offset)
'
'Description: This returns todays date in the format YYMMDDhhmmss
'
'Parameters: offset - number of days after today
'
'Return: String
'
'#################################################################################################################################
Public Function TimeFormathhmm(offset)
TheHour = Hour(Now + offset)
If Len(TheHour) = 1 Then
TheHour = "0" & TheHour
End If
TheMinute = Minute(Now + offset)
If Len(TheMinute) = 1 Then
TheMinute = "0" & TheMinute
End If
TimeFormathhmm = TheHour &":" &TheMinute
End Function
'#################################################################################################################################
'Public Function DateFormatDD_MMM_YYYY(offset)
'
'Description: This returns todays date in the format DD_MMM_YYYY
'
'Parameters: offset - number of days after today
'
'Return: String
'
'#################################################################################################################################
Public Function DateFormatDD_MMM_YYYY(offset)
TheYear = Year(Now + offset)
TheMonth = MonthName(Month(Now + offset), True)
TheDay = Day(Now + offset)
If Len(TheDay) = 1 Then
TheDay = "0" & TheDay
End If
DateFormatDD_MMM_YYYY = TheDay & " " & TheMonth & " " & TheYear
End Function
'#################################################################################################################################
'Public Function DateFormatDDMMYY(offset)
'
'Description: This returns todays date in the format DD/MM/YY
'
'Parameters: offset - number of days after today
'
'Return: String
'
'#################################################################################################################################
Public Function DateFormatDDMMYY(offset)
TheYear = Right(Year(Now + offset), 2)
TheMonth = Month(Now + offset)
If Len(TheMonth) = 1 Then
TheMonth = "0" & TheMonth
End If
TheDay = Day(Now + offset)
If Len(TheDay) = 1 Then
TheDay = "0" & TheDay
End If
DateFormatDDMMYY = TheDay & "/" & TheMonth & "/" & TheYear
End Function
'#################################################################################################################################
'Public Function DateFormatDDMMYYYY(offset)
'
'Description: This returns todays date in the format DD/MM/YYYY
'
'Parameters: offset - number of days after today
'
'Return: String
'
'#################################################################################################################################
Public Function DateFormatDDMMYYYY(offset)
TheYear = Year(Now + offset)
TheMonth = Month(Now + offset)
If Len(TheMonth) = 1 Then
TheMonth = "0" & TheMonth
End If
TheDay = Day(Now + offset)
If Len(TheDay) = 1 Then
TheDay = "0" & TheDay
End If
DateFormatDDMMYYYY = TheDay & "/" & TheMonth & "/" & TheYear
End Function
'#################################################################################################################################
'Public Function ConvertDateFormatDDmonYYYY(dateToBeConverted)
'
'Description: This returns a date in the format DD/MM/YYYY
'
'Parameters: dateToBeConverted
'
'Return: String in format dd/mm/yyyy
'
'#################################################################################################################################
Public Function ConvertDateFormatDDmonYYYY(dateToBeConverted)
' Convert payment date from dd mmm yyyy to dd/mm/yyyy
DateArray = Split(dateToBeConverted)
If UBound(DateArray ) <> 2 Then
Reporter.ReportEvent micFail, "ConvertDateFormatDDmonYYYY", "Invalid parameter: " & dateToBeConverted
ExitTest
End If
TheDay = DateArray(0)
TheYear = DateArray(2)
sMonth = DateArray(1)
Select Case sMonth
Case "Jan"
TheMonth = "01"
Case "Feb"
TheMonth = "02"
Case "Mar"
TheMonth = "03"
Case "Apr"
TheMonth = "04"
Case "May"
TheMonth = "05"
Case "Jun"
TheMonth = "06"
Case "Jul"
TheMonth = "07"
Case "Aug"
TheMonth = "08"
Case "Sep"
TheMonth = "09"
Case "Oct"
TheMonth = "10"
Case "Nov"
TheMonth = "11"
Case "Dec"
TheMonth = "12"
End Select
ConvertDateFormatDDmonYYYY = TheDay & "/" & TheMonth & "/" & TheYear
End Function
'#################################################################################################################################
'Public Function DDMMYYYYToDDmonYYYY(dateToBeConverted)
'
'Description: This returns a date in the format DD/MM/YYYY into dd mon yyyy
'
'Parameters: dateToBeConverted
'
'Return: String in format dd/mm/yyyy
'
'#################################################################################################################################
Public Function DDMMYYYYToDDmonYYYY(dateToBeConverted)
DateArray = Split(dateToBeConverted, "/")
If UBound(DateArray ) <> 2 Then
Reporter.ReportEvent micFail, "DDMMYYYYToDDmonYYYY", "Invalid parameter: " & dateToBeConverted
ExitTest
End If
TheDay = DateArray(0)
TheYear = DateArray(2)
sMonth = DateArray(1)
Select Case sMonth
Case "01"
TheMonth = "Jan"
Case "02"
TheMonth = "Feb"
Case "03"
TheMonth = "Mar"
Case "04"
TheMonth = "Apr"
Case "05"
TheMonth = "May"
Case "06"
TheMonth = "Jun"
Case "07"
TheMonth = "Jul"
Case "08"
TheMonth = "Aug"
Case "09"
TheMonth = "Sep"
Case "10"
TheMonth = "Oct"
Case "11"
TheMonth = "Nov"
Case "12"
TheMonth = "Dec"
End Select
DDMMYYYYToDDmonYYYY = TheDay & " " & TheMonth & " " & TheYear
End Function
'#################################################################################################################################
'Public Function ConvertDateFormatDDmmmYYYY(dateToBeConverted)
'
'Description: This returns a date in the format dd mmm yyyyy
'
'Parameters: dateToBeConverted dd/mm/yyyy format
'
'Return: String in format dd mmm yyyyy
'
'#################################################################################################################################
Public Function ConvertDateFormatDDmmmYYYY(dateToBeConverted)
' Convert payment date from dd mmm yyyy to dd/mm/yyyy
DateArray = Split(dateToBeConverted, "/")
If UBound(DateArray ) <> 2 Then
Reporter.ReportEvent micFail, "ConvertDateFormatDDmmmYYYY", "Invalid parameter: " & dateToBeConverted
ExitTest
End If
TheDay = DateArray(0)
If Len(TheDay) = 1 Then
TheDay = "0" & TheDay
End If
TheYear = DateArray(2)
sMonth = DateArray(1)
Select Case sMonth
Case "1"
TheMonth = "Jan"
Case "01"
TheMonth = "Jan"
Case "2"
TheMonth = "Feb"
Case "02"
TheMonth = "Feb"
Case "02"
TheMonth = "Feb"
Case "3"
TheMonth = "Mar"
Case "03"
TheMonth = "Mar"
Case "4"
TheMonth = "Apr"
Case "04"
TheMonth = "Apr"
Case "04"
TheMonth = "Apr"
Case "5"
TheMonth = "May"
Case "05"
TheMonth = "May"
Case "6"
TheMonth = "Jun"
Case "06"
TheMonth = "Jun"
Case "7"
TheMonth = "Jul"
Case "07"
TheMonth = "Jul"
Case "8"
TheMonth = "Aug"
Case "08"
TheMonth = "Aug"
Case "9"
TheMonth = "Sep"
Case "09"
TheMonth = "Sep"
Case "10"
TheMonth = "Oct"
Case "11"
TheMonth = "Nov"
Case "12"
TheMonth = "Dec"
End Select
ConvertDateFormatDDmmmYYYY = TheDay & " " & TheMonth & " " & TheYear
End Function
'#################################################################################################################################
'Public Function ReformatDateDDMMYYYY(inputdate)
'
'Description: Reformat the date after the dateadd to bring it back to format DD/MM/YYYY
'
'Parameters: DD/MM/YYYY
'
'Return: Reformatted date in DD/MM/YYYY
'
'#################################################################################################################################
Public Function ReformatDateDDMMYYYY(inputdate)
TheYear = Year(inputdate)
TheMonth = Month(inputdate)
TheDay = Day(inputdate)
If Len(TheMonth) = 1 Then
TheMonth = "0" & TheMonth
End If
If Len(TheDay) = 1 Then
TheDay = "0" & TheDay
End If
ReformatDateDDMMYYYY = TheDay & "/" & TheMonth & "/" & TheYear
End Function
'#################################################################################################################################
'Public Function UpLoadAttachmentToQC(FilePath)
'
'Description: This copies a specified file to the attachments tab in QC.
' NOTE - the script you are calling this from MUST be stored in QC
'
'Parameters: offset - number of days after today
'
'Return: String
'
'#################################################################################################################################
Public Function UpLoadAttachmentToQC(FilePath)
Set ObjCurrentTest = sCurrentTest.Attachments
Set ObjAttch = ObjCurrentTest.AddItem(Null)
ObjAttch.FileName = FilePath
ObjAttch.Type = 1
ObjAttch.Post
ObjAttch.Refresh
End Function
'#################################################################################################################################
'Public Function RandStr(vLength)
'
'Description: return a random string
'
'Parameters: vLength - the length of string
'
'Return: String
'
'#################################################################################################################################
Public Function RandStr(vLength)
vString = "abcdefghijklmnopqrstuvwxyz"
If vLength > Len(vString) Then
vLen = Len(vString)
Else
vLen = Cint(vLength)
End If
Do Until Len(vTemp) = vLen
Randomize ' Initialize random-number generator.
vNum = Int((Len(vString) * Rnd) + 1)
If Not Instr(vTemp, Mid(vString,vNum,1)) Then
vTemp = vTemp & Mid(vString,vNum,1)
End If
Loop
RandStr = vTemp
End Function
'#################################################################################################################################
'Public Function RandInt(vLength)
'
'Description: return a random number (string)
'
'Parameters: vLength - the length of string
'
'Return: String
'
'#################################################################################################################################
Public Function RandInt(vLength)
vString = "0123456789"
If vLength > Len(vString) Then
vLen = Len(vString)
Else
vLen = Cint(vLength)
End If
Do Until Len(vTemp) = vLen
Randomize ' Initialize random-number generator.
vNum = Int((Len(vString) * Rnd) + 1)
If Not Instr(vTemp, Mid(vString,vNum,1)) Then
vTemp = vTemp & Mid(vString,vNum,1)
End If
Loop
RandInt = vTemp
End Function
'#################################################################################################################################
'Public Function RemoveExtraSpaces(Text)
'
'Description: return a string with any double-spaces between words removed
'
'Parameters: Text - the string
'
'Return: String
'
'#################################################################################################################################
Public Function RemoveExtraSpaces(Text)
If (IsNull(Text)) Or (Text = "") Then
RemoveExtraSpaces = ""
Exit Function
End If
tmpArray = Split(Text)
newstring = tmpArray(0)
For i = 1 to UBound(tmpArray)
If tmpArray(i) <> "" Then
newstring = newstring & " " & tmpArray(i)
End If
Next
RemoveExtraSpaces = newstring
End Function
'#################################################################################################################################
'Public Function InitDB(DBName, objConn, objRecordset)
'
'Description: Initialises DB Connection
'
'Parameters: DBName - the database to connect to
' objConn - the connection object
' objRecordset - the record set object
'
'Return: objConn, objRecordset
'
'#################################################################################################################################
Public Function InitDB(DBName, objConn, objRecordset)
Set objConn = CreateObject("ADODB.Connection")
objConn.CursorLocation = 3
Set objRecordset = CreateObject("ADODB.recordset")
objRecordset.CursorType = 3
On Error Resume Next
objConn.Open(DBName)
On Error Goto 0
If objConn.State = 0 Then
ReportStepResult Test_Step_Id, "Failed", "InitDB: Unable to establish connection to " & DBName
ExitTest
InitDB = False
End If
InitDB = True
End Function
'#################################################################################################################################
'Public Function GetEnv()
'
'Description: Gets the environment being tested, either ftom QC or the env vars
'
'Parameters: N/A
'
'Return: the environment being tested
'
'#################################################################################################################################
Public Function GetEnv()
If sCurrentRun Is Nothing Then
GetEnv = Environment("Env")
Else
QCUtil.CurrentTestSet.Refresh
GetEnv = UCase(QCUtil.CurrentTestSet.Field("CY_USER_06"))
'only use field value if it's valid
If (Trim(GetEnv) <> "ST1") And (Trim(GetEnv) <> "ST2") And (Trim(GetEnv) <> "UAT") Then
GetEnv = Environment("Env")
End If
End If
End Function
'#################################################################################################################################
'Public Function CalcSecsFromTime(Timestamp)
'
'Description: calculates the number of seconds from a given timestamp
'
'Parameters: Timestamp, format HH:MM:SS
'
'Return: the value in seconds
'
'#################################################################################################################################
Public Function CalcSecsFromTime(Timestamp)
tmpArray = Split(Timestamp, ":")
If UBound(tmpArray) <> 2 Then
Reporter.ReportEvent micFail, "CalcSecsFromTime", "Invalid parameter: " & Timestamp
ExitTest
End If
hh = tmpArray(0) * 3600
mm = tmpArray(1) * 60
CalcSecsFromTime = hh + mm + tmpArray(2)
End Function
'#################################################################################################################################
'Public Function MonetaryAmount(Amount)
'
'Description: ensures a given value is pounds and pence
'
'Parameters: Amount
'
'Return: monetary amount
'
'#################################################################################################################################
Public Function MonetaryAmount(Amount)
If Instr(Amount, ".") Then
MonetaryAmount = Amount
Else
MonetaryAmount = Amount & ".00"
End If
End Function
'#################################################################################################################################
'Public Function RunJarFile
'
'Description: RunJarFile
'
'Parameters: jarLocation
'
'Return: N/A
'
'#################################################################################################################################
Public Function RunJarFile(jarLocation)
Dim oShell
Set oShell = CreateObject ("Wscript.shell")
jarFile = "eDocsTestStub.jar"
oShell.run jarLocation &"\" &jarFile
ReportStepResult Test_Step_Id, "Passed", "Launched jar file: '" & jarFile & "' from: '" & jarLocation & "'"
Set oShell = Nothing
End Function
'#################################################################################################################################
'GetFolderAttachmentPath(TDAttachmentName, TDFolderPath)
'
'Description: Extracts a named file from QC to the temp QTP folder
'
'Parameters: TDAttachmentName, TDFolderPath
'
'Return: the path to the downloaded file
'
'#################################################################################################################################
Public Function GetFolderAttachmentPath(TDAttachmentName, TDFolderPath)
Set otaTreeManager = QCUtil.TDConnection.TreeManager
Set otaSysTreeNode = otaTreeManager.NodeByPath(TDFolderPath)
Set otaAttachmentFactory = otaSysTreeNode.Attachments
Set otaAttachmentFilter = otaAttachmentFactory.Filter
intNdId = otaSysTreeNode.NodeID
otaAttachmentFilter.Filter("CR_REFERENCE") = "'ALL_LISTS_" & intNdId & "_" & TDAttachmentName & "'"
Set otaAttachmentList = otaAttachmentFilter.NewList
If otaAttachmentList.Count > 0 Then
Set otaAttachment = otaAttachmentList.Item(1)
otaAttachment.Load True, ""
strPath = otaAttachment.FileName
Else
Reporter.ReportEvent micFail,"Failure in library function 'GetFolderAttachmentPath'", _
"Failed to find attachment '" & TDAttachmentName & "' in folder '" & TDFolderPath & "'."
End If
GetFolderAttachmentPath = strPath
Set otaAttachmentFactory = Nothing
Set otaAttachment = Nothing
Set otaAttachmentList = Nothing
Set otaAttachmentFilter = Nothing
Set otaTreeManager = Nothing
Set otaSysTreeNode = Nothing
End Function
'########################################################################################################################################################################
'#Function Description: The function terminates all the active caffeine processes and relaunches the app, for the duration indicated by the parameter
'#Input Parameters: Duration
'#Return Values: N/A
'#######################################################################################################################################################################
Public Function Launch_Caffeine(Duration)
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'caffeine.exe'") 'Capture the active windows Excel Processes
If colProcesses.Count > 0 Then
Set oShell = CreateObject("WScript.shell")
cmd = "c:\caffeine.exe -appexit"
On Error Resume Next
For Each objProcess in colProcesses 'Terminate Caffeine Processes one by one
oShell.Run(cmd)
Next
If err.number <> 0 Then
Reporter.ReportEvent micPass, "Caffeine", "Caffeine was already running, but not from the root c: drive, so unable to terminate it"
End If
On Error GoTo 0
Set oShell = Nothing
End If
On Error Resume Next
Set oShell = CreateObject("WScript.shell")
cmd = "c:\caffeine.exe -exitafter:" & Duration
oShell.Run(cmd)
If err.number <> 0 Then 'caffeine app not found; install it from QC
DownloadFileFromQC "Subject\Automated Testing - Shared Files", "caffeine.exe", "c:\caffeine.exe"
oShell.Run(cmd)
End If
On Error GoTo 0
Set objWMIService = Nothing
Set colProcesses = Nothing
Set oShell = Nothing
End Function
'#################################################################################################################################
'Generate_NI_No()
'
'Description: Create a random, valid national Insurance number
'
'Parameters: None
'
'Return: NI no.
'
'#################################################################################################################################
Public Function Generate_NI_No()
tmp = RandomNumber(0,3)
tmpArray = Array("A", "B", "C", "D")
Generate_NI_No = UCase(RandStr(2)) & RandInt(6) & tmpArray(tmp)
End Function
'########################################################################################################################################################################
'#Function Description:
'#Input Parameters:
'#Return Values:
'#######################################################################################################################################################################
Public Function UploadFileToResources(FileName, ResourceFolder)
Set RootResourceFolder = QCUtil.QCConnection.QCResourceFolderFactory.Root
Set RootResourceFolderFactory= RootResourceFolder.QCResourceFolderFactory
Set theFilter = RootResourceFolderFactory.Filter
theFilter("RFO_NAME") = "'" & ResourceFolder & "'"
NumAutoFolders = theFilter.NewList.count
If NumAutoFolders = 0 Then 'create the folder
Set NewFolder = RootResourceFolderFactory.AddItem(Null)
NewFolder.Name = CStr(ResourceFolder)
NewFolder.Post
MsgBox "'" & ResourceFolder & "' folder did not exist and has now been created. Please re-run this script"
wscript.quit
End If
tmpArray = Split(FileName, "\")
FullPath = ""
For i = 0 to UBound(tmpArray) - 1
FullPath = FullPath & tmpArray(i) & "\"
Next
LongFileName = tmpArray(UBound(tmpArray))
tmpArray = Split(LongFileName, ".")
ShortFileName = tmpArray(0)
FileExtension = tmpArray(UBound(tmpArray))
Set AutoFolder = theFilter.NewList(1)
Set resourceFactory = AutoFolder.QCResourceFactory
Set theFilter = resourceFactory.Filter
theFilter("RSC_NAME") = "'" & CStr(ShortFileName) & "'"
Set tmpResource = theFilter.NewList
For Each Resource in tmpResource
resourceFactory.RemoveItem Resource
Next
Set theResource = resourceFactory.AddItem(CStr(ShortFileName))
theResource.FileName = LongFileName
Select Case LCase(FileExtension)
Case "tsr"
theResource.ResourceType ="Shared object repository"
Case "xls"
theResource.ResourceType ="Data table"
Case "qfl", "vbs"
theResource.ResourceType ="Function library"
End Select
theResource.Post
Set resourceStorage = theResource
resourceStorage.UploadResource CStr(FullPath), True
End Function
'########################################################################################################################################################################
'#Function Description:
'#Input Parameters:
'#Return Values:
'#######################################################################################################################################################################
Public Function DownloadFileFromResources(ResourceName, ResourceFolder, Destination)
Set RootResourceFolder = QCUtil.QCConnection.QCResourceFolderFactory.Root
Set RootResourceFolderFactory= RootResourceFolder.QCResourceFolderFactory
Set theFilter = RootResourceFolderFactory.Filter
theFilter("RFO_NAME") = "'" & ResourceFolder & "'"
NumAutoFolders = theFilter.NewList.count
If NumAutoFolders = 0 Then
MsgBox "ERROR - '" & ResourceFolder & "' folder does not exist. "
ExitTest
End If
Set AutoFolder = theFilter.NewList(1)
Set resourceFactory = AutoFolder.QCResourceFactory
Set theFilter = resourceFactory.Filter
theFilter("RSC_NAME") = "'" & CStr(ResourceName) & "'"
Set tmpResource = theFilter.NewList
If tmpResource.Count = 0 Then
MsgBox "ERROR - '" & ResourceName & "' resource not found in '" & ResourceFolder & "'"
ExiTest
End If
Set resourceStorage = tmpResource(1)
resourceStorage.DownloadResource CStr(Destination), True
End Function
'#######################################
Public Function Generate_Random_Name()
vowels = Array("a", "e", "i", "o", "u")
hh =hour(now)
mm = minute(now)
ss = second(now)
Generate_Random_Name = UCase(RandStr(1)) & vowels(RandomNumber(0,4)) & Randstr(2) & vowels(RandomNumber(0,4)) & Randstr(1) & hh & mm & ss
End Function
'#######################################
Public Function GenerateTestData()
On Error Resume Next
tmpstr = "Set objExcel = GetObject( ,""Excel.Application"")"
Execute tmpstr
If err.number <> 0 Then ' excel not running; cannot proceed as this test is run from Excel
MsgBox "This test must be run from Excel; closing"
ExitTest
ElseIf TestArgs("XLSheet") <> "" Then
Set objWorkBook = GetObject(TestArgs("XLSheet")) 'will open it if not already running
Set sResultsSheet = objWorkBook.Sheets(TestArgs("ResultsSheet"))
Else'included hard-coded sheet for debugging
Set objWorkBook = GetObject("F:\Condeco\Condeco Test Automation.xlsm")
Set sResultsSheet = objWorkBook.Sheets("testresults")
End If
objExcel.DisplayAlerts = False
Set objSheet = objWorkBook.ActiveSheet
With objSheet
If .AutoFilterMode Then
If .FilterMode Then
.ShowAllData
End If
Else
If .FilterMode Then
.ShowAllData
End If
End If
End With
On Error GoTo 0
'dynamically declare all public variables from spreadsheet
Set c = objSheet.Columns(1).Find(TestName,,,1) 'just find instances where it matches the whole cell
If c is nothing Then
ReportStepResult Test_Step_Id, "Failed", "No data found for '" & TestName & "' in sheet '" & Environment("TestDataSheet") & "'"
ExitTest
End If
PubVarRow = c.Row
LastCol = objSheet.Cells(PubVarRow, objSheet.Columns.count).end(xlToLeft).Column
Set NextPubVar = objSheet.Columns(1).Find("*",c,,1) 'finds the next non-blank cell in column 1
If (NextPubVar Is Nothing) or (NextPubVar.Row <= c.Row) Then
LastRow = objSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row 'this is the last set of data in the sheet
else
LastRow = NextPubVar.Row - 1 'just get the rows before the next set of data
End If
'build a custom dictionary of data to be used
For i = PubVarRow + 1 To LastRow
If UCase(Left(objSheet.Cells(i,2), 1)) = "Y" Then 'data is to be included
sNumIterations = sNumIterations + 1
For j = 3 To LastCol
key = objSheet.Cells(PubVarRow, j)
CustDict.Item(key) = CustDict.Item(key) & objSheet.Cells(i,j) & Chr(10)
Next
End If
Next
pubItems = CustDict.Items
'Clean Items - remove trailing separator
For i = 0 To UBound(pubItems)
pubItems(i) = Left(pubItems(i), len(pubItems(i)) - 1)
Next
'add test name to test results
ReportRow = sResultsSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row + 1
sResultsSheet.Cells(ReportRow, sTestNameCol) = TestName
sResultsSheet.Cells(ReportRow, sTestNameCol).Font.Bold = True
End Function
'#######################################
Sub DeclareIterationData(iteration)
pubKeys = CustDict.Keys
pubItems = CustDict.Items
For i = 0 To UBound(pubKeys)
tmpArr = Split(pubItems(i), Chr(10))
If IsNumeric(tmpArr(iteration - 1)) Then
tmpstr = pubKeys(i) & " = " & tmpArr(iteration - 1)
Else
tmpstr = pubKeys(i) & " = """ & tmpArr(iteration - 1) & """"
End If
Execute tmpstr
Next
End Sub