SilkTest天龙八部系列3-动态父窗口

SilkTest中用parent语句来声明某个window的父窗口,这会帮助silktest在识别该对象时检查其是否是由该父窗口打开,如果parent语句申明的父窗口并不存在,那么该对象无法被正确识别。

有的时候,某些新打开的窗口可能由多个父窗口打开,那么固定的parent语句显然无法完成任务,这个时候有两种方法解决。一是使用动态的tag语句来代替parent的功能,另外就是编写tag函数来动态返回动态的tag。

例如我们想要测试一个silktest onlinehelp的BookmarkDefine窗口(打开silktest onlinehelp->菜单bookmark->define),正常情况下我们抓取的inc文件如下:

[-] window MainWin SilkTestHelp
[+] multitag “SilkTest Help”
[ ] “$C:/WINDOWS/winhlp32.exe”
[+] Menu File
[ ] tag “File”
[+] MenuItem Open
[+] multitag “Open”
[ ] “$1101”
[+] MenuItem PrintTopic
[+] multitag “Print Topic”
[ ] “$1103”
[+] MenuItem Exit
[+] multitag “Exit”
[ ] “$1105”
[+] Menu Edit
[ ] tag “Edit”
[+] MenuItem Copy
[+] multitag “Copy”
[ ] “$1203”
[+] MenuItem Annotate
[+] multitag “Annotate”
[ ] “$1202”
[+] Menu Bookmark
[ ] tag “Bookmark”
[+] MenuItem Define
[+] multitag “Define”
[ ] “$1301”
[+] Menu Options
[ ] tag “Options”
[+] Menu KeepHelpOnTop
[ ] tag “Keep Help on Top”
[+] MenuItem Default
[+] multitag “Default”
[ ] “$1470”
[+] MenuItem OnTop
[+] multitag “On Top”
[ ] “$1471”
[+] MenuItem NotOnTop
[+] multitag “Not On Top”
[ ] “$1472”
[+] MenuItem DisplayHistoryWindow
[+] multitag “Display History Window”
[ ] “$1453”
[+] Menu Font
[ ] tag “Font”
[+] MenuItem Small
[+] multitag “Small”
[ ] “$1462”
[+] MenuItem Normal
[+] multitag “Normal”
[ ] “$1460”
[+] MenuItem Large
[+] multitag “Large”
[ ] “$1461”
[+] MenuItem UseSystemColors
[+] multitag “Use System Colors”
[ ] “$1465”
[+] Menu Help
[ ] tag “Help”
[+] MenuItem Version
[+] multitag “Version”
[ ] “$1503”
[+] MenuItem AboutWinHelp2000
[+] multitag “About WinHelp 2000”
[ ] “$10001”
[+] CustomWin MS_WINTOPIC1
[ ] tag “[MS_WINTOPIC]$0”
[+] CustomWin MS_WINICON1
[ ] tag “[MS_WINICON]$0”
[+] PushButton HelpTopics
[+] multitag “Help Topics”
[ ] “$-1[1]”
[+] PushButton Back
[+] multitag “Back”
[ ] “$-1[2]”
[+] PushButton Print
[+] multitag “Print”
[ ] “$-1[3]”
[+] CustomWin Wh98NavPane1
[ ] tag “[Wh98NavPane]$999”
[+] CustomWin AfxWnd42s1
[ ] tag “[AfxWnd42s]$999[1]”
[+] PageList PageList1
[ ] tag “$998”
[+] StaticText StaticText1
[ ] tag “$65535”
[+] CustomWin Index
[+] multitag “[AfxWnd42s]Index”
[ ] “[AfxWnd42s]$999[2]”
[+] TextField TextField1
[ ] tag “$14003”
[+] TreeView TreeView1
[ ] tag “$14005”
[+] PushButton Display
[+] multitag “Display”
[ ] “$14004”
[ ]
[-] window DialogBox BookmarkDefine
[ ] tag “Bookmark Define”
[ ] parent SilkTestHelp
[+] StaticText BookmarkNameText
[+] multitag “Bookmark name:”
[ ] “$65535”
[+] TextField BookmarkName1
[+] multitag “Bookmark name:”
[ ] “$102”
[+] ListBox BookmarkName2
[+] multitag “Bookmark name:”
[ ] “$103”
[+] PushButton OK
[+] multitag “OK”
[ ] “$1”
[+] PushButton Cancel
[+] multitag “Cancel”
[ ] “$2”
[+] PushButton Delete
[+] multitag “Delete”
[ ] “$104”

注意是
tag “Bookmark Define”
parent SilkTestHelp

使用动态tag的方法如下:
将上面的内容改成
tag “../Bookmark Define”

使用tag函数的方法如下:
[ ] tag GetTag()
[-] string GetTag()
[-] if SilkTestHelp.Exists()
[ ] return “../Bookmark Define”

下面这段代码可以用来测试:

[-] testcase DynamicParent()
[ ] SilkTestHelp.SetActive()
[ ] SilkTestHelp.Bookmark.Define.Check()
[ ] sleep(1)
[ ] BookmarkDefine.Close()
[ ] sleep(1)

Leave a comment

请输入正确的验证码