我需要在函数中传递一个对象及其操作,以便每次只能调用该函数并保存我为所有对象编写相同的步骤,例如在执行操作之前验证对象。类似于QTP/UFT中的注册用户函数。
但是,Testcomplete没有此功能
(至少据我所知,我很乐意知道是否有)
这是我正在尝试但无法执行的代码:
Call OpenPageorTab("Aliases.Admin.wndMain.toolStrip", ".Visible")
Function OpenPageorTab(obj, method)
'if obj.Exists then
execute a = obj&method
delay(1000)
OpenPageorTab = True
'Else
log.Error "Unable to find the object"
OpenPageorTab = False
'End if
在前面传递对象而不是字符串时使用if条件
它在“execute”语句处失败,并在执行此语句时给我VbScript运行时错误。
我的问题有两个方面-
-
如何在函数中传递对象及其操作并执行它
-
也可以将对象传递给它自己,而不是传递给ex的字符串:
obtoolbar = "Aliases.Admin.wndMain.toolStrip"
Call OpenPageorTab(obtoolbar, ".Visible")
感谢您在此问题上提供的任何帮助或指导
编辑1
我离答案很近,但并不准确。我可以将对象作为字符串传递-请检查下面的代码
Call OpenPageorTab("Aliases.Admin.wndMain.toolStrip", ".Click")
Function OpenPageorTab(obj, method)
' if obj.Exists then
eobj = "" & obj & method
execute (eobj)
delay(1000)
OpenPageorTab = True
' Else
log.Error "Unable to find the object"
OpenPageorTab = False
' End if
End Function
但是我仍然需要传递对象
Set oToolStrip = Aliases.Admin.wndMain.toolStrip
Call OpenPageorTab(oToolStrip, ".Click")
这是我无法做到的。
编辑2
我已经得到了这个问题的答案,并发布了解决方案。也就是说,是否有任何方法可以将该函数用作一种方法?