QTP測試QQ登入介面

TIB發表於2010-03-15

GUI測試過程中,通常會碰到物件無法被測試工具識別的問題,這時候往往需要特殊的解決辦法,其中一種方法就是通過傳送鍵盤按鍵的方式來操縱控制元件。

 

下面以QQ2009正式版為例,介紹使用TypeMercury.DeviceReplay物件處理控制元件的方法。

 

以下是錄製的指令碼:

Window("QQ2009 正式版").Activate

Window("QQ2009 正式版").WinObject("123456").Click 46,11

Window("QQ2009 正式版").WinObject("123456").Type "123456"

Window("QQ安全中心").Activate

Window("QQ安全中心").Click 369,302

 

可以看到密碼輸入的步驟沒有錄製下來,按下登入按鈕的步驟也沒有錄製下來。在物件庫手工新增物件後再錄製,仍然沒有把密碼輸入的步驟錄製下來,因此需要手工新增這一步的指令碼(另外在物件庫中也不能手工地把登入按鈕物件新增進去)。調整指令碼如下:

Window("QQ2009 正式版").Activate

Window("QQ2009 正式版").WinObject("123456").Click 46,11

Window("QQ2009 正式版").WinObject("123456").Type "123456"

Window("QQ2009 正式版").WinEdit("Edit").Type "123456"

' 5TAB鍵後聚焦在“登入”按鈕上面

For I=1 to 5

       Window("QQ2009 正式版").Type micTab

Next

Window("QQ2009 正式版").Type micReturn     ' 按Enter鍵模擬使用者點選“登入”按鈕

 

在這裡使用了Window測試物件的Type方法來模擬按鍵,Type方法接受一個按鍵常量作為輸入引數

 

登入如果失敗會出現“QQ安全中心”介面,在這個介面中“取消按鈕”也沒有被識別出來,因此需要採用相同的辦法來處理:

If Window("QQ安全中心").Exist(10) Then ' 密碼輸入不正確

       Window("QQ安全中心").Activate

       Window("QQ安全中心").Type micTab

       Window("QQ安全中心").Type micReturn

End If

 

 

 

 當然,這裡也可以使用DeviceReplay物件來模擬按鍵。

附Type方法的按鍵常量:

 

Constant

Action

micCtrlDwn

Presses the Ctrl key.

micCtrlUp

Releases the Ctrl key.

micLCtrlDwn

Presses the left Ctrl key.

micLCtrlUp

Releases the left Ctrl key.

micRCtrlDwn

Presses the right Ctrl key.

micRCtrlUp

Releases the right Ctrl key.

micAltDwn

Presses the Alt key.

micAltUp

Releases the Alt key.

micLAltDwn

Presses the left Alt key.

micLAltUp

Releases the left Alt key.

micRAltDwn

Presses the right Alt key.

micRAltUp

Releases the right Alt key.

micShiftDwn

Presses the Shift key.

micShiftUp

Releases the Shift key.

micLShiftDwn

Presses the left Shift key.

micLShiftUp

Releases the left Shift key.

micRShiftDwn

Presses the right Shift key.

micRShiftUp

Releases the right Shift key.

micIns

Presses the Insert key.

micDel

Presses the Delete key.

micHome

Presses the Home key.

micEnd

Presses the End key.

micPgUp

Presses the Page Up key.

micPgDwn

Presses the Page Down key.

micUp

Presses the Up arrow key.

micDwn

Presses the Down arrow key.

micLeft

Presses the Left arrow key.

micRight

Presses the Right arrow key.

micEsc

Presses the Esc key.

micBack

Presses the Backspace key.

micReturn

Presses the Return key.

micTab

Presses the Tab key.

micBreak

Presses the Break key.

micPause

Presses the Pause key.

micPrintScr

Presses the Print Screen key.

micWinLogoDwn

Presses the Windows Logo key.

micWinLogoUp

Releases the Windows Logo key.

micLWinLogoDwn

Presses the left Windows Logo key.

micLWinLogoUp

Releases the left Windows Logo key.

micRWinLogoDwn

Presses the right Windows Logo key.

micRWinLogoUp

Releases the right Windows Logo key.

micAppKey

Presses the Application key.

micF1

Presses the F1 key.

micF2

Presses the F2 key.

micF3

Presses the F3 key.

micF4

Presses the F4 key.

micF5

Presses the F5 key.

micF6

Presses the F6 key.

micF7

Presses the F7 key.

micF8

Presses the F8 key.

micF9

Presses the F9 key.

micF10

Presses the F10 key.

micF11

Presses the F11 key.

micF12

Presses the F12 key.

micNumLockOn

Turns on the Num Lock.

micCapsLockOn

Turns on the Caps Lock.

micScrollOn

Turns on the Scroll Lock.

micNumLockOff

Turns off the Num Lock.

micCapsLockOff

Turns off the Caps Lock.

micScrollOff

Turns off the Scroll Lock.

 

 

 

 

 

 

相關文章