The idea is to create a keyword framework with dynamic properties, as much as possible. Keywords to read from Excel:
Keyword=Trim(TS_Sheet.cells(j,"D"))
Arg1=Trim(TS_Sheet.cells(j,"E"))
Arg2=Trim(TS_Sheet.cells(j,"F"))
Arg3=Trim(TS_Sheet.cells(j,"G"))
Arg4=Trim(TS_Sheet.cells(j,"H"))
'Execute the corresponding test Steps(Or Keywords)
Call_Function Keyword, Arg1, Arg2, Arg3, Arg4
Call_Function should execute steps:
Function Call_Function (Keyword, Arg1, Arg2, Arg3, Arg4)
On Error Resume Next
Print "Keyword for execution is:- " & Keyword
Dim subS1 : Set subS1 = GetRef(cstr(Keyword))(Arg1, Arg2, Arg3, Arg4)
If Err.Num<>0 Then
Msgbox "Error: "&Err.Num, "OK", "Runtime Error "&Err.Num
reporter.ReportNote "Error occured: "&Err.Num&" keyword: "&keyword&" TCID: "&TCID&" TSID: "&TSID
End If
Mybrowser.Sync
Err.Clear
On Error GoTo 0
Set subS1 = Nothing
End Function
I need to wait for a property to be reached using WaitProperty, Chekproperty or any other methot, like
MyBrowser.WebButton("html id:=.*"&Arg2).WaitProperty ("disabled", Arg4, 1)
BUT I need to pass the parameter to wait from Excel to make it more dynamic, like
MyBrowser.ChildObject("micclass:=.*"&Arg1, "html id:=.*"&Arg2).WaitProperty (Arg3, Arg4, 1)
So far, it did not work. QTP just skips that part of code. I tried something like following:
Function Wait_Property (Arg1, Arg2, Arg3, Arg4)
Process=".."
Do
For Iterator = 1 To 100 Step 0.5 '///this can be any number just to make sure loop executes long enough to property to be reached
If MyBrowser.ChildObject("micclass:=.*"&Arg1, "html id:=.*"&Arg2).WaitProperty (Arg3, Arg4, 0.1) Then
Print "Reached."
Exit Do
Else
Print "Wait. Processing.."&Process
Wait 0.5
End If
Process = Process+".."
Next
Loop While False
End Function
Also I tried ...If MyBrowser.ChildObject("micclass:=.*"&Arg1, "html id:=.*"&Arg2, Arg3=Arg4).Exist Then...
but QTP still skips that.
What's wrong? Is there any other way to do that?
UPD 1: The following is working now:
PropWait = cstr(Browser("micclass:=Browser","CreationTime:=0","name:=.*").page("micclass:=Page","CreationTime:=0","Title:=.*").WebButton("html id:=.*"&Arg2).GetROProperty(Arg3))
Do Until cstr(PropWait) = cstr(Arg4)
If PropWait = Arg4 Then
Exit Do
ElseIf PropWait = "" Then
print "PropWait Empty"
Exit Do
Else
End If
Wait 2
Print PropWait&" : Wait. Processing.."&Process
Process = Process+".."
PropWait = cstr(Browser("micclass:=Browser","CreationTime:=0","name:=.*").page("micclass:=Page","CreationTime:=0","Title:=.*").WebButton("html id:=.*"&Arg2).GetROProperty(Arg3))
Loop
But I need micclass to be dynamic, too.
UPD 2: Added description.create to previous update:
Dim WaitObj : Set WaitObj = Description.Create
WaitObj("micclass").Value = Arg1
WaitObj("html id").Value = Arg2
PropWait = Browser("micclass:=Browser","name:=.*").page("micclass:=Page","Title:=.*").ChildObjects(WaitObj).GetROProperty(Arg3)
But QTP skips it and everything following this peace.
UPD 3:
As advised in comments, tried to comment On Error Resume Next
in Call_Function
, but now after first step (which is to open browser) it returns error:
"Object required: 'GetRef(...)(...)"
UPD 4:
Tried to put On Error Resume Next
in Wait_Property Function: (On Error Resume Next
in Call_Function
uncommented)
Function Wait_Property (Arg1, Arg2, Arg3, Arg4)
On Error Resume Next
...
Now, not sure if it recognizes the object, but it prints next (while the property in Arg3 has a value:
PropWait =
PropWait Empty
Finally, the next is working:
Function Wait_Property (Arg1, Arg2, Arg3, Arg4)
print "Test Function Call"
Dim WObj : Set WObj = Description.Create()
WObj("micclass").Value = Arg1
WObj("html id").Value = Arg2
Dim ObjColl : Set ObjColl = MyBrowser.ChildObjects(WObj)
For t = 0 To ObjColl.Count-1
'print "count:="&ObjColl.Count
WaitPro = cstr(ObjColl(t).GetROProperty(Arg3))
Do Until WaitPro = Arg4
print "Wait. Progress..."&Progress
wait 2
Progress = Progress+".."
Set ObjColl = MyBrowser.ChildObjects(WObj)
WaitPro = cstr(ObjColl(t).GetROProperty(Arg3))
Loop
print "Function Executed"
Next
Set WObj = Nothing
End Function