QTP測試Windows計算器

TIB發表於2010-03-19

relevantcodes.com在《Automating Windows Calculator Part 1》這篇文章中介紹了用QTP測試Windows計算器的例子,對於初學者理解QTP自動化測試過程、函式的使用等方面的內容都很有幫助:

http://relevantcodes.com/automating-windows-calculator-part-1/

 

例如封裝了一個函式叫TypeKey用於處理各個按鈕的點選:

Function TypeKey(vKey)

       'Use a Select block for special regex characters

       Select Case vKey

              Case "*", "+", "+/-", "."

                     vKey = "/" & vKey

              Case "M+"

                     vKey = "M/+"

       End Select

 

       With Window("nativeclass:=SciCalc", "index:=0")

              .WinButton("text:=" & vKey).Click

       End With

End Function

 

呼叫方法:

TypeKey "1"

TypeKey "*"

TypeKey "2"

TypeKey "+"

TypeKey "3"

TypeKey "="

 

MsgBox CalculatedValue

 

相關文章