Automation Testing, Manual Testing, QTP/UFT 11 , QC/ALM 11 ,SAP TAO, Unix, Selenium, Oracle SQL, Shell Scripting and For Online Trinings to contact me : Cell:+91-8897972059 , Email Id : quicktestprotech@gmail.com

Sunday, November 14, 2010

Ways to send keyboard input to an application using QTP when it does not record using normal recording

There are occasions when keyboard inputs are not recorded or replayed successfully using the normal recording methods of QTP. Also many applications depend on keyboard events to trigger the opening of a window/pop-up window or displaying an edit field. To send keyboard inputs to an application using QTP we have many ways. I suggest using them in the order in which they appear below. (I prefer using co-ordinates recording as the last option in QTP.

1. Use the simplest .Type ( key ) to send keyboard input. 
Eg: Window("Notepad").WinEditor("Edit").Type micF5

2. Use the Windows Scripting SendKeys method
There are some Web/Windows objects which will perform actions when certain key commands, such as CTRL+SHIFT+ESC are entered. These Web/Windows objects do not have a type method associated with them that can be used to replay these keys. In these cases you can use SendKeys method to send keyboard input to your application.
Download and install the Windows Scripting Host.
1. Create a WScript.Shell object.
2. Activate the browser in which you want to execute the keys.
3. Use the SendKeys method to type the key combination. 
Example:
' This code executes the CTRL+F key combination (search) on a browser.
Set WshShell = CreateObject("WScript.Shell")
WshShell.AppActivate "Put the label of the browser" ' Activate the browser window
wait(3)
WshShell.SendKeys "^f" ' The caret (^) represents the CTRL key.
wait(2) 
The SendKeys method will send keystroke(s) to the active window. To send a single character (for example, x), use "x" as the string argument. To send multiple characters (for example, abc), use "abc" as the string argument. You can also send special characters such as SHIFT, CTRL, and ALT, which are represented by the plus sign (+), the caret (^), and the percent sign (%), respectively. 
For more information on the SendKeys method, please refer to the MSDN SendKeys Method page.
  
3. Use Analog or low-level recording when entering keyboard input 

4. Use Mercury Device Replay feature 
The Device Replay feature is used to perform mouse and keyboard actions against screen co-ordinates that are provided. The Device Replay functions are not automatically recorded, but must be programmed manually in the Expert View. (I refrain from using this feature generally)

The steps involved are: 
1.    Creating the Device Replay Object. 
2.    Calling the Device Replay function.  
3.    Destroying Device Replay object.

Here is an example to simulate F5 function key using DeviceReplay. 
Set obj = CreateObject("Mercury.DeviceReplay")
Window("Notepad").Activate
obj.PressKey 63Note:
The PressKey method uses the appropriate ASCII or IBM Scan Code value for the key. "63" is the IBM Scan Code value for F5.
For more information on ASCII and IBM Scan Codes, refer to Lookup Tables. For the ASCII characters, click the "ASCII Table" tab at the top of the page. For IBM Scan Codes, click the "Scan Codes & EBCDIC" tab. The value needed for the PressKey method is the decimal value.

Reference: QTP Documentation

0 comments:

Post a Comment

Loading...