无法从 Excel 读取参数名称(!不是值)

Cannot read parameter name (!not value) from Excel

我们的想法是创建一个尽可能具有动态属性的关键字框架。要阅读的关键字 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 应执行步骤:

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、Chek属性 或任何其他方法等待 属性 到达,例如

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 仍然跳过那个。

怎么了?还有其他方法吗?

更新 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 是动态的。

更新 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 会跳过它以及此和平之后的所有内容。

UPD 3:

按照评论中的建议,尝试在 Call_Function 中评论 On Error Resume Next,但现在在第一步(打开浏览器)之后它 returns 错误:

"Object required: 'GetRef(...)(...)"

更新 4: 试图将 On Error Resume Next 放入 Wait_Property 函数:(On Error Resume NextCall_Function 未注释)

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

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

PropWait =

PropWait Empty

终于,下一个开始工作了:

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