一段Winrunner的样例脚本

#########################################################################################################
#
# Test Name     : Date Boundary
# Subject          : Open Order Form
#
# Description    : Checks that the input of illegal values in the Flight Date is blocked and that error messages
#    appear.  The following input should be tested:
#     1. Flight Date Edit field is disabled when button is unchecked
#     2. Characters (not accepted)
#     3. More than six numbers (not accepted)
#     4. Less than six numbers (OK is disabled)
#     5. Invalid Month
#     6. Invalid date of the month
#     7. No entry
#
#
#########################################################################################################
#static variables:
static ret_val,date_str,i;
# Constant declaration
static const DISABLED = FALSE;
# Variable declaration.  Can be anything the user wants.
static date_string_of_chars  = "as/cd/ef";     # Used in STEP 2.  Characters (Not accepted).
static date_seven_numbers = "12/34/567"; # Used in STEP 3.  More than six numbers not accepted.
static date_invalid_month    = "13/20/95";   # Used in STEP 5.  Invalid month.
static date_invalid_day        = "12/32/95";   # Used in STEP 6.  Invalid date of month.
static lib_path = getvar("testname") & "\\..\\flt_lib";
# Static function reinitialize ().  Reinitializes Flight Date to OFF and clears the edit field.
static function reinitialize ()
{
 auto ret_val;
 set_window ("Open Order");
 obj_get_info ("FlightDateEdit", "enabled", ret_val);
 if (ret_val == TRUE) {
     set_window ("Open Order");
  edit_set_insert_pos ("FlightDateEdit", 0, 0);
  type ("<kS_End_E><kDel_E>");
 }
}
# Static function insert_date ().  Inserts the date into the FlightDateEdit field.
static function insert_date (in date)
{
 set_window ("Open Order");
 edit_set_insert_pos("FlightDateEdit",0,0);
 type(date);
}
reload(lib_path);
# Open the flight application
rc = open_flight();
if (rc == E_GENERAL_ERROR){
  tl_step(initialization, FAIL,couldnt_open_flight);
 clean_up();
 texit;
}
 
# Initialization.
open_OpenOrderForm ();

# STEP 1.  Flight Date Edit is disabled
set_window ("Open Order");
# Checking to see if the edit field is disabled when button is unchecked
obj_get_info ("FlightDateEdit", "enabled", ret_val);
if (ret_val == DISABLED)
 tl_step (disabled, PASS, flight_date_disabled);
else
 tl_step (disabled, FAIL, flight_date_not_disabled);
reinitialize ();

# STEP 2.  Characters (not accepted)
button_set ("Flight Date", ON);
# Inserting a date of characters using variable, "date_string_of_chars", defined above.
insert_date (date_string_of_chars);
edit_get_text ("FlightDateEdit", date_str);
# Checking to see if application handled illegal open order procedure
if (date_str == "__/__/__")
 tl_step (characters, PASS, chars_not_accepted);
else
 tl_step (characters, FAIL, chars_accepted);
reinitialize ();
# STEP 3. More than six numbers (not accepted)
button_set ("Flight Date", ON);
# Inserting a date consisting of more than six numbers using variable, "date_seven_numbers", defined above.
insert_date (date_seven_numbers);
edit_get_text ("FlightDateEdit", date_str);
# Checking to see if application handled illegal open order procedure
if (date_str == "12/34/56")
 tl_step(more_than_six, PASS, more_than_six_not_accepted);
else
 tl_step(more_than_six, FAIL, more_than_six_accepted);
reinitialize ();
# STEP 4. Less than six numbers (OK is disabled)
edit_set_insert_pos ("FlightDateEdit", 0, 0);
# Using for_loop to systematically check if OK button is disabled for any date with less than six numbers in it
for (i = 1; i <= 6; i++) {
 type(i);
 if (button_check_enabled ("OK", TRUE) == E_OK)
  break;
}
#  The actual check to make sure that OK was disabled for date less than six numbers
ts_msg = sprintf(ok_not_disabled, i);
if (i < 6)
 tl_step (less_than_six, FAIL, ts_msg);
else
 tl_step (less_than_six, PASS, ok_disabled);
reinitialize ();
# STEP 5. Invalid Month
set_window ("Open Order");
# Inserting a date with an invalid month using variable, "date_invalid_month", defined above.
insert_date (date_invalid_month);
# Checking to verify that unless there is a valid month, an error message will pop up when trying to press "OK"
set_window("Open Order");
button_press("OK");
if(win_exists("Flight Reservation Message",10) != E_OK){
 tl_step (invalid_month, FAIL, invalid_month_msg_popup);
 clear_main_window();
 open_OpenOrderForm ();
}
else{
 set_window("Flight Reservation Message");
 static_get_text("Message", txt);
 if(txt !=invalid_month_entered_msg)
  tl_step (invalid_month, FAIL, invalid_month_wrong_msg);
 else
  tl_step (invalid_month, PASS, invalid_month_correct_msg);
 button_press("OK");
}
reinitialize ();

# STEP 6.  Invalid day of month.
set_window ("Open Order");
# Inserting a date with an invalid day using variable, "date_invalid_day", defined above.
insert_date (date_invalid_day);
# Checking to verify that unless there is a valid day of the month the "OK" button will be disabled
set_window("Open Order");
button_press("OK");
if(win_exists("Flight Reservation Message",10) != E_OK){
 tl_step (invalid_day, FAIL, invalid_day_no_err_msg);
 clear_main_window();
 open_OpenOrderForm ();
}
else{
 set_window("Flight Reservation Message");
 static_get_text("Message", txt);
 if(txt !=invalid_day_entered_msg)
  tl_step (invalid_day, FAIL, invalid_day_wrong_err_msg);
 else
  tl_step (invalid_day, PASS, invalid_day_not_accepted);
 button_press("OK");
}
reinitialize ();

# STEP 7.  No Entry.
set_window ("Open Order");
# Inserting no date to see if OK is disabled.
insert_date ("__/__/__");
# Checking to see if OK is disabled without any date set in edit field
if (button_check_enabled ("OK", TRUE) != E_OK)
 tl_step (no_entry, PASS, ok_button_disabled);
else
 tl_step (no_entry, FAIL, ok_button_enabled);

# Returning to initial state.
button_press ("Cancel");
clean_up();

# End of test.




本文转自 fish_yy 51CTO博客,原文链接:http://blog.51cto.com/tester2test/138722,如需转载请自行联系原作者
上一篇:C#.NET通用权限管理在DB2数据库上运行的脚本参考 - 通过程序将数据导入到目标数据库中


下一篇:shell脚本函数名不能使用Linux关键字或命令