Winrunner Howto

Create GUI file

There are several options:
  1. The easiest way is recording of operations — press record button (or F2) and do what you want (stop recording with Stop button or Ctrl+F3). Each of processed window and element will be recorded in temporary GUI file automatically. 2. You can discover GUI elements using with Tools-GUI map editor...-Learn — point to necessary window -(Yes), but then you will get all objects, most of which aren't necessary. 3. You can discover individual element using GUI spy. In WR main window select: Tools-GUI spy... (or in GUI map editor: Tools-GUI spy...)- Spy- select necessary object- Copy. Then add object in GUI file and paste its description.
By default WR opens temporary GUI file (see options under Tools-General Options-General (for WR 7.6)) where are objects are stored. You need to move them save in some persistent file. Also, by default WR doesn't show GUI files but 'GUI maps' what is not convenient. Select View-GUI Files for GUI map editor, and Expand>> button to see clearly how it looks.

Handle custom table

If you are not able to recognize table, then you have following options:
  1. Hack GUI map configuration using Tools-GUI Map Configuration, to teach WR that this generic Delphi object is a table (something similar to my set_GUI_map_configuration()). 2. If 1. don't work, but text from obj_get_text() is delimited — develop your custom function which extract necessary part from table.

Date operations howto

WinRunner lacks some important date functions such as datediff(), day(), hour(), month(), and lacks different date formats. However using its built in functions time_str(), date_string_to_Julian(), there is possibility to get all other features. Here are examples of getting necessary date operations using WR custom date functions:

Get current time in predefined format:now=date_from_WRtime('YYMMDDHHNN');
Get date shift (e.g. previous month) from current date:shifted_date=date_from_WRsecs('mm/dd/YY',date_diff('m',-1));
Get shifted date from another formatted date:shifted_date=date_shift(input_date,'DD/MM/YYYY HH:NN:SS',10,'D');
Get current weekday:weekday=date_from_WRtime('ddd');

Simple test example

If you are confused with ABC_Functions file, see following Simple_example.zip with compiled module for common functions and simple script invocation schema.

Make screenshot

Emulate PrtScr event using type("");

and then open paintbrush and paste it there. See screen_shoot function.

Get hostname or IP address

I didn't find OS related functions for WR more than GUI_get_name() and get_lang(). As a workaround to get system info (e.g. IP properties) invoke system command, store this info in file. Then process file and variable with string functions, to get necessary info. See example script_get_system_settings

Kill the processes like notepad or any other application

Application can be nicely killed (including WR itself, if necessary ;-)) using Taskmanager. Kill_Application.zip script shows simple example. More integrated approach is used in custom win_restore function.

Handle DHTML/Javasript pages

In case if web application doesn't catch value submits in DHTML/Javascript pages, probably exact submit of onchange event could help. Following codelines show main operations:

web_set_run_event_mode(TRUE); # Necessary to allow web_event(object,"event"); function for DHTML handling edit_set(object,"Text"); # set value for e.g. editbox web_event(object,"change"); # send onchange event to browser

If it doesn't help, use graphical (analog) WR functions as it is shown in Analog Functions.

Handle several sheets in Excel file

Easy and fast way to get access to multiple sheets in *.xls file is using of additional DLL. See Problem ID: 11861 at http://kb-web.mercury.com/Index/KBquery.asp'>Mercury WinRunner Knowledge Base. But it has some drawbacks. Slower but more correct way is to use ODBC data source connection to the Excel file, and then working with sheets as database tables. See sample script Excel_Sheets.zip.

Get text from application in different ways

Usually text can be got using some application object property (such function as edit_get_text() or obj_get_info() do that). If it is not possible, text can be also extracted using OCR. script_get_text script shows these two approaches.

Read a particular line from the Excel file using ddt_... functions

WR has several ddt_.. functions for work with Excel file. They are designed by assumption that Excel file is organized as a database, where the first row contains table column/field names (named as "parameters" in ddt_ functions), and exact value can be get by passing column name ("parameter") and row number. Therefore for easier life Excel tables should be managed in such way, if possible. If Values for the first row are unique, then values from passed row, can be get by following script_get_xls_line.

Use generator_add.. functions

generator_add_... functions customize dynamically Function generator. It is available through F7 functional button, it also auto-completes function names in code and shows function parameters in tool tip. Run following code lines – they will modify function generator:

generator_add_category("My Category"); generator_add_function_to_category("My Category","my_set_window"); generator_add_function("my_set_window","This function uses set_window() with additional checks and warnings",2, "window_name","point_window","","timeout","type_edit",""); generator_add_function_to_category("My Category","my_set_window");

Then press F7 and select Category: My Category, Function name: my_set_window click Args>>, click on some window, and press Paste, Close. You'll see in script recorded line, something like this:
my_set_window("Google","");

Also you can type my_set_window( and after bracket you will see tool tip with function parameter names. Note that code should be always executed when WR is opened (therefore can't be stored with function definition). Because Function generator doesn't care about actual function parameters and implementation, synchronization between generator and actual function parameters is user responsibility. Use function_generator.vbs script to generate necessary WR commands for Function generator customization. Then paste generated commands into some function (e.g. update_generator()) and invoke this function. As Function generator shows only parameter names, use Ctrl+F8 to step into invoked function and see its parameter type and meaning.

Read long lines from the file

Simple approach is using file_getline(filname,line); function which reads 2048 characters from file in the loop, while line is not empty. However, if line is longer than 32736 characters, WR breaks with "..WinRunnerlibwr_gen (670): Error: The string is too long line = line & tmp_line;" error. In such case exact invocation of utility function _file_getline(file_name,res); allows custom error handling. See attached Read_long_string_from_file.zip script.

Invoke a DLL function

WR allows to invoke external functions from the loaded DLLs. Original implementation design is taken from http://www.wilsonmar.com/1wrfuncs.htm'> http://www.wilsonmar.com/1wrfuncs.htm (csolib*.zip files and descriptions) and simplified example is stored as Invoke_dll.zip.

Use Call Chain window

Call chain window can be opened by View-Debug Toolbar, Debug-Call Chain. It shows something only when structured script with custom function is invoked.

Try

function a1(in param1) { printf "into a1"; a2(param1); printf "out of a1"; } function a2(in param2) { printf "into a2"; printf param2; printf "out of a2"; }

a1("aaa");

and go through it step-by-step with F6.

Print string in the new line

WR uses DOS style for new line coding, thus carriage return "r" should be added before new line character "n", e.g.

printf("arnbrncrnd");

See e.g. file_append() function.
Tags English Testing
Created by Administrator on 2008-11-23 10:29
Last modified by Administrator on 2021-04-13 14:29
 
Xwiki Powered
Creative Commons Attribution 3.0 Unported License