How to use Print Statement or Print log functionality in UFT QTP ?

Print statement and log in UFT QTP

We know about Msgbox() that prints the user messages to a dialogue box. Whereas, Print statement outputs to a pane. In this post we will know how to use Print statement in UFT/QTP.Print Statement displays information in the Output pane during the run session. The Output pane remains open while the run session continues, until you close it.

Syntax :

Print ("Message") or Print (Variable)

Message – The string is displayed as entered in the braces. String is always entered in quotes.

Variable – The data of the variable is displayed as output.

Example 1 :

Print("welcome to testnbug.com")

Example 2 :


name = inputbox("please enter your name")
print name

Example 3:

To print list of all available flights in the FLIGHT RESERVATION application. Before execution we need to add the objects to repository. how to add objects ? refer post “Adding objects

Set FlightsList = Window("Flight Reservation").Dialog("Flights Table").WinList("From")

For i = 1 to FlightsList.GetItemsCount

Print FlightsList.GetItem(i - 1)

Next

Print statement in UFT QTP

How to view Print log in UFT QTP

By now, you might have executed the print statement and could not find the Print log displayed. So, how do you configure or view the print log window.

Its listed under View/Output or Ctrl + Alt + U . On selection output pane is displayed either at the bottom or to the right side.

How to separate Print log as separate window:

Using output pane options which are available at the top right corner (down arrow) .’Float’ is used to separate the output log window.

Print log options in UFT QTP

The print log is very useful when you have too many lines to be printed, we use it all time wherever applicable. The message box requires user input to proceed further.whereas, print will show you the output of run sessions.

  • The Mac

    How can you redirect the print statement to go to the system console instead of the qtp gui log?
    we would need this to show current run progress while running on jenkins slaves.