R. E. Cook
Home 
Contact Us 

Dr. Cook
Resume 

RunningShoes Library for WinRunner 
RunningShoes 

Custom WinRunner Functions 
and Utilities,
to Your Specs
Custom 

A Random Collection of WinRunner Solutions
Solutions 

Creating DLLs for WinRunner 
"DLLs Demystified" 
(Mercury Interactive's Worldwide Users Conference 2000)

Send a Windows Message requesting the text.

 

Often WinRunner's obj_get_text() statement retrieves garbage, or no text at all. Sometimes it is possible to capture the text using the Windows API to send a Windows message that, in effect, says "Tell me what text you are displaying." The process does not depend on font recognition.

The SendMessageString() function is declared in the WinRunner module "win32api" which is in WinRunner's lib folder. That function sends the request to the object whose text we want.

(WinRunner's lib folder is usually in the search path:
C:\Program Files\Mercury Interactive\WinRunner\lib)

The process is defined as a function following the explanation below.


The process in essence

Load the win32api module.
Set the window.
Get the object's handle.
Send a message requesting the text to the object with that handle.
Unload the module when finished.


How to do it in TSL


## Load the windows API module
api_module = "win32api";
rc = load(api_module , 0, 1);

## Define the message constant.
const WM_GETTEXT = 13;

## Define the maximum number of characters to retrieve.
## (Set for your needs.)
const MAX_CHARS = 256; 

## Define variables with logical names from your GUI map.
## DO THIS!
window = ""; 
object = ""; 

## Make the window active.
set_window(window);

## Get the object's handle in the variable hWnd.
rc = obj_get_info(object, "handle", hWnd);

## Send message requesting the text.
## Text is retrieved into the output variable.
rc = SendMessageString(hWnd, WM_GETTEXT , MAX_CHARS, output);

## Unload the module.
unload(api_module );


The process as a function

Define the function in a compiled module. Load the module as you would any other compiled module.


#### Calling the function.

## Define variables with logical names from your GUI map.
window = "Untitled - Notepad"; 
object = "Edit"; 

## Make the window active.
rc = set_window(window);

## Request the text.
rc = ObjGetTextWM(object, text);

## Display text if successful.
if(rc > 0)
    pause(text);



Top of  This Page | R. E. Cook Home Page

Copyright R. E. Cook Consulting, 2000 - 2011.
All rights reserved.

The site is designed to look best when viewed with Internet Explorer 5.0 - 8.0. Results with other browsers will probably deviate from what is intended.

NOTE: This website refers to registered trademarks and service marks that are owned by other companies, including Mercury Interactive, WinRunner, TestDirector, TSL, Microsoft, Windows.