0

这个想法是尽可能地创建一个具有动态属性的关键字框架。从 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_Fu​​nction 应该执行以下步骤:

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

我需要等待使用 WaitProperty、Chekproperty 或任何其他方法到达属性,例如

MyBrowser.WebButton("html id:=.*"&Arg2).WaitProperty ("disabled", Arg4, 1)

但我需要传递参数以等待 Excel 以使其更具动态性,例如

MyBrowser.ChildObject("micclass:=.*"&Arg1, "html id:=.*"&Arg2).WaitProperty (Arg3, Arg4, 1)

到目前为止,它没有奏效。QTP 只是跳过那部分代码。我尝试了以下方法:

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

我也尝试过...If MyBrowser.ChildObject("micclass:=.*"&Arg1, "html id:=.*"&Arg2, Arg3=Arg4).Exist Then...,但 QTP 仍然跳过它。

怎么了?有没有其他方法可以做到这一点?

UPD 1: 以下正在工作:

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

但我也需要 micclass 是动态的。

UPD 2: 在之前的更新中添加了 description.create:

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)

但是 QTP 跳过了它以及遵循这种和平的一切。

更新 3

On Error Resume Next正如评论中所建议的那样,尝试在 中发表评论Call_Function,但现在在第一步(即打开浏览器)之后它返回错误:

“需要对象:'GetRef(...)(...)”

UPD 4: 试图放入Wait_PropertyOn Error Resume Next函数:(未注释)On Error Resume NextCall_Function

Function Wait_Property (Arg1, Arg2, Arg3, Arg4)
On Error Resume Next
...

现在,不确定它是否识别出该对象,但它会打印下一个(而 Arg3 中的属性有一个值:

道具等待 =

PropWait 空

4

1 回答 1

1

最后,下一个工作:

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
于 2017-07-11T21:36:43.720 回答