Reading Text - WinRunner

You can read the entire text contents of any GUI object or window in your application, or the text in a specified area of the screen. You can either retrieve the text to a variable, or you can compare the retrieved text with any value you specify.

To retrieve text to a variable, use the win_get_text, obj_get_text, and get_text functions. These functions can be generated automatically, using a Insert > Get Text command, or manually, by programming. In both cases, the read text is assigned to an output variable.

To read all the text in a GUI object, you choose Insert > Get Text > From Object/Window and click an object with the mouse pointer. To read the text in an area of an object or window, you choose Insert > Get Text > From Screen Area and then use a crosshairs pointer to enclose the text in a rectangle.

In most cases, WinRunner can identify the text on GUI objects automatically. However, if you try to read text and the comment “#no text was found” is inserted into the test script, this means WinRunner was unable to identify your application font. To enable WinRunner to identify text, you must teach WinRunner your application fonts and use the image text recognition mechanism.

To compare the text in a window or object with an expected text value, use the win_check_text or obj_check_text functions.

Reading All the Text in a Window or an Object

You can read all the visible text in a window or other object using win_get_text or obj_get_text.

To read all the visible text in a window or an object:

  1. Choose Insert > Get Text > From Object/Window or click the Get Text from Object/Window button on the User toolbar. Alternatively, if you are recording in Analog mode, press the GET TEXT FROM OBJECT/WINDOW softkey.
  2. WinRunner is minimized, the mouse pointer becomes a pointing hand, and a Help window opens.

  3. Click the window or object. WinRunner captures the text in the object and generates a win_get_text or obj_get_text statement.

In the case of a window, this statement has the following syntax:

win_get_text ( window, text );

The window is the name of the window. The text is an output variable that holds all of the text displayed in the window. To make your script easier to read, this text is inserted into the script as a comment when the function is recorded.

For example, if you choose Insert > Get Text > From Object/Window and click on the Windows Clock application, a statement similar to the following is recorded in your test script:

# Clock settings 10:40:46 AM 8/8/95
win_get_text("Clock", text);

In the case of an object other than a window, the syntax is as follows:

obj_get_text ( object, text );

The parameters of obj_get_text are identical to those of win_get_text.

Reading the Text from an Area of an Object or a Window

The win_get_text and obj_get_text functions can be used to read text from a specified area of a window or other GUI object.

To read the text from an area of a window or an object:

  1. Choose Insert > Get Text > From Screen Area or click the Get Text from Screen Area button on the User toolbar. Alternatively, if you are recording in Analog mode, press the GET TEXT FROM SCREEN AREA softkey.
  2. WinRunner is minimized and the recording of mouse and keyboard input stops. The mouse pointer becomes a crosshairs pointer.

  3. Use the crosshairs pointer to enclose the text to be read within a rectangle. Move the mouse pointer to one corner of the text you want to capture. Press and hold down the left mouse button. Drag the mouse until the rectangle encompasses the entire text, then release the mouse button. Press the right mouse button to capture the string.

You can preview the string before you capture it. Press the right mouse button before you release the left mouse button. (If your mouse has three buttons, release the left mouse button after drawing the rectangle and then press the middle mouse button.) The string appears under the rectangle or in the upper left corner of the screen.

WinRunner generates a win_get_text statement with the following syntax in the test script:

win_get_text ( window, text, x1,y1,x2,y2 );

For example, if you choose Get Text > Area and use the crosshairs to enclose only the date in the Windows Clock application, a statement similar to the following is recorded in your test script:

win_get_text ("Clock", text, 38, 137, 166, 185); # 8/13/95

The window is the name of the window. The text is an output variable that holds all of the captured text. x1,y1,x2,y2 define the location from which to read text, relative to the specified window. When the function is recorded, the captured text is also inserted into the script as a comment.

The comment occupies the same number of lines in the test script as the text being read occupies on the screen. For example, if three lines of text are read, the comment will also be three lines long.

You can also read text from the screen by programming the Analog TSL function get_text into your test script.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

WinRunner Topics