Tricentis Tosca 16.0 Released on Feb-2023 ----- UFT has been upgraded from UFT 15.0.1 to UFT One 15.0.2, Beginning at November 2020.

Wednesday 17 June 2015

Hidden functions in QTP/UFT

There are  four "Hidden functions" in QTP/UFT:
1.       Highlight
2.       TestArgs
3.       Mercury.DeviceReplay
4.       Reporter Method
QTP/UFT’s Highlight Function:

The Highlight function allows you to programmatically highlight an object in your test script. This functionality is identical to what can be seen in the object spy when you click on the highlight in application option.

The undocumented feature is that this can also be done programmatically. 
To see this example in action:
  • Create a new script.
  • Navigate to "http://www.joecolantonio.com"
  • Add the following line of code in your script:
    Browser(“index:=0″).Page(“index:=0″).WebEdit(“name:=MERGE0″).highlight
  • Run the test and you should see the Enter your email here field flicker. Highlight it a few times.

I personally find this method helpful when debugging my running scripts and also to keep track of what field it might be on before a failure.
QTP/UFT’s TestArgs Function

Did you know that you can access your test parameters at run time orprogrammatically? Just looking at the QTP/UFT documentation you would think not, but it is, in fact, possible to read, get, write and set parameter values at run time and programmatically.
Let’s check this out using the Read option:
  • In the canvas, select the Start step.
  • In the Properties pane, open the Parameters tab.
  • Click the Add button and select Add Input
    Parameter.
  • In the Add Input Parameter dialog box, enter the following:
    • Name = WhatsYourName
    • Type = String
    • Default Value = Jimi

  • Click on Action1 and create the same exact Input property and Value.
  • Next, add the following code to your action:
set QTP = CreateObject(“QuickTest.Application”)
msgbox QTP.Test.ParameterDefinitions.GetParameters().Item(“WhatsYourName”).Value
  • Run your test and a message box should appear with the value JIMI.

QTP/UFT’s Mercury.DeviceReplay Function

The Device Replay feature can be used to perform mouse and keyboard actions against screen coordinates that you provide. To access these undocumented functions, you need to programmatically enter them in the Expert View.
there are three types:

1. QTP/UFT’s TYPE METHOD
Most objects support the TYPE method.  Type will enter the specified string into an object or perform a certain keyboard combination against an application.  

For example:
To tab off an object you would use the following syntax:

SwfObject(“swfname:=Blank”).Type micTab

To enter text:
SwfObject(“swfname:=Blank”).Type “This is my string
To send an enter keystroke:
SwfObject(“swfname:=Blank”).Type “ “

we can also send a combination of keystrokes at one time. The following holds down the CTRL and the Shift Keys, then presses the “L” key and releases the CTRL and Shift keys:

SwfObject("swfname:=Blank").Type micCtrlDwn + micShiftDwn + "L" + micShiftUp + micCtrlUp
2. VBScript SendKeys Method.
There are instances in which QTP/UFT’s Type method does not trigger certain events, or is unable to mimic certain keystrokes.  In these cases, VBScript SendKeys method can be used. To use the SendKeys you need to first set the WshShell object:

Dim mySendKeys
set mySendKeys = CreateObject("WScript.shell")
mySendKeys.SendKeys(“{TAB}”)



To send the text you would use:
mySendKeys.SendKeys(“This is my string”)

To send an enter keystroke:
mySendKeys.SendKeys(“~”)
Important tips: Unlike the QTP TYPE method, you will need to use curly braces for arguments like a TAB or Up arrow key strokes. Also — SendKeys has the following special characters:  Alt(%), Ctrl(^), Shift(+) and Enter(~) keys.
So, to send a CTRL and press the A key you would send: 
mySendKeys.SendKeys("^A")
If you need to perform the same keystroke multiple times, you can create a compound string argument. This will allow you to perform a specific keystroke and repeat it any number of times. To select, say, the 10th row in a grid control you might use:

mySendKeys.SendKeys(“{DOWN 10}”)

This will send the down key ten times.

3. Device Replay
This is an undocumented and unsupported QuickTest method, but can be used as a last resort. To employ this method, you’ll need to create a Device Replay object.
To tab off an object:
Dim myDeviceReplay
Set myDeviceReplay = CreateObject("Mercury.DeviceReplay")
myDeviceReplay.PressKey 15
*Remember that Device Replay uses ASCII characters To send text you would use:
myDeviceReplay.SendString “This is my string”

To send an enter keystroke:
myDeviceReplay.PressKey 28 ‘ASCII code for enter
From The HP knowledge base: The functions that can be used with the Device Replay object are (all coordinates are relative to the top left corner of the screen):


Function
Description
MouseMove x, y
Move the mouse to the screen coordinate (x,y).
MouseClick x, y, button
Move the mouse to the screen coordinate (x,y) and click the button
(0=left; 1=middle; 2=right).
MouseDblClick x, y, button
Move the mouse to the screen coordinate (x,y) and double-click the     button
(0=left; 1=middle; 2=right).
DragAndDrop x, y, dropx, dropy, button
Drag the mouse from screen coordinate (x,y) to (dropx,dropy) with the button
(0=left; 1=middle; 2=right) pressed.
PressKey key
Press a key using the ASCII code of the key.
For example, Chr(13), vbCR and vbTab.
MouseDown x, y, button
Press the mouse button on screen coordinate (x,y).
MouseUp x, y, button
Release the mouse button on screen coordinate (x,y).
KeyDown key
Press a key using the ASCII code of the key.
For example, Chr(13), vbCR and vbTab.
KeyUp key
Release a key using the ASCII code of the key.
For example, Chr(13), vbCR and vbTab.
SendString string
Type a string.
QTP/UFT’s Reporter Functions:
This secret method allows you to create custom HTML to your QuickTest and Unified Functional Testing reports. This functionality was common in earlier versions of QTP, but in QTP 11 and above these built-in methods were removed. The bravest of us, however, can still use them even though they are “unsupported” now.
Here is one way to create custom HTML in your reports. This example will embed a link to a website in the report, but you can use this for HTML-like tables, etc.
Enter the following code in the Expert View of your tests:
Set oEventDesc = CreateObject(“Scripting.Dictionary”)
oEventDesc(“ViewType”) = “Sell.Explorer.2″
oEventDesc(“Status”) = micPass
oEventDesc(“EnableFilter”) = False
oEventDesc(“NodeName”) = “My Blog”
oEventDesc(“StepHtmlInfo”) = “<a href=’http://www.testtalks.com’>TestTalks</a>”
newEventContext = Reporter.LogEvent (“Replay”,oEventDesc,Reporter.GetContext)
  • Run your test and look at the HP Run Results Viewer.
  • You should see a TestTalks link under your Result Details section.



Clicking on the TestTalks link should bring up my podcast in the report! 



No comments:

Post a Comment

Note: only a member of this blog may post a comment.