Interview Questions

How to Create a Test Using Winrunner (3)

Introduction To WinRunner Basics


(Continued from previous question...)

How to Create a Test Using Winrunner (3)


Bitmap Checkpoint for Screen Area

To create a Bitmap Checkpoint for Screen Area
Choose Insert>:Bitmap Checkpoint >:For Screen Area.

The WinRunner window is minimized, the mouse pointer becomes a crosshairs pointer Mark the area to be captured: press the left mouse button and drag the mouse pointer until a rectangle encloses the area; then release the mouse button.

Press the right mouse button to complete the operation.
WinRunner captures the area and generates a win_check_bitmap statement in the script.

The win_check_bitmap statement for an area of the screen has the following syntax:

win_check_bitmap (window, bitmap, time, x, y, width, height);

x, y For an area bitmap: the coordinates or the upper-left corner, relative to the window in which the selected area is located. width, height For an area bitmap: the size of the selected area, in pixels.

When area of the window is captured, the additional parameters i.e. x, y, width and height define the area's location and dimensions.

The analog version of win_check_bitmap is check_window. Syntax is as follows

check_window (time, bitmap, window, width, height, x, y [, relx1, rely1, relx2, rely2]);

time - Indicates the interval between the previous input event and the bitmap capture, in seconds. This interval is added to the timeout_msec testing option. The sum is the interval between the previous event and the bitmap capture, in seconds.
bitmap - A string identifying the captured bitmap. The string length is limited to 6 characters.
window - A string indicating the name in the window banner.
width, height - The size of the window, in pixels.

x, y - The position of the upper left corner of the window (relative to the screen). In the case of an MDI child window, the position is relative to the parent window.
relx1, rely1 For an area bitmap: the coordinates of the upper left corner of the rectangle, relative to the upper left corner of the client window (the x and y parameters).
relx2, rely2 For an area bitmap: the coordinates of the lower right corner of the rectangle, relative to the lower right corner of the client window (the x and y parameters).

The check_window function captures a bitmap of a window. During recording, the specified bitmap is captured and stored. During a test run, the current bitmap is compared to the bitmap stored in the database, and if it is different, the actual bitmap is captured.

Text checkpoints
Text checkpoints read text in GUI objects and in bitmaps and enable user to verify the contents. When creating a text check point for an object or a window containing text. WinRunner reads the text and writes a TSL statement to the test script. Using simple programming the user can use the text content.

User can use a text checkpoint to:
1. Read text from a GUI object or window in the application, using obj_get_text or win_get_text. The maximum number of characters that can be captured in one obj_get_text statement is 2048.

obj_get_text (object, out_text [, x1, y1, x2, y2]);

object The logical name or description of the GUI object. The object may belong to any class.
out_text The name of the output variable that stores the captured text.
x1,y1,x2,y2 An optional parameter that defines the location from which text will be read, relative to the specified object. The pairs of coordinates can designate any two diagonally opposite corners of a rectangle.


2. Search for text in an object or window, using obj_find_text or win_find_text returns the location of a string within an object.
obj_find_text (object, string, result_array [, search_area [, string_def]]);
object The logical name or description of the object. The object may belong to any class.

string A valid string expression or the name of a string variable, which can include a regular expression. The regular expression should not include an exclamation mark (!), however, which is treated as a literal character.
result_array The name of the four-element array that stores the location of the string. The elements are numbered 1 to 4. Elements 1 and 2 store the x- and y- coordinates of the upper left corner of the enclosing rectangle; elements 3 and 4 store the coordinates for the lower right corner.

search_area Indicates the area of the screen to search as coordinates that define any two diagonal corners of a rectangle, expressed as a pair of x,y coordinates. The coordinates are stored in result_array.

string_def Defines the type of search to perform. If no value is specified (0 or FALSE, the default), the search is for a single, complete word only. When 1, or TRUE, is specified, the search is not restricted to a single, complete word. Any regular expression used in the string must not contain blank spaces, and only the default value of string_def, FALSE, is in effect.


3. Compares two strings using compare_text (str1, str2 [, chars1, chars2]);
str1, str2 the two strings to be compared.
chars1 One or more characters in the first string that should be considered equivalent to the character(s) specified in chars2.
chars2 One or more characters in the second string. that should be considered equivalent to the character(s) specified in chars1.

The compare_text function compares two strings, ignoring any differences specified. The two optional parameters are used to indicate characters that should be considered equivalent during the comparison. For instance, if the user specify "m" and "n", the words "any" and "amy" will be considered a match. The two optional parameters must be of the same length. Note that blank spaces are ignored.

WinRunner can read the visible text from the screen in most applications. If the Text Recognition mechanism is set to driver based recognition, this process is automatic. However, if the Text Recognition Mechanism is set to image-based recognition, WinRunner must first learn the fonts used by the application. When using the WinRunner text-recognition mechanism for Windows-based applications, keep in mind that it may occasionally retrieve unwanted text information (such as hidden text and shadowed text, which appears as multiple copies of the same string). The text recognition may behave differently in different run sessions depending on the operating system version, service packs, other installed toolkits, the APIs used, and so on. Therefore, when possible, it is highly recommended to retrieve or check text from application window by inserting a standard GUI checkpoint and selecting to check the object ís value (or similar)property.

When reading text with a learned font, WinRunner reads a single line of text only. If the captured text exceeds one line, only the leftmost line is read. If two or more lines have the same left margin, then the bottom line is read.

Database Checkpoint

Default Check on a Database
To create default check on a database using ODBC or Microsoft Query:
Choose Insert >Database Checkpoint >Default Check
If Microsoft Query is installed and user is creating a new query, an instruction screen opens for creating a query. If Microsoft Query is not installed, the Database Checkpoint wizard opens to a screen where the user can define the ODBC query manually.
Define a query, copy a query, or specify an SQL statement.

WinRunner takes several seconds to capture the database query and restore the WinRunner window. WinRunner captures the data specified by the query and stores it in the testís exp folder. WinRunner creates the msqr*.sql query file and stores the query and the database checklist is stored in the testís chklist folder.

A database checkpoint is inserted in the test script as a db_check statement.
Syntax:-
db_check (checklist, expected_results_file [, max_rows [, parameter_array]]);

checklist The name of the checklist specifying the checks to perform.
expected_results_file The name of the file storing the expected database data.
max_rows The maximum number of rows retrieved in a database. If no maximum is specified, then by default the number of rows is not limited.
parameter_array The array of parameters for the SQL statement.

The db_check function captures and compares information about a database. During a test run, WinRunner checks the query of the database with the checks specified in the checklist. WinRunner then checks the information obtained during the test run against the expected results contained in the expected_results_file.
Note:-when using Create > Database Checkpoint command to create a database checkpoint, only the first two (obligatory) parameters are included in the db_check statement (unless the user parameterize the SQL statement from within Microsoft Query). If the user changes this parameter in a db_check statement recorded in test script, user must run the test in Update mode before running it in Verify mode. SQL queries used with db_check are limited to 4Kb in length.

(Continued on next question...)

Other Interview Questions