Public Function func_waitForPage(objectref)
Dim strResult
Dim intloopcounter
strResult=False
Set wshell = CreateObject("WScript.Shell")
wShell.Sendkeys("^{HOME}")
For intloopcounter = 1 to 3
If objectref.Exist Then
sub_VerifyErrorNumber "wait for page"
strResult = True
Exit For
End If
Next
If strResult <> True Then
func_waitForPage = False
Else
func_waitForPage = True
End If
End Function
Monday, May 20, 2013
Wait for a page to load
Close all browsers using QTP
Public Function func_closeBrowsers()
Dim oBrowser 'to store browser object description
'Create description object
Set strOpenBrowser = Description.Create
strOpenBrowser("creationtime").Value = 0
'close all open browsers
While Browser(strOpenBrowser).Exist(0)
Browser(strOpenBrowser).Close
Wend
'verify whether all the opened browsers are closed or not.
If Browser(strOpenBrowser).Exist(0) = False Then
func_closeBrowsers = True
sub_reportSuccess "Close Browser", "All browsers are closed successfully"
Else
func_closeBrowsers = False
End If
End Function 'End of 'closeBrowsers' function.
Tuesday, May 14, 2013
Convert date format
Public Function func_convertDateFormat(ByVal DateString, ByVal SourceFormat, ByVal ReqFormat)
Dim strMonthVal ' to store the month value
Dim strDayVal ' to store the day value
Dim strYearVal ' to store the year value
Dim aTempVal ' to store the splitting date values in an array
If Not IsEmpty(DateString) Then
' select the specified source format
Select Case SourceFormat
Case "MM-DD-YYYY"
' split and store the month,day and year values in variables
aTempVal = Split(DateString, "-")
'verify input date string whether it is in source format or not.
If Ubound(aTempVal) = 2 Then
strMonthVal = aTempVal (0)
strDayVal = aTempVal (1)
strYearVal = aTempVal (2)
Else
func_convertDateFormat = "ErrMsg: Input parameter DateString is not in specified source format"
End If
Case "YYYY-MM-DD"
' split and store the month,day and year values in variables
aTempVal = Split(DateString, "-")
'verify input date string whether it is in source format or not.
If Ubound(aTempVal) = 2 Then
strYearVal = aTempVal (0)
strMonthVal = aTempVal (1)
strDayVal = aTempVal (2)
Else
func_convertDateFormat = "ErrMsg: Input parameter DateString is not in specified source format"
End If
Case "MM/DD/YYYY"
' split and store the month,day and year values in variables
aTempVal = Split(DateString, "/")
'verify input date string whether it is in source format or not.
If Ubound(aTempVal) = 2 Then
strMonthVal = aTempVal (0)
strDayVal = aTempVal (1)
strYearVal = aTempVal (2)
Else
func_convertDateFormat = "ErrMsg: Input parameter DateString is not in specified source format"
End If
Case "YYYY/MM/DD"
' split and store the month,day and year values in variables
aTempVal = Split(DateString, "/")
'verify input date string whether it is in source format or not.
If Ubound(aTempVal) = 2 Then
strYearVal = aTempVal (0)
strMonthVal = aTempVal (1)
strDayVal = aTempVal (2)
Else
func_convertDateFormat = "ErrMsg: Input parameter DateString is not in specified source format"
End If
Case "DD/MM/YYYY"
' split and store the month,day and year values in variables
aTempVal = Split(DateString, "/")
'verify input date string whether it is in source format or not.
If Ubound(aTempVal) = 2 Then
strDayVal = aTempVal (0)
strMonthVal = aTempVal (1)
strYearVal = aTempVal (2)
Else
func_convertDateFormat = "ErrMsg: Input parameter DateString is not in specified source format"
End If
Case Else
'returns false when sorce format is not in the specified list.
func_convertDateFormat = "ErrMsg: Input parameter" & " " & SourceFormat & " " & "is not valid"
Exit Function
End Select
' select the specified source format
Select Case ReqFormat
' Combine the month,day and year values in variables to get required format
Case "MM-DD-YYYY"
func_convertDateFormat = strMonthVal & "-" & strDayVal & "-" & strYearVal
Case "YYYY-MM-DD"
func_convertDateFormat = strYearVal & "-" & strMonthVal & "-" & strDayVal
Case "MM/DD/YYYY"
func_convertDateFormat = strMonthVal & "/" & strDayVal & "/" & strYearVal
Case "DD/MM/YYYY"
func_convertDateFormat = strDayVal & "/" & strMonthVal & "/" & strYearVal
Case "YYYY/MM/DD"
func_convertDateFormat = strYearVal & "/" & strMonthVal & "/" & strDayVal
Case Else
func_convertDateFormat = "ErrMsg: Input parameter" & " " & ReqFormat & " " & "is not valid"
Exit Function
End Select
Else
func_convertDateFormat = "ErrMsg: Input parameter" & " " & DateString & " " & "is not valid"
End If
End Function
Register user func
Public function func_WebEditset(object,strValue)
strTempfieldname=Replace(Replace(object.ToString,"WebEdit",""),"_"," ")
If object.Exist Then
If object.GetROProperty("disabled")=0 Then
object.Set strValue
func_WebEditset = True
Else
func_WebEditset= " field is disabled"
End If
Else
func_WebEditset=" field is not Found"
End If
End Function
RegisterUserFunc "WebEdit","Set","func_WebEditset",True
Finding a table from the webpage
The below function finds a table and sets the control to the table using the index.
Public Function func_Find_Table_Index_Variable(objTable,introw,intcol,sCel_1_1_value,intStartIndex,blnExactMatch)
Table_Index = intStartIndex
cel_value = ""
sCel_1_1_value=Trim(sCel_1_1_value)
objTable.SetTOProperty "index", Table_Index
Do
If objTable.Exist(0) =False Then
Exit Do
End If
cel_value = Trim(objTable.GetCellData(introw,intcol))
Table_Index = Table_Index+1
objTable.SetTOProperty "Index", Table_Index
If objTable.Exist(0) =False Then
Exit Do
End If
If (blnExactMatch=False and Instr(Ucase(cel_value),ucase(sCel_1_1_value))>0 ) Or (blnExactMatch=True and Ucase(cel_value)=Ucase(sCel_1_1_value) ) Then
Exit Do
End If
Loop
If (blnExactMatch=False and Instr(Ucase(cel_value),ucase(sCel_1_1_value))>0 )Or blnExactMatch=True and Ucase(cel_value)=Ucase(sCel_1_1_value)Then
objTable.SetTOProperty "index", Table_Index-1
func_Find_Table_Index_Variable = Table_Index-1
Exit Function
End If
func_Find_Table_Index_Variable = False
End Function
Thursday, May 9, 2013
Compare 2 arrays
Public Function func_Comparetwoarrays(aFirstArray,aSecondArray)
Dim intRowVal ' Incrementer
Dim StrInputVal ' Capture input Array details
Dim strFailureVal 'To capture failed array values.
Dim strCapturedVal 'to store captured values.
'verify whether input arrays are empty or not.
If UBound(aFirstArray) <> -1 And UBound(aSecondArray) <> -1 Then
'verify whether input arrays sizes are equal or not.
If UBound(aFirstArray) = UBound(aSecondArray) Then
'repeat loop untill last element in each array is verified.
For intRowVal = 0 To UBound(aFirstArray)
'converting each charated in text in to upper case.
firstarrval = Ucase(Trim(aFirstArray(intRowVal)))
secondarrval = Ucase(Trim(aSecondArray(intRowVal)))
'removing spaces between the words in the text.
firstarrval = Replace(firstarrval," ","")
secondarrval = Replace(secondarrval," ","")
If Trim(firstarrval)<> "" and Trim(secondarrval)<>""Then
' Compares the input array values with captured array values
If Instr(Trim(firstarrval),Trim(secondarrval)) > 0 or Instr(Trim(secondarrval),Trim(firstarrval)) > 0 Then
func_Comparetwoarrays = True
Else
'captures the array values which are not matched.
func_Comparetwoarrays = aFirstArray(intRowVal)&" , "&aSecondArray(intRowVal)
Exit Function
End If
End If
Next
Else
func_Comparetwoarrays = "Two arrays are different in size."
End If
Else
func_Comparetwoarrays = "Input parameters are not Valid."
End If
End Function ' End of 'Comparetwoarrays' function
Generate random dates
Public Function func_generate_RandomDates(NoofDates)
Dim datesArray 'To capture generated dates in an array
Dim intincrementer 'To store loop counter value.
Dim intRandomnumber 'To store random number.
Dim strtravelDateTime 'To store travel date.
Dim strFirstDate 'To store first date.
Dim astrDates 'To store dates.
Dim strReturnval 'To store the return value
strFirstDate = ""
'verify whether input parameter is equal to null or zero.
If NoofDates > 0 Then
'To get specified number of dates (after 90 to 180 days of current date)
For intincrementer=0 To Cint(NoofDates)-1
'generates random number between 90 and 181
intRandomnumber = Int((91 * Rnd) + 90)
'addes random number with current date to generate random date.
strtravelDateTime=Date + intRandomnumber
If intincrementer > 0 Then
strFirstDate=Trim(strFirstDate & ". " & strtravelDateTime)
Else
strFirstDate = strtravelDateTime
End If
Next
'splits random dates
datesArray=Split(strFirstDate,". ")
' Call the function to sort the generated random dates
astrDates = func_datesSorting(datesArray)
' to verify for dates in sorting order
If Instr(astrDates(0),"ErrMsg:") > 0 Then
func_generate_RandomDates = "ErrMsg: Unable to get the dates in sorting order. Because," & " " & astrDates
Else
func_generate_RandomDates = astrDates
End If
Else
'Return the failure message when input parameter is not valid
func_generate_RandomDates = Array("ErrMsg: Input parameter Is Invalid")
End If
End Function 'Enfd of 'generate_RandomDates' function
'####################################################
Public Function func_datesSorting(strArray)
Dim inti 'to store the increment value
Dim blnSwitched 'to hold the value to switch
Dim strTemp 'temparary variable
If Not IsEmpty(strArray) AND Ubound(strArray) <> -1 Then
Do
blnSwitched =False
'loop to sort the dates in the array.
For inti = 0 To Ubound(strArray)-1
'verify whether present date is greater than preveous date
If CDate(strArray(inti)) > CDate(strArray( inti+1)) Then
strTemp = strArray(inti)
strArray( inti) = strArray( inti + 1)
strArray( inti + 1) = strTemp
blnSwitched = True
End If
Next
Loop While blnSwitched
'retuns sorted array.
func_datesSorting = strArray
Else
func_datesSorting = Array("ErrMsg: Input Dates Array is empty.")
End If
End Function
Subscribe to:
Comments (Atom)
AI in Software Testing: How Artificial Intelligence Is Transforming QA
For years, software testing has lived under pressure: more features, faster releases, fewer bugs, smaller teams. Traditional QA has done her...
-
Agile software development is a highly iterative and collaborative approach to software development that emphasizes flexibility and a...
-
Test-Driven Development (TDD) is a software development approach that emphasizes writing automated tests before writing the code. The appr...
-
Software development is a complex process that requires a high degree of accuracy, efficiency, and speed. One way to achieve these goals i...