Академический Документы
Профессиональный Документы
Культура Документы
4) executes the query based on the SQL statement and creates a record set.
db_execute_query ( session_name, SQL, record_number );
session_name The logical name of the database session.
SQL The SQL statement.
record_number An out parameter returning the number of records in the result query.
The db_execute_query function executes the query based on the SQL statement and
creates a record set.
In the following example, WinRunner executes the query based on the "SELECT *
FROM Orders" SQL statement and creates the record set, which has record_number
records.
db_execute_query ("query1","SELECT * FROM Orders",record_number);
1
db_get_field_value ( session_name, row_index, column );
session_name The logical name of the database session.
row_index The index of the row written as a string: "# followed by the numeric index.
(The first row is always numbered "#0".)
column Either the name of the field in the column, or the index of the column
within the database written as a string: "# followed by the numeric index. (The first
column is always numbered "#0".)
The db_get_field_value function returns the value of a single field in the specified
row_index and column in the session_name database session.
In case of an error, an empty string will be returned.
In each of the following examples, WinRunner returns the value of a single field in the
"query1" database session.
val = db_get_field_value ("query1","#1","#1");
val = db_get_field_value ("query1","#1","Customer_Name");
6) returns the number of column headers in a query and the content of the column
headers, concatenated and delimited by tabs.
db_get_headers ( session_name, header_count, header_content );
In the following example, WinRunner returns the number of column headers in the
"query1" database session and all the strings in all column headers, concatenated and
delimited by tabs.
db_get_headers ("query1",field_num,headers);
split (headers, header_arr, "\t");
8) compares information that appears in the application under test during a test run with
the current values in the corresponding record(s) in your database.
db_record_check ( ChecklistFileName , SuccessConditions, RecordNumber );
ChecklistFileName A file created by WinRunner and saved in the test's checklist
folder. The file contains information about the data to be captured during the test run and
its corresponding field in the database. The file is created based on the information
entered in the Runtime Record Checkpoint wizard.
SuccessConditions Contains one of the following values:
2
The db_record_check function compares information that appears in the application
under test during a test run with the current values in the corresponding record(s) in your
database.
In the following example, db_record_check creates a runtime database record checkpoint.
"list_1.cvr" is the name assigned to the checklist captured for the test script;
"DVR_ONE_MATCH" indicates that the checkpoint will pass if one, and only one,
matching database record is found.
db_record_check("list1.cvr", DVR_ONE_MATCH, record_num);
USING DDT IN WR
1) creates or opens a data table file so that WinRunner can access it.
ddt_open ( data_table_name [ , mode ] );
data_table_name The name of the data table. The name may be the table variable
name, the Microsoft Excel file or a tabbed text file name, or the full path and file name of
the table.The first row in the file contains the names of the parameters. This row is
labeled row 0.
mode The mode for opening the data table: DDT_MODE_READ (read-only) or
DDT_MODE_READWRITE (read or write). When the mode is not specified, the default
mode is DDT_MODE_READ.
The ddt_open function opens the data table file with the specified data_table_name. The
active row becomes row number 1.
3) ddt_close_all_tables();
The ddt_close_all_tables function closes all open tables in all open tests. Note that this
includes any tables that are open in the table editor, tables that were opened using the
ddt_open or ddt_show functions or/and using the DataDriven Tests Wizard.
In the following example, Test2 begins with the ddt_close_all_tests
function in order to close any open tables from any other open tests.
Test1:
# Open table1. ddt_open(table1);
# Open table2. ddt_open(table2);
# Open table3. ddt_open(table3);
Test2:
# Open table4. ddt_open(table4);
#Close all open tables (from both Test1 and Test2)
ddt_close_all_tests();
3
In the following example, WinRunner exports the information from the Excel file entitled
"Default" to the Excel file entitled "flight".
ddt_export ( "C:\\mercury\\tmp\\merc1\\Default.xls" , "
C:\\mercury\\tmp\\merc1\\flight.xls" );
4
rc = ddt_open(table);
if (rc!=E_OK)
pause("ERROR");
# Get the table parameters.
ddt_get_parameters(table,params_list,params_num);
ddt_close(table);
5
# Open the table.
rc = ddt_open(table);
if (rc!=E_OK)
pause("ERROR");
do
{
# Reports the active row to the test results.
rc=ddt_report_row(table);
if (rc!=E_OK)
pause("ERROR");
}
# Go to the next row.
while (ddt_next_row(table)==E_OK);
ddt_close(table);
Note: You can only use this function if the data table was opened in
DDT_MODE_READWRITE (read or write mode).
In the following example, WinRunner inserts the name "Klein" into the "new" column in
the row which is currently in use.
ddt_set_val ( "C:\\mercury\\tmp\\merc1\\flight.xls","new","Klein" );
6
EXCEPTION HANDLING IN WR
7
To enable handling of the exception from a test script, you must use the exception_on
function.
8
6) disables handling of all exceptions.
exception_off_all ( );
The exception_off_all function disables all previously activated exceptions.
The following example shows a handler function of some exception. This handler
function turns off all exception handling before closing the AUT.
public function capture_handler (in rc, in func)
{
# turn of all exceptions
exception_off_all() ;
# Write a message to the report and close the application.
report_msg("Capture failed. Closing the application.");
menu_select_item("File;Exit");
texit;
}
DOS COMMANDS IN WR
USING FILES IN WR
9
Note that if the file does not exist in the specified path, then if the file mode is
FO_MODE_WRITES, WinRunner creates the file. If the specified path does not exist,
the file is not created and the command fails.
In the following example, the contents of readme.txt are printed to readme2.txt. The
file_open function opens readme.txt in read only mode and readme2.txt in write only
mode.
file_open("C:\\readme.txt",FO_MODE_READ);
file_open("C:\\readme2.txt",FO_MODE_WRITE);
i=0;
while(file_getline("C:\\readme.txt",line)==0)
{
i++;
file_printf("C:\\readme2.txt","%d "&toupper(line),i);
}
file_close("C:\\readme.txt");
file_close("C:\\readme2.txt");
10
system("notepad.exe win.ini");
set_window("Notepad",1);
# Save win.ini as win1.ini
menu_select_item("File;Save As...");
set_window("Save As");
edit_set("File Name:_0","c:\win31\win1.ini");
set_window("Save As", 1);
button_press("OK");
# Compare win.ini to win1.ini and save both files to "save".
file_compare("c:\\win31\\win.ini","c:\\win31\\win1.ini","save");
USING PASSWORD IN WR
11
1) encrypts a plain password.
password_encrypt ( password );
password The plain password.
You use the password_encrypt function when you import a password from an external
database after having used the password edit set function and you want to encrypt that
particular password. Alternatively, you can use the edit_set function to set the edit field's
value with the plain password string.
In the following example, the user imports a password from a data table and encrypts the
password using the password_encrypt function.
plain_pw = ddt_val ( table, "password");
encrypted_pw = password_encrypt (plain_pw);
INVOKE_APPLICATION IN WR
12
SW_SHOWMINIMIZED Activates the window and displays it as an icon.
SW_SHOWMINNOACTIVE Displays the window as an icon. The window that is
currently active remains active.
SW_SHOWNA Displays the window in its current state. The currently active
window remains active.
SW_SHOWNOACTIVATE Displays the window in its most recent size and position.
The currently active window remains active.
SW_SHOWNORMAL Activates and displays the window. If the window is
minimized or maximized, WinRunner restores it to its original size and position (same as
SW_SHOWRESTORE).
The invoke_application command runs a Windows executable (*.exe file). Test execution
is paused while the operating system command is executed.
Use dos_system to execute DOS system commands.
In the following example, the test invokes the Notepad text editor. If the test is unable to
invoke the application, a message is sent to the report.
if (invoke_application("notepad","","C:\\TEXT",SW_SHOWMINIMIZED)!=0)
{
report_msg("AUT is not found. exiting.");
texit;
}
else call batch_test();
CUSTOMIZATION FUNCTIONS IN WR
Customization functions allow you to enhance your testing tool so that it better supports
your specific needs. For example, you can add functions to the Function Generator, or
create custom GUI checkpoints.
login The label of the first edit box, used for user-name input. If you specify an empty
string (empty quotation marks), the default label "Login" is displayed.
password The label of the second edit box, used for password input. If you specify
an empty string (empty quotation marks), the default label "Password" is displayed.
When the user enters input into this edit box, the characters do not appear on the screen,
but are represented by asterisks.
login_out The name of the parameter to which the contents of the first edit box
(login) are passed. Use this parameter to verify the contents of the login edit box.
password_out The name of the parameter to which the contents of the second edit box
(password) are passed. Use this parameter to verify the contents of the password edit box.
13
encrypt_password A Boolean parameter which allows the output edit field value to be
encrypted. If this parameter is left blank, the default value is FALSE.
The create_password_dialog creates a dialog box with two edit boxes, one for login name
input, and one for password input. You use a password dialog box to limit user access to
tests or parts of tests. A password dialog box has two edit boxes, an OK button, and a
Cancel button. You supply the labels for the edit boxes. The text that the user types into
the edit boxes during interactive test execution is returned for analysis. For details on
creating a user interface to pass input to your test during interactive test execution, refer
to the "Creating Dialog Boxes for Interactive Input" chapter in your WinRunner User's
Guide.
Note: You cannot use this function in a test you run in batch mode or in silent mode,
because no one is monitoring the computer where the test is running to view the
messages.
In the following example, a password dialog box is created using the default edit box
labels. If you click the OK button, the value 1 is passed to the status variable and the
entered text is passed to the user_name and password variables. If you click the Cancel
button, the value 0 is passed to the status variable and the login_out and password_out
parameters are assigned empty strings.
Increase power and flexibility of tests without any programming: The Function
Generator presents a quick and error-free way to design tests and enhance scripts without
any programming knowledge. Testers can simply point at a GUI object, and Mercury
WinRunner® will examine it, determine its class and suggest an appropriate function to
be used.
14
View, store, and verify at a glance every attribute of tested objects: Mercury
WinRunner's GUI Spy automatically identifies, records and displays the properties of
standard GUI objects, ActiveX controls, as well as Java objects and methods. This
ensures that every object in the user interface is recognized by the script and can be
tested.
Maintain tests and build reusable scripts: The GUI map provides a centralized
object repository, allowing testers to verify and modify any tested object. These changes
are then automatically propagated to all appropriate scripts, eliminating the need to build
new scripts each time the application is modified.
Validate applications across browsers: Mercury WinRunner enables you to use the
same test to validate applications in Internet Explorer, Netscape, and AOL. This saves
testing time and reduces the number of scripts that must be developed and maintained.
15
Mercury TestDirector Features and Benefits
Allows teams to access testing assets anytime, anywhere via a browser interface
Allows teams to analyze application readiness at any point in the testing process
with integrated graphs and reports
16