刚刚用了QTP的描述性编程,忽然想起用WinRunner也用一下描述性编程。做了感觉还不错,呵呵。。。。
以下是本人用WINDOW XP自带的一个计算器做的一个小例子:
#################################################################################
#
# Descrīption-------------Use Descrīption Programing to Test the CALC in Window XP by WinRunner
#
# Tester------------------Lantian Wei
#
# Modify Time-----------2007-7-24
#
#################################################################################
invoke_application("calc.exe","","c:\\windows\\system32\\",SW_SHOW); static myarr[]={{1,"+",2,3},{1,"-",2,-1},{1,"*",2,2},{1,"/",2,0.5}}; win_activate("{class: window,label: Calculator}"); set_window("{class: window,label: Calculator}",5); for(i=0;i<4;i++) { for(j=0;j<3;j++) button_press("{class: push_button,label:"&myarr[i,j]&"}"); button_press("{class: push_button,MSW_class: Button,label:=}"); edit_get_text ("{class: edit}", result); if(index(myarr[i,j],".")==0) { if(result==myarr[i,j]&". ") tl_step("CheckAnswer",0,"The calculatation is right:"&myarr[i,j-3]&" "&myarr[i,j-2]&" "&myarr[i,j-1]&" = "result); else tl_step("CheckAnswer",1,"The calculatation is wrong:"&myarr[i,j-3]&" "&myarr[i,j-2]&" "&myarr[i,j-1]&" != "result); wait(1); } else { if(result==myarr[i,j]&" ") tl_step("CheckAnswer",0,"The calculatation is right:"&myarr[i,j-3]&" "&myarr[i,j-2]&" "&myarr[i,j-1]&" = "result); else tl_step("CheckAnswer",1,"The calculatation is wrong:"&myarr[i,j-3]&" "&myarr[i,j-2]&" "&myarr[i,j-1]&" != "result); wait(1); } } win_close("{class: window,label: Calculator}"); |
以上是本人用描述性编程写的脚本,至此现丑了。如有不足之处还请大家指正!在此先表示感谢!
通过这个例子的练习,我发现它确实有好多优点,比如你从此不用在关心那烦人的对象库了,而一个测试脚本里基本上在对象库中出现的问题最多了。然而它还是有缺点的,比如对于无法识别的对象,它就无能为力了,而对于那些OBJECT对象,它的支持也不好。所以如果WR对应用程序识别的满好的话,不如用描述性编程试试。