|
Tester Software Testing www.TSLScripting.comHere are my notes on programming WinRunner TSL (Test Script Language) and crafting GUI maps, Want script example Winrunner code? I suggest that you begin with source from Data/Keyword Driven Frameworks Sound: Disapointed “Oh man” by Cheech Marin
| Topics this page:
|
Related Topics: |
GUI Mapping Overview
|
ClassesThis is reorganized from WinRunner User's Guide Part VI - "Working with the GUI Map" - "Configuring the GUI Map" - "Understanding WinRunner Objects Classes". Links are provided to my page detailing specific functions.
|
Learning GUI MapsWinRunner always learns Obligatory properties. What is obligatory can be specified in tools > GUI Map Configuration. After selecting the class (such as "object"), WR also learns optional properties to ensure uniqueness of identification. To differentiate among objects with the same name, WinRunner appends "_1", "_2", etc. These are called spatial location selectors. You can manually edit the gui map to add index selector numbers to control uniqueness among physical descriptions. A large number of items in the gui map can make playback very slow! So only learn the elements that will actually be referenced by scripts. KB 17955 "WinRunner does not have a direct method to learn objects into a GUI Map file from within a script." However, the GUI_add function allows you to add objects to the GUI Map at runtime, if know the physical description of the object before calling the function. The GUI Map will not allow a variable to be used in place of an actual value. However, you can update the GUI Map at runtime or use the object's physical description directly within the function using the GUI_buf_set_desc_attr function, which sets the value of a property for an object in a GUI Map file. See Problem ID 26036 - How to add a property to the physical description of an object in the GUI Map. You can also build the physical description for an object at runtime and use it directly. This option bypasses the GUI Map completely. See KB 4391 - How to use a physical description in place of a logical name. KB 25653 - How to use a physical description in a set_window() function KB 4389 - How to map a custom object to a standard object User-defined custom objects are defined in physical description with class value of simply "object". The "Virtual Object Wizard" from the Tool menu provides cross hairs for a tester to mark the specific coordinates of objects and assign them a logical name. However, be aware that virtual objects must be relearned whenever those objects are moved or resized. |
GUI Map PropertiesThis is reorganized from WinRunner User's Guide Part VI - "Working with the GUI Map" - "Configuring the GUI Map" - "Understanding Object Properties"
|
Actual Results May Vary: Checklists and Checkpoints
TSL code such as the following is used to detect differences: win_check_gui("Login", SHARED_CL & "Login.ckl", "gui2", 1); This code compares expected results in the shared "Login.ckl" checklist file against the "gui2" actual results file. Note that expected results in checklist files have a file extension of .ckl. These files are stored in the "chklist" folder associated with each specific script or in the shared scope folder referenced by several scripts. This folder is designated from Settings, General Options, Folders tab.
To create a checklist fileFirst, click the script editor pointer to a blank line and not in the middle of another statement. This is because when you click "OK" from the "Create GUI Checkpoint" dialog, WinRunner automatically inserts code.Press F12 for the default equivalent to selecting Create, GUI Checkpoint, for Multiple objects. WinRunner automatically comes up with a checklist file named something like "list1.ckl", which you could rename when you save it as something else.
To specify what will be checkedClick the Add button from the "Create GUI Checkpoint" dialog window, left click with your mouse on the object being checked, then right click.On the right pane, WinRunner presents standard properties with default checks automatically checked for you. Check the names of properties you want compared. Remember: Only the properties you check will be stored in the checklist file. The properties you don't check will not be stored in the checklist file.
| Note: The links to documents which used to be here were removed at the request of Mercury Interactive lawyers. I guess they don't want people to know about their software. God forbid that anyone actually can figure out how to use their product. |
New ChecksTo add default checksUse the gui_ver_set_default_checks against existing check names.Note that check names may not contain spaces, since the list of check names specified in this function are separated by spaces.
To add check names not listed(such as "font size"), create a custom capture and comparison function.
To add a check class(such as "pbTool"), create a custom capture and comparison function.
To add expected results to a checklist fileFrom the win_check_gui and obj_check_gui function stores results in an expected results file.
To reference a checklist fileThe default_compare_func function is used for simple comparisons.
| These are Customization Guide "custom.pdf" file. |
Multiple WindowsA Bad ExampleIn WinRunner 7, there is a bug in the identify script in the \samples\general folder under wherever you installed WinRunner (C:\Program Files\Mercury Interactive\WinRunner\)The logic to determining the common label using the Operating System is backward. The Windows NT version of Notepad is initiated with a title of "Untitled - Notepad". The Windows 95 version of Notepad is initiated with a title of "Notepad - (Untitled)". Only the Microsoft Gods know why this difference came about. Getting A Handle On The WindowAnyway, its strategy is to capture the internal handle number (named hWnd) of each window by using the win_get_info() function to obtain a physical description.The gui_add function is then used to associate each handle to a logical name referenced by other WinRunner statements. Minimizing WinRunner ItselfWinRunner can minimize itself by using the Win32API function library to get the internal handle than Windows uses for the active window (hWnd).
load ( "win32api", 1, 1 );
extern int CloseWindow(unsigned int); extern int OpenIcon(unsigned int); hWnd = GetForegroundWindow(); CloseWindow(hWnd); win_activate ("Flight Reservation"); .... # To see WR again: OpenIcon(hWnd); Load and a one and a twoThe load statement above converts the script into "internal form".The first 1 is to designate system module rather than a usermodule. A closed module is "invisible" to the tester. It is not displayed when it is loaded, cannot be stepped into, and is not stopped by a pause command. The second 1 is to close the script rather than leaving it open.
| Read more about GetForegroundWindow() on MSDN. |
Errors and DebuggingError CodesThe most common error codes (you would do well to memorize) are:
Constants such as E_OK have names defined in file hlerr.h which maps to a set of "internal constants" such as "MIC_E_OK" defined with actual values (such as 0) in header file mic.h (so named because MIC is an acronymn for "Mercury Interactive Corporation"). This is referenced in the mic_if.h file, all within the custom\mic_if folder where WinRunner is installed. The short names of error codes are defined there.
WatchTo save space/time selecting variables to watch, use the same private variable names within functions, such as i for iterator, n for element count, etc.
Step ThroughDo not step through right clicks in code lines such as:
menu_select_item ("Rename"); If you do, menu_select_item will not recognize the pop-up menu. Instead, set a stop after the item is selected in menu_select_item and execute "From Arrow" rather than one step at a time (with the default F6 key).
Optional Execution of Scripts
if( my_results_lvl>= 2 )
report_msg("Run done " & time_str() );
The variable my_results_lvl controls how much information is sent to the results table.
1 = Error and warning messages only. 2 = Run environment, count of records in files used, start/end time, plus the above. 3 = Every data table record at each step plus all of the above.
Level of PausingThe variable my_pause_lvl controls how often to pause.
1 = At file level error conditions only. 2 = At each error in the script. 3 = At each data table record read and successfully processed as well as all the above. Sample code:
tl_msg = "Row:"& my_table_Row &" Found:"& text &" Expected:"& my_exp_text &" Agent:"& my_agent_name ;
if( my_pause_lvl>= 3 ) pause( tl_msg );
Print to a windowWinRunner has an undocumented command which prints a string to a separate window. Example:
tl_msg = "Row:"& my_table_Row &" Found:"& text &" Expected:"& my_exp_text &" Agent:"& my_agent_name ;
if( my_pause_lvl>= 3 ) pause( tl_msg ); | C Programming Tutorials Over the InternetSteve Holmes' Classic from GlasgowMarshall Brain's How Stuff Works focuses on common misunderstandings.
|
Sychronization
| . |
Juggling Script Files
Reload places compiled function libraries into memory, ready fur use. There are two ways to compile a function library:
|
Including Files with Dynamically Compiling a DLLUnlike other C programs, WinRunner ignores "#include" compiler directives. I don't know why. But there is a (rather convoluted) way to dynamically supply TSL script code in a separate file — make calls to have WinRunner compile a dll which picks up that script code, then invoke that DLL. | . |
| Your first name: Your family name: Your location (city, country): Your Email address: |
Top of Page
Thank you! |