Sei sulla pagina 1di 23

################################################################################

###########
#Author: gvenka
#Date: 08/03/2001
#Revision History:
#
#Purpose of library: To define functions common to all applications
#
#
#Dependencies:
#
################################################################################
###########
public WR_WIN_TIMEOUT, WR_OBJ_TIMEOUT, WR_DEBUG, WR_PARAM_DELIMITER, WR_ENABLE_E
RRORS;
public g_temp_val, g_temp_arr[], g_rc_array[ ], g_element_desc_array[], g_elemen
t_action_array[];
public g_test_env_array[];
public script_name, qfile_name, client_request_path, unc_client_request_path;
public engine_request_path, test_scripts_path, request_file, testset_file, produ
ct_lib_path;
# These variables are defined to be used for automated installation process
public build_product_name, build_path, windows_cmd_file_name, unix_cmd_file_name
, build_notify_file_name;
public nt_server, w2k_server, hpux11i_server, sol28_server, aix433_server, wxp_s
erver;
public nt_uid, nt_pwd, unix_uid, unix_pwd, exec_time, win_id, win_ver;
public wnt_test_scripts_path, w2k_test_scripts_path, unix_test_scripts_path;
#public i2_app_nav_keys[], i2_app_action_keys[];

const TRUE = 1;
const FALSE = 0;
const PASS = 0;
const FAIL = 1;
const WARN = 2;
const CONTINUE = 2;
extern RSTART;
extern int GetPrivateProfileStringA(in string, in string, in string, out string,
in int, in string);
extern int WritePrivateProfileStringA(in string, in string, in string, in string
);
################################################################################
###########
#Author: gvenka
#Date: 08/03/2001
#Revision History:
#
#Purpose of function: To return string descriptions for WinRunner return codes
#
#Arguments: rc - return code
#
#Dependencies: g_rc_array - global array holding return code descriptions. The i
ndices in
# this array are the return code integers and the valu
es are the
# corresponding string descriptions. Initialized in i2
_app_data_init.
#
#Example usage: i2_app_rc_desc(-10002);
################################################################################
###########
public function i2_app_rc_desc(in rc)
{
if (rc in g_rc_array) return rc & ":" & g_rc_array[rc];
return rc & ":UNKNOWN ERROR CODE";
}
################################################################################
###########
#Author: gvenka
#Date: 08/03/2001
#Revision History:
#gvenka(05/30/2002) - modified function to report the complete call chain
#gvenka(07/29/2002) - removed usage since i2_app_element_action calls this funct
ion now.
#
#Purpose of function: To write messages upon encountering error conditions.
#
#Arguments: rc - return code returned by function where the error occurred.
# element - UI element or file on which action was performed when erro
r occurred.
#
#Dependencies: g_rc_array - global array holding return code descriptions. The i
ndices in
# this array are the return code integers and the valu
es are the
# corresponding string descriptions. Initialized in i2
_app_data_init.
#
################################################################################
###########
public function i2_app_report_err_msg(in rc, in element)
{
auto i, err_module, err_line_num, err_msg, err_depth, err_type, temp, no
w;
auto err_file = getvar("result")&"\\..\\test_errors.txt";
if (!WR_ENABLE_ERRORS) return 1;
if (match(i2_app_rc_desc(rc), "UNKNOWN ERROR CODE") > 0) return 1;
err_msg = "";
err_depth = call_chain_get_depth();
for(i=err_depth; i>1; i--) {
call_chain_get_attr("type", i, err_type);
if (compare_text(err_type, "test") == 1) {
call_chain_get_attr("testname", i, err_module);
call_chain_get_attr("line_no", i, err_line_num);
err_msg = err_msg & "test " & err_module & ":line " & er
r_line_num;
}
else if(compare_text(err_type, "function") == 1) {
call_chain_get_attr("function", i, err_module);
call_chain_get_attr("line_no", i, err_line_num);
err_msg = err_msg & "->function " & err_module & ":line
" & err_line_num;
}
}
now = time_str(get_time);
now = i2_substr_replace(now, ":", "");
now = i2_substr_replace(now, " ", "_");
err_msg = "Using " & element & ": " & i2_app_rc_desc(rc) & ": " & err_ms
g;
#call_chain_get_attr("testname", err_depth, err_module);
tl_step("ERROR", 1, now & "->" & err_msg);
#err_msg = err_module & " => " & err_msg & "\r\n\n";
err_msg = now & "-> ERROR => " & err_msg & "\r\n\n";
temp = WR_PARAM_DELIMITER;
WR_PARAM_DELIMITER = "#";
i2_file_action(err_file, "open#2");
i2_file_action(err_file, "write#"&err_msg);
i2_file_action(err_file, "close");
WR_PARAM_DELIMITER = temp;

return 1;
}
################################################################################
###########
#Author: gvenka
#Date: 05/07/2002
#Revision History:
#
#Purpose of function: To trim the beginning of a string, end of a string, or bot
h by
# removing the specified characters. The trimmed string is r
eturned.
#
#Arguments: str - the string that needs to be trimmed
# chars - a string specifying the characters to be removed
# boundary - an integer specifying whether to trim the beginning of th
e string (0),
# end of the string (1), or both (anything other than 0 or
1).
#
#Dependencies:
#
#Example usage: res = i2_trim_string(" \tname ;", " \t;");
# res = i2_trim_string(" \tname ;", " \t", 0);
# res = i2_trim_string("\tname ;", " ", 1);
################################################################################
###########
public function i2_trim_string(in str, in chars, in boundary)
{
auto rc;
switch(boundary)
{
case 0:
rc = match(str,"[^"&chars&"]") ? substr(str, RSTART) : E
_ILLEGAL_PARAMETER;
break;
case 1:
rc = match(str&"\001","["&chars&"]*\001") ? substr(str,
1, RSTART-1) : E_ILLEGAL_PARAMETER;
break;
default:
rc = match(str,"[^"&chars&"]") ? substr(str, RSTART) : E
_ILLEGAL_PARAMETER;
if (rc > 0)
rc = match(rc&"\001","["&chars&"]*\001") ? subst
r(rc, 1, RSTART-1) : E_ILLEGAL_PARAMETER;
break;
}
return rc;
}

################################################################################
###########
#Author: gvenka
#Date: 08/03/2001
#Revision History:
#
#Purpose of function: To replace all occurrences of a substring in a string and
return the
# modified string.
#
#Arguments: str - the string to be modified
# old_substr - the substring to be replaced
# new_substr - the substring to replace old_substr with
#
#Dependencies:
#
#Example usage: i2_substr_replace("item1;item2;item3", ";", ",");
################################################################################
###########
public function i2_substr_replace(in str, in old_substr, in new_substr)
{
auto rc;
if (index(new_substr, old_substr) > 0) {
str = i2_substr_replace(str, old_substr, "@@");
old_substr = "@@";
}
while ((rc = index(str, old_substr)) > 0)
str = substr(str, 0,rc-1) & new_substr & substr(str, rc+length(o
ld_substr));
return str;
}

################################################################################
###########
#Author: gvenka
#Date: 07/22/2002
#Revision History:
#
#Purpose of function: To modify directory paths for UNC correctness, removing th
e drive
# specification, or terminating the path with a "\". In addi
tion to the
# specified action, the path will always be modified to corr
ect special
# characters "\t", "\r", and "\n".
#
#Arguments: path - the path string to be modified
# action - the action to perform on the path string. The valid actions
are "unc",
# "terminate", and "remove drive".
#
#Dependencies: i2_substr_replace
#
#Example usage: unc_path = i2_modify_path_str("\\rllab03\t8000x598", "unc");
#unc_path = "\\\\rllab03\\t8000x598";
# terminated_path = i2_modify_path_str("C:\test_server", "terminat
e");
#terminated_path = "C:\\test_server\\";
# path_without_drive = i2_modify_path_str("C:\test_server", "remov
e drive");
#path_without_drive = "\\test_server";
# path = i2_modify_path_str("C:\test_server");
#path = "C:\\test_server";
################################################################################
###########
public function i2_modify_path_str(in path, in action) {
path = i2_substr_replace(path, "\t", "\\t");
path = i2_substr_replace(path, "\r", "\\r");
path = i2_substr_replace(path, "\n", "\\n");
switch(tolower(action)) {
case "terminate":
if (compare_text(substr(path,length(path)),"\\") != 1)
path = path & "\\";
break;
case "unc":
if (compare_text(substr(path,1,1), "\\") != 1)
path = "\\\\" & path;
else if (compare_text(substr(path,1,2), "\\\\") != 1)
path = "\\" & path;
break;
case "remove drive":
if (compare_text(substr(path,2,1), ":") == 1)
path = substr(path,3);
break;
default:
break;
}
return path;
}
################################################################################
###########
#Author: gvenka
#Date: 08/03/2001
#Revision History:
#
#Purpose of function: To replace attribute values for a GUI map element (window
or object)
#
#Arguments: buf - GUI map file containing the window or object
# win - logical name of window/frame
# obj - logical name of object
# replace_str - delimited string containing attribute value pairs whic
h need to
# be modified or added to the physical description of th
e element
# sep1 - delimiter for attribute value pairs in replace_str. Default i
s ";".
# sep2 - delimiter between attribute and value for each pair. Default
is ":".
#
#Dependencies:
#
#Example usage: i2_app_gui_map_attr_replace("", "Browser Main Window", "", "loca
tion:1");
# i2_app_gui_map_attr_replace("", "myframe", "myobj", "location:1"
);
################################################################################
###########
public function i2_app_gui_map_attr_replace(in buf, in win, in obj, in replace_s
tr, in sep1, in sep2)
{
auto rc, temp1[], temp2[], count, i;
rc = E_OK;
if (sep1 == "") sep1 = ";";
if (sep2 == "") sep2 = ":";
count = split(replace_str,temp1,sep1);
for (i=1; i<=count; i++)
{
split(temp1[i],temp2,sep2);
if ((rc = GUI_buf_set_desc_attr(buf, win, obj, temp2[1], temp2[2
])) != E_OK) break;
}
return rc;
}
################################################################################
###########
#Author: gvenka
#Date: 08/03/2001
#Revision History:
#
#Purpose of function: To add elements dynamically to the GUI map
#
#Arguments: element_type - specifies type of element. Can be either "win" or "ob
j".
# element_name - logical name of element
# element_class - string used to identify type of window or object. Ca
n be one
# of the indices for the global array g_element_desc_a
rray.
# opt_args - delimited string containing attribute-value pairs which n
eed to
# be modified or added to the physical description of the e
lement.
# It is assumed that attribute-value pairs are delimited by
";" and
# each attribute and value are delimited by ":"
#
#Dependencies: Global variable WR_DEBUG and element description array g_element_
desc_array
# Functions i2_app_report_err_msg and i2_app_gui_map_attr_replace s
hould be defined
#
#Example usage: i2_app_gui_map_attr_replace("", "Browser Main Window", "", "loca
tion:1");
# i2_app_gui_map_attr_replace("", "myframe", "myobj", "location:1"
);
################################################################################
###########
public function i2_app_gui_map_add(in element_name, in element_class, out elemen
t_buf, out win_name, out obj_name)
{
auto rc, element_desc, hWnd;
rc = E_OK;
element_class = tolower(element_class);
if (!(element_class in g_element_action_array) || !(element_class in g_e
lement_desc_array)) {
rc = E_ILLEGAL_PARAMETER;
i2_app_report_err_msg(rc, element_name);
return rc;
}
if (match(g_element_desc_array[element_class], "class:.*window") > 0) {
win_name = element_name;
obj_name = "";
}
else {
win_name = GUI_get_window();
obj_name = element_name;
}
if (win_name && GUI_map_get_desc(win_name, obj_name, element_desc, eleme
nt_buf) != E_OK)
{
element_desc = sprintf("{%s\"%s\"}", g_element_desc_array[elemen
t_class], element_name);
if (match(element_desc, ": *\"") == 0)
element_desc = sprintf("{%s}", g_element_desc_array[elem
ent_class]);
rc = GUI_add(element_buf, win_name, obj_name, element_desc);
}
return rc;
}

public function i2_app_gui_cleanup() {


GUI_close_all();
GUI_close("<temporary>");
return E_OK;
}
################################################################################
###########
#Author: gvenka
#Date: 08/03/2001
#Revision History:
#
#Purpose of function: To perform an action on an element (window, frame, object)
#
#Arguments: element_name - logical name of element
# element_class - string used to identify type of window or object. Ca
n be one
# of the indices for the global array g_element_desc_a
rray.
# element_params - a delimited string specifying the type of action on
the
# element, The delimiter to be used is ";"
# timeout - specifies the timeout parameter for win_exists, set_window
, and
# obj_exists functions. If this is "", it is set to WR_WIN_T
IMEOUT
# and WR_OBJ_TIMEOUT for windows and objects respectively.
# opt_args - delimited string containing attribute-value pairs which n
eed to
# be modified or added to the physical description of the e
lement.
# It is assumed that attribute-value pairs are delimited by
";" and
# each attribute and value are delimited by ":"
# err_flag - an optional flag to indicate whether error reporting shou
ld be turned off
# during this call to i2_app_element_action. If anything ot
her than "" or 0 is
# passed for this parameter, no error reporting is performe
d during this call.
#
#Dependencies:
#
#Example usage: i2_app_element_action("Browser Main Window", "html_browser", "cl
ose");
# i2_app_element_action("PO_edit", "html_edit", "PO_10001");
# i2_app_element_action("Login", "html_link");
# i2_app_element_action("Supplier_Names", "html_list", "Supp1;Supp
2;Supp3");
# i2_app_element_action("Order_1", "html_check", "ON");
################################################################################
###########
public function i2_app_element_action(in element_name, in element_class, in elem
ent_params, in timeout, in opt_args, in err_flag)
{
auto rc, element_buf, win_name, obj_name, func_call;
auto err_val = WR_ENABLE_ERRORS;
auto hWnd, DWIN, osver;
rc = E_OK;
element_class = tolower(element_class);
if (!(element_class in g_element_action_array) || !(element_class in g_e
lement_desc_array)) {
rc = E_ILLEGAL_PARAMETER;
i2_app_report_err_msg(rc, element_name);
return rc;
}
# Added on 05/16/2003 - eQuality Issue No.456844
# To recognize the telnet and console windows in Win2K and XP
# The following If else statement was added.
if (element_class == "telnet"){
rc = get_os_ver(osver);
hWnd = FindWindowA("ConsoleWindowClass", element_name);
DWIN = "{ handle: " & hWnd & " }";
if (substr(osver,0,11)=="Version 4.0"){
DWIN = element_name;
}
element_name = DWIN;
}
if (element_class == "console"){
hWnd = FindWindowA("ConsoleWindowClass", element_name);
DWIN = "{ handle: " & hWnd & " }";
element_name = DWIN;
}
# End of the enhancement for 456844
rc = i2_app_gui_map_add(element_name, element_class, element_buf, win_na
me, obj_name);
if (opt_args) rc = i2_app_gui_map_attr_replace(element_buf, win_name, ob
j_name, opt_args, ";", ":");
func_call = sprintf("treturn %s(\"%s\", \"%s\", \"%s\");", g_element_act
ion_array[element_class],
element_name, element_params, timeout);
(rc == E_OK) && (rc = eval(func_call));
if (err_flag) WR_ENABLE_ERRORS = 0;
i2_app_report_err_msg(rc, element_name);
WR_ENABLE_ERRORS = err_val;
return rc;
}

public function i2_app_data_init(in app_nav_data_file, in app_action_data_file)


{
auto i, rc, key, line, temp[];
if (!WR_PARAM_DELIMITER) WR_PARAM_DELIMITER = ";";
setvar("List_item_separator", WR_PARAM_DELIMITER);
WR_DEBUG = getenv("WR_DEBUG");
WR_ENABLE_ERRORS = 1;
rc = GUI_get_name(win_id,win_ver);
#Error codes description array
#g_rc_array[0] = "Return Code 0; E_OK / E_FILE_OK; Operation successful.
";
g_rc_array[-10001] = "E_GENERAL_ERROR; General error occurred.";
g_rc_array[-10002] = "E_NOT_FOUND; Window or object not found.";
g_rc_array[-10003] = "E_NOT_UNIQUE; More than one window or object respo
nds to the physical description.";
g_rc_array[-10004] = "E_ILLEGAL_OPERATION; Operation invalid for object.
See note.";
g_rc_array[-10005] = "E_OUT_OF_RANGE; Parameter is out of range.";
g_rc_array[-10006] = "E_ILLEGAL_PARAMETER; Specified value for one or mo
re parameters is invalid.";
g_rc_array[-10007] = "E_FILE_OPEN; Cannot open file. File may already be
open.";
g_rc_array[-10011] = "E_NOT_IN_MAPPING; Cannot find window or object in
the GUI map.";
g_rc_array[-10012] = "E_EXIST; Object already exists";
g_rc_array[-10018] = "E_OPERATION_NOT_PERFORMED; Cannot perform requeste
d operation.";
g_rc_array[-10019] = "E_FUNCTION_NOT_LOADED; Specified function is not c
urrently loaded. In the case of a handler function, the exception is undefined."
;
g_rc_array[-10024] = "E_NO_FONT; No font was loaded.";
g_rc_array[-10025] = "E_SYNTAX; Syntax error in TSL statement.";
g_rc_array[-10026] = "E_NO_SVC; Called function does not exist.";
g_rc_array[-10028] = "E_FUNCTION_NOT_IMPLEMENTED; Called function could
not be implemented.";
g_rc_array[-10029] = "E_ATTR_IN_DESC; Specified property is used in the
object s physical description in the GUI map.";
g_rc_array[-10030] = "E_NO_LABEL; Label property is not used in the wind
ow s physical description in the GUI map.";
g_rc_array[-10032] = "E_FILE_NOT_OPEN; File is not open.";
g_rc_array[-10033] = "E_FILE_NOT_FOUND; File is not found.";
g_rc_array[-10034] = "E_FILE_LINE_TRUNC; File line is truncated.";
g_rc_array[-10035] = "E_FILE_EOF; End of file.";
g_rc_array[-10036] = "E_FILE_NOT_READ_MODE; Cannot read file because fil
e is not in read mode. ";
g_rc_array[-10037] = "E_FILE_READ_MODE; Cannot write to file because fil
e is in read mode.";
g_rc_array[-10038] = "E_BAD_PATH; Incorrect path.";
g_rc_array[-10039] = "E_ACCESS_DENIED; Access is denied.";
g_rc_array[-10040] = "E_DISK_FULL; Disk is full.";
g_rc_array[-10041] = "E_SHARING_VIOLATION; Sharing violation.";
g_rc_array[-10042] = "E_FILE_ERROR; General file error.";
g_rc_array[-10044] = "E_NOT_PARAMETER; Parameter is invalid.";
g_rc_array[-10101] = "E_NOT_DISPLAYED; Window or object is not displayed
.";
g_rc_array[-10102] = "E_DISABLED; Window or object is disabled.";
g_rc_array[-10103] = "E_IMPROPER_CLASS; Operation cannot be performed on
this object class.";
g_rc_array[-10104] = "E_ILLEGAL_KEY; Key or mouse button name is illegal
.";
g_rc_array[-10105] = "E_ITEM_NOT_FOUND; Item in list or menu not found."
;
g_rc_array[-10107] = "E_OBJECT_SYNTAX; Illegal syntax used.";
g_rc_array[-10112] = "E_ILLEGAL_NUM_OF_PARAMS; Number of parameters does
not match those for the command.";
g_rc_array[-10114] = "E_AUT_DISCONNECTED; The application under test was
disconnected.";
g_rc_array[-10115] = "E_ATTR_NOT_SUPPORTED; Property function is not sup
ported.";
g_rc_array[-10116] = "E_MISMATCH; Verification mismatch found.";
g_rc_array[-10117] = "E_ITEM_NOT_UNIQUE; More than one item in list or m
enu has this name.";
g_rc_array[-10118] = "E_TEXT_TOO_LONG; Text to be inserted exceeds maxim
um number of characters. The string will be truncated to the appropriate length.
";
g_rc_array[-10119] = "E_DIFF; GUI checkpoint mismatch found.";
g_rc_array[-10120] = "E_CMP_FAILED; Comparison failed.";
g_rc_array[-10121] = "E_CAPT_FAILED; Capture failed.";
g_rc_array[-10122] = "E_WRONG_OBJ_FAILED; Object in checklist is not the
object in the command.";
g_rc_array[-10123] = "E_SET_WIN; Window setting parameters missing.";
g_rc_array[-10124] = "E_BITMAP_TIMEOUT; The wait_bitmap operation exceed
ed specified wait time.";
g_rc_array[-10125] = "E_BAD_CHECK_NAME; Syntax error in requested check.
";
g_rc_array[-10126] = "E_OBJ_CAPT_FAILED; Capture failed for specified ob
ject.";
g_rc_array[-10127] = "E_UNEXP_WIN; Window in checklist is not the window
in the command.";
g_rc_array[-10128] = "E_CAPT_FUNC_NOT_FOUND; Capture function not define
d.";
g_rc_array[-10129] = "E_CMP_FUNC_NOT_FOUND; Compare function not defined
.";
g_rc_array[-10130] = "E_TSL_ERR; Syntax error detected.";
g_rc_array[-10131] = "E_TOOLKIT_MISMATCH; Incorrect toolkit detected.";
g_rc_array[-10132] = "E_RECT_COVERED; Desired rectangle is hidden.";
g_rc_array[-10133] = "E_RECT_OUT; Desired rectangle does not appear on s
creen.";
g_rc_array[-10134] = "E_AREA_COVERED; Desired area is hidden.";
g_rc_array[-10135] = "E_AREA_OUT; Desired area does not appear on screen
.";
g_rc_array[-10136] = "E_STR_NOT_FOUND; Text string not located.";
g_rc_array[-10137] = "E_WAIT_INFO_TIMEOUT; The wait_info operation excee
ded specified wait time.";
g_rc_array[-10138] = "E_SYNC_FAILED; Synchronization failed.";
g_rc_array[-10139] = "E_DIFF_SIZE; Expected and actual bitmaps are diffe
rent sizes.";
g_rc_array[-10141] = "E_DROP_WITHOUT_DRAG; Drop operation is performed w
ithout a drag operation preceding it.";
g_rc_array[-10142] = "E_VIR_OBJ; Function not supported for virtual obje
cts.";
g_rc_array[-10143] = "E_MISSING_ATTR; Lack of x-, y-, height, or width c
oordinates in the description of the virtual object.";
g_rc_array[-10144] = "E_EDIT_SET_FAILED; The edit_set operation failed."
;
#Object descriptions
g_element_desc_array["push"] = "class: push_button, label: ";
g_element_desc_array["edit"] = "class: edit, attached_text: ";
g_element_desc_array["list"] = "class: list, attached_text: ";
g_element_desc_array["combo"] = "class: list, attached_text: ";
g_element_desc_array["radio"] = "class: radio_button, label: ";
g_element_desc_array["check"] = "class: check_button, label: ";
g_element_desc_array["msg_text"] = "class: static_text, MSW_id: 65535";
#Window descriptions
g_element_desc_array["dialog"] = "class: window, MSW_class: Dialog, labe
l: ";
g_element_desc_array["window"] = "class: window, MSW_class: \"!Afx:.*\",
label: ";
g_element_desc_array["popup_window"] = "class: window, MSW_class: #32770
, label: ";
if (win_id == "Windows XP"){
g_element_desc_array["telnet"] = "class: window, MSW_class: Cons
oleWindowClass, label: ";
}
else {
g_element_desc_array["telnet"] = "class: window, MSW_class: Teln
etWClass, label: ";
}
g_element_desc_array["console"] = "class: window, MSW_class: ConsoleWind
owClass, label: ";
#Window actions
g_element_action_array["dialog"] = "i2_app_win_common_action"; #"i2_app_
dialog_action";
g_element_action_array["window"] = "i2_app_win_common_action"; #"i2_app_
window_action";
g_element_action_array["console"] = "i2_app_console_action";
g_element_action_array["telnet"] = "i2_app_telnet_action"; #"i2_app_cons
ole_action";
g_element_action_array["popup_window"] = "i2_app_win_common_action"; #"i
2_app_popup_action";
#Object actions
g_element_action_array["edit"] = "i2_app_edit_action";
g_element_action_array["combo"] = "i2_app_combobox_action";
g_element_action_array["list"] = "i2_app_list_action";
g_element_action_array["check"] = "i2_app_statebutton_action";
g_element_action_array["radio"] = "i2_app_statebutton_action";
g_element_action_array["push"] = "i2_app_pushbutton_action";
g_element_action_array["table"] = "i2_app_table_action";
g_element_action_array["msg_text"] = "i2_app_msg_text_action";

GUI_close_all();
GUI_close("<temporary>");
# unload_dll("kernel32.dll");
# load_dll("kernel32.dll");
reload (getenv("M_ROOT")&"\\lib\\win32api", 1, 1);
return E_OK;
# for (key in g_gui_map_array) delete g_gui_map_array[key];
# for (key in i2_app_nav_keys) delete i2_app_nav_keys[key];
# for (key in i2_app_action_keys) delete i2_app_action_keys[key];
#
# if ((rc = file_open(app_nav_data_file, FO_MODE_READ)) == E_OK)
# {
# while (file_getline(app_nav_data_file, line) == E_OK)
# {
# if ((line == "") || (match(line, "#") == 1)) continue;
# split(line, temp, ",");
# #key = temp[i];
# #line = substr(line, length(temp[1])+2);
# key = substr(line, 1, length(temp[1])+length(temp[2])+1)
;
# line = substr(line, length(temp[1])+2);
# i2_app_nav_keys[tolower(key)] = line;
# }
# file_close(app_nav_data_file);
# }
#
# if ((rc = file_open(app_action_data_file, FO_MODE_READ)) == E_OK)
# {
# while (file_getline(app_action_data_file, line) == E_OK)
# {
# if ((line == "") || (match(line, "#") == 1)) continue;
# split(line, temp, ",");
# key = temp[1];
# line = substr(line, length(temp[1])+2);
# i2_app_action_keys[tolower(key)] = line;
# }
# file_close(app_action_data_file);
# }
}

public function i2_app_data_end() {


auto i;
for (i in g_rc_array) delete g_rc_array[i];
for (i in g_element_desc_array) delete g_element_desc_array[i];
for (i in g_element_action_array) delete g_element_action_array[i];
unload_dll("kernel32.dll");
return E_OK;
}

# public function i2_app_perform_action(in action_name, in args) {


# auto i, max_num_args, num_args, temp[], func_call;
#
# split(i2_app_action_keys[tolower(action_name)], temp, ",");
# func_call = sprintf("%s(", temp[1]);
# max_num_args = temp[2];
# if (max_num_args == "") max_num_args = 0;
#
# num_args = split(args, temp, ",");
# if (num_args > max_num_args) num_args = max_num_args;
# for (i=1; i<=num_args; i++) {
# func_call = sprintf("%s\"%s\"", func_call, temp[i]);
# if (i != num_args) func_call = sprintf("%s,", func_call);
# }
# func_call = sprintf("%s);", func_call);
#
# eval(func_call);
# return;
# }

# public function i2_app_perform_action_ddt(in i2_app_action_desc) {


# auto args, temp[];
#
# if (i2_app_action_desc!="" && (match(i2_app_action_desc,"#")!=1)) {
# split(i2_app_action_desc, temp, ",");
# args = substr(i2_app_action_desc, length(temp[1])+2);
#
# i2_app_perform_action(temp[1], args);
# }
# return E_OK;
# }

# public function i2_app_db_connect(in hostname, in db_alias, in db_user, in db_


password)
# {
# auto rc;
#
# }

# public function i2_app_add_funcs_to_generator()


# {
# static func_category = "i2 generic functions";
# auto rc, i, select_str1, select_str2;
#
# rc = E_OK;
# rc = generator_add_category(func_category);
# rc = generator_add_subcategory("all_functions", func_category);
#
# select_str1 = "select_list(";
# for (i in g_element_desc_array) select_str1 = select_str1 & " \"" & i &
"\"";
# select_str1 = select_str1 & ")";
# rc = generator_add_function("i2_app_element_exists",
#
"This function checks whether a object is displayed on\r\nthe screen. "&
#
"If the object doesn't exist in the GUI map,\r\nit adds it to the map.\r\n", 5,
#
"window name", "point_window", "\"data_frame\"", "object name", "point_object",
#
"\"Order Management\"", "object class", select_str1, "\"html_text\"",
#
"optional args", "type_edit", "", "timeout", "type_edit", "");
# rc = generator_add_function_to_category(func_category, "i2_app_obj_exist
s");
#
# select_str2 = "select_list(\"\" \"valid\" " &
#
"\"get text\" \"check text;dummy text\" \"item count\" " &
#
"\"select range;index1;index2\" \"select all\" \"get state\" " &
#
"\"check state;ON\" \"get info;dummy attr\" " &
#
"\"check info;dummy attr;dummy val\" \"row count\" \"column count\" " &
#
")";
# rc = generator_add_function("i2_app_element_action",
#
"This function performs an action on an object specified by the\r\nobj "&
#
"params argument\r\n", 6,
#
"window name", "point_window", "\"data_frame\"", "object name", "point_object",
#
"\"Order Management\"", "object class", select_str1, "\"html_text\"",
#
"obj params", select_str2, "", "optional args", "type_edit", "",
#
"timeout", "type_edit", "");
# rc = generator_add_function_to_category(func_category, "i2_app_obj_actio
n");
#
# }

################################################################################
###########
#Author: gvenka
#Date: 04/17/2002
#Revision History:
#
#Purpose of function: To perform operations on a file
#
#Arguments: file_name - the name of the file.
# file_params - a delimited string specifying the type of action on th
e file
# "open;<mode>": open a file for r
eading (<mode> = 0),
# writi
ng (<mode> = 1), append(<mode> = 2).
# "close": close a file
# "read": read a line from the fil
e and return the line
# "write;<str>": write/append the
string <str> to the file.
# err_flag - an optional flag to indicate whether error reporting shou
ld be turned off
# during this call to i2_file_action. If anything other tha
n "" or 0 is
# passed for this parameter, no error reporting is performe
d during this call.
#
#
#Dependencies:
#
#Example usage: file1 = "C:\\mydata.txt";
# rc = i2_file_action(file1, "open;2");
# rc = i2_file_action(file1, "write;10\n20");
# rc = i2_file_action(file1, "close");
# rc = i2_file_action(file1, "open;0");
# rc = i2_file_action(file1, "read");
################################################################################
###########
public function i2_file_action(in file_name, in file_params, in err_flag)
{
auto rc, line, params[], rval;
auto err_val = WR_ENABLE_ERRORS;
#g_current_element = file_name;
split(file_params, params, WR_PARAM_DELIMITER);
switch(tolower(params[1]))
{
case "open":
rc = file_open(file_name, params[2]);
break;
case "close":
rc = file_close(file_name);
break;
case "read":
rc = E_OK;
(params[2]==0) && (rc = file_open(file_name, params[2]))
;
(rc == E_OK) && (rc = file_getline(file_name, line));
(rc == E_OK) && (params[2]==0) && (rc = file_close(file_
name));
(rc == E_OK) && (rc = line);
break;
case "write":
rc = E_OK;
(params[3]>0) && (rc = file_open(file_name, params[3]));
(rc == E_OK) && (rc = file_printf(file_name, "%s\r\n", p
arams[2]));
(rc == E_OK) && (params[3]>0) && (rc = file_close(file_n
ame));
break;
case "exists":
rc = file_exists(file_name);
break;
case "read key":
rc = GetPrivateProfileStringA(params[2], params[3], "",
rval, 256, file_name);
rc = rval;
break;
case "write key":
((rc = WritePrivateProfileStringA(params[2], params[3],
params[4], file_name)) > 0) &&
(rc = E_OK);
break;
case "copy":
rc = dos_system("xcopy /C "&file_name&" "&params[2]);
break;
case "move":
rc = dos_system("move "&file_name&" "&params[2]);
break;
case "delete":
rc = dos_system("del /F /Q "&file_name);
break;
default:
rc = E_ILLEGAL_OPERATION;
break;
}
if (err_flag) WR_ENABLE_ERRORS = 0;
i2_app_report_err_msg(rc, file_name);
WR_ENABLE_ERRORS = err_val;
return rc;
}

################################################################################
###########
#Author: jmathews
#Date: 03/06/2002
#Revision History:
#
#Purpose of function: To write a string to a file
#
#Arguments: str - the string to be written
# filename - the filename
# path - full path of the output file (null path (default)
writes to "result_dir")
# mode - 1=append 0(default) is overwrite
#
#Dependencies:
# If "path" is null-string, file will be written to the "result directory"
as defined
# by WinRunner
# If "path" is non-null, file will be written to path\filename
#
#Example usage: i2_save_string_to_file("item1;item2;item3", "my_file.txt", "c:\p
ath", "0");
#Example usage: i2_save_string_to_file("item1;item2;item3", "my_file.txt", "", "
0");
################################################################################
###########
public function i2_save_string_to_file(in str, in filename, in pathname, in mode
)
{
auto rc;
auto path;
auto full_filename;
if (length(pathname) > 2)
{
full_filename = pathname & filename;
} else {
# get the results directory for the path...
path = getvar("result");
full_filename = path & "\\" & filename;
}

if (mode == 1){
# this is append mode...
file_open( full_filename, FO_MODE_APPEND);
} else {
# overwrite mode...
file_open( full_filename, FO_MODE_WRITE);
}
# write the string...
rc = file_printf( full_filename, "%s\r\n",str);
file_close(full_filename);
return rc;
}

# ------------------------------------------------------------------------------
--------------------------------------------------
# FAIL:
# public helper function which will show up as a test failure in the WinRunner T
est
# Results window for the reason given in the variable <reason>. This function
# will also exit the calling test with the value FAIL. If the test is part of a
batch
# run, it returns control to the batch test script with the value FAIL.
# ------------------------------------------------------------------------------
--------------------------------------------------
public function FAIL (reason) {
tl_step ("Test Failed", FAIL, reason);
#TEST_RESULT = 1;
}
# ------------------------------------------------------------------------------
--------------------------------------------------
# WARN:
# public helper function which will show up as a test failure in the WinRunner
# Test Results window. However, unlike FAIL ( ) this function does NOT stop the
test execution.
# It will simply return control to the calling test with the return code = WARN
# ------------------------------------------------------------------------------
--------------------------------------------------
public function WARN (reason) {
tl_step ("Test Failed", WARN, reason);
}
# ------------------------------------------------------------------------------
--------------------------------------------------
# CONTINUE:
# public helper function which will show up as a test pass in the WinRunner
# Test Results window. It will return control to the calling test with the
# return code = CONTINUE.
# ------------------------------------------------------------------------------
--------------------------------------------------
public function CONTINUE (step) {
tl_step ("Test Passed", PASS, step);
}
# ------------------------------------------------------------------------------
--------------------------------------------------
# PASS:
# public helper function which will show up as a test pass in the WinRunner
# Test Results window. It will return control to the calling test with the
# return code = PASS .If the test is part of a batch
# run, it returns control to the batch test script with the value PASS.
# ------------------------------------------------------------------------------
--------------------------------------------------
public function PASS (step) {
tl_step ("Test Passed", PASS, step);
#TEST_RESULT = 0;
}

#-------------------------------------------------------------------------------
-------------------------------------------------------------------------
# Compare_files:
# A new Compare function which takes the list of files to compare as a string ar
gument and uses
# the split function to get the individual files. To separate the files, commas
, semicolons, or
# tabs can be used. If full paths is TRUE, then the third and fourth arguments n
eed to be specified
# for the actual path and expected path, respectively. The assumption here is th
at all the actual
# files are under actual path and all the expected files are under expected path
.
# Examples:
# i2_compare_files("orders1.txt,orders2.txt,mfg1a.txt,mfg1b.txt", FALSE);
# i2_compare_files("orders1.txt,orders2.txt,mfg1a.txt,mfg1b.txt", TRUE, "Z:\\fp-
qa\\UI_Scripts\\functionality\\ato_set1\\res1",
# "Z:\\fp-qa\\UI_Scripts\\functionality\\ato_set1\\exp"
);
#-------------------------------------------------------------------------------
-------------------------------------------------------------------------
public function i2_compare_files (in comparison_str, in full_paths, in actual_pa
th, in expected_path){
auto test_passed= 1, i, actual, expected, comparison_array[];
auto result_dir_path, expected_dir_path;
# We start with test_passed = 1 and see if there are differences between
the files
split(comparison_str, comparison_array, ",;\t");
result_dir_path = getvar("result");
expected_dir_path = getvar("exp");
for (i in comparison_array) {
if (!full_paths) {
expected = sprintf ("%s\\%s", expected_dir_path, compari
son_array[i]);
actual = sprintf ("%s\\%s", result_dir_path, comparison_
array[i]);
} else {
actual = sprintf ("%s\\%s", actual_path, comparison_arra
y[i]);
expected = sprintf ("%s\\%s", expected_path, comparison_
array[i]);
}
if (file_compare (actual,expected) != E_OK){
# Files are different
# Send a message to the WinRunner report.
WARN ("Files are different" );
test_passed = 0;
} else {
# Files are identical,
# A message is sent to the WinRunner report. The compari
son continues.
CONTINUE("Files are identical");
}
}
# After comparing all the files, if the test_passed is still 1 then file
s are as expected.
# The test PASSed. Otherwise, it FAILed. The PASS and FAIL functions are
called
# where the public variable TEST_RESULT is set to either 0 (for pass) or
1 (for fail).
# TEST_RESULT is used in writing the text report for web result generati
on.
(test_passed) ? PASS ("All files were as expected!") : FAIL ("One or m
ore files were different");
return(test_passed);
}
################################################################################
###########
#Author: jmathews
#Date: 03/08/2002
#Revision History:
#gvenka(07/12/2002) - replaced the dos_system command with i2_file_action
# changed the "move" action to "copy" to archive the results
file on the
# client machine.
#
#Purpose of function: To publish the pass/fail results of a test...
# Function will use WinRunner environment variables to determine the
# name of the current test and the results directory.
# Output results file is written to the results directory
#
#Arguments: result - the result flag (0= fail, >0 = pass)
# testname - (optional) string containing name of the test
# by default, function will use test_name defined in confi
guration
#
#Dependencies: uses global variables updated in calls to i2_test_init
#
#Example usage: i2_publish_results(1,["my_test"]);
################################################################################
###########
public function i2_publish_results(in result,in testname)
{
auto result_string, rc, res_file, current_time;
auto execution_string, res_path, dest_path, exec_string, publish_testnam
e;
auto seconds_time, total_test_run_time;
current_time = time_str(get_time());
seconds_time = get_time();
current_time = i2_substr_replace(current_time, " ", "_");
current_time = i2_substr_replace(current_time, ":", "_");
# Calculate current test total run time
rc = i2_AP_GetTransactionTime(testname, total_test_run_time);
#res_file = "wr_result_" & current_time & ".txt";
res_file = g_test_env_array["machine_name"] & "_" & seconds_time & "_wr_
result.txt";
res_path = g_test_env_array["client_results_path"];
if (length(res_path) < 1) {
res_path = getvar("result") & "\\";
}
if ((length(g_test_env_array["test_name"]) < 1) || (testname != "")) {
g_test_env_array["test_name"] = testname;
}
# format for output string follows:
# testname;status;date/time;machine;stackid;clientuitype;projid;relid
#result_string = (match(g_test_env_array["test_name"],":")==2) ? substr(g_te
st_env_array["test_name"],3)
#
: g_test_env_array["test_name"];
result_string = i2_modify_path_str(g_test_env_array["test_name"], "remov
e drive");
result_string = (result > 0) ? result_string & ";Passed" : result_string & "
;Failed";
result_string = result_string & ";" & current_time;
result_string = result_string & ";" & g_test_env_array["machine_name"];
result_string = result_string & ";" & g_test_env_array["stack_id"];
result_string = result_string & ";" & g_test_env_array["ui_client_type"]
;
result_string = result_string & ";" & g_test_env_array["project_id"];
result_string = result_string & ";" & g_test_env_array["release_id"];
result_string = result_string & ";" & total_test_run_time;
#rc = i2_save_string_to_file(result_string, res_file, res_path, 0);
res_path = i2_modify_path_str(res_path, "terminate");
WR_PARAM_DELIMITER = "!";
i2_file_action(res_path&res_file, "write!"&result_string&"!1");
WR_PARAM_DELIMITER = ";";
dest_path = i2_modify_path_str(g_test_env_array["engine_results_path"],
"unc");
rc = i2_file_action(res_path&res_file, "copy;"&dest_path);
return(rc);
}

################################################################################
###########
#Author: gvenka
#Date: 06/17/2002
#Revision History:
#Modified by Sumana : Tested the function using xls file and txt file, added ddt
_save option to the function.
#Purpose of function: To perform operations on a Excel data file or tab delimite
d text file. This
# assumes that the user is familiar with how WinRunner inter
acts with such
# files.Added examples using the function.
#
#Arguments: file_name - the name of the file.
# file_params - a delimited string specifying the type of action on th
e file. Parameters
# in [] are optional.
# "open;<mode>": open a file for r
eading (<mode> = 0) or
# readi
ng/writing (<mode> = 1).
# "close": close a file
# "get val;<parameter>;[row number
]": returns the value corresponding to
# the parameter <parameter> from the current row if [row
number] is not
# specified.
# "set val;<parameter>;<value>;[ro
w number]": writes the value <value>
# corresponding to the parameter <parameter> to the curre
nt row if
# [row number] is not specified.
# "get row": returns the active/current row number in the
file.
# "set row;[row number]": sets the active row to the [row
number]. If
# [row number] is not specified, the next row is set to b
e the active row.
# "row count": returns the number of rows in the file.
# "save": saves the file specified by file_name.
# "export;<export_file>": exports the contents of file spe
cified by file_name
# to the file specified by <export_file>.
# err_flag - an optional flag to indicate whether error reporting shou
ld be turned off
# during this call to i2_ddt_file_action. If anything other
than "" or 0 is
# passed for this parameter, no error reporting is performe
d during this call.
#
#
#Dependencies:
#Added by Sumana
#This function has a dependency on the following function-
#i2_substr_replace()
#Example usage:
#To open the file in reading/writing mode:
#i2_ddt_file_action("c:\abc123.xls","open;1");
#To get the value of the parameter named "c", at row number 1:
#test3=i2_ddt_file_action("c:\abc123.xls","get val;c;1");
#To set the value of the parameter named "c", at row number 1:
#i2_ddt_file_action("c:\abc123.xls","set val;c;"hello";1");
#To get the active/current row number in the file.
#rownumber=i2_ddt_file_action("c:\abc123.xls","get row");
#To set the active/current row number in the file to a certain row
#i2_ddt_file_action("c:\abc123.xls","set row;5");
#To save the file:
#i2_ddt_file_action("c:\abc123.xls","save");
################################################################################
###########
public function i2_ddt_file_action(in file_name, in file_params, in err_flag)
{
auto rc, params[], rval, temp;
auto err_val = WR_ENABLE_ERRORS;
split(file_params, params, WR_PARAM_DELIMITER);
switch(tolower(params[1]))
{
case "open":
rc = ddt_open(file_name, params[2]);
break;
case "close":
rc = ddt_close(file_name);
break;
case "get val":
((rc = ddt_is_parameter(file_name,params[2])) == E_OK) &
&
(rc = params[3] ? ddt_val_by_row(file_name,params[3],par
ams[2])
: ddt_val(file_name, par
ams[2]));
break;
case "set val":
((rc = ddt_is_parameter(file_name,params[2])) == E_OK) &
&
(rc = params[4] ? ddt_set_val_by_row(file_name,params[4]
,params[2],params[3])
: ddt_set_val(file_name,params[2],params
[3]));
(rc == E_OK) && (rc = ddt_save(file_name)); #added ddt_s
ave
break;
case "row count":
((rc = ddt_get_row_count(file_name, rval)) == E_OK) &&
(rc = rval);
break;
case "get row":
((rc = ddt_get_current_row(file_name, rval)) == E_OK) &&
(rc = rval);
break;
case "set row":
rc = params[2] ? ddt_set_row(file_name, params[2]) : ddt
_next_row(file_name);
break;
case "get params":
rc = ddt_get_parameters(file_name, rval, temp);
(rc == E_OK) && (rc = i2_substr_replace(rval, "\t", WR_P
ARAM_DELIMITER));
break;
case "save":
rc = ddt_save(file_name);
break;
case "export":
rc = ddt_open(file_name, DDT_MODE_READ) && (rc = ddt_ope
n(params[2], DDT_MODE_READWRITE));
(rc==E_OK) && (rc = ddt_export(file_name, params[2]));
(rc==E_OK) && (rc = ddt_close(file_name)) && (rc = ddt_c
lose(params[2]));
break;
default:
rc = E_ILLEGAL_OPERATION;
break;
}
if (err_flag) WR_ENABLE_ERRORS = 0;
i2_app_report_err_msg(rc, file_name);
WR_ENABLE_ERRORS = err_val;
return rc;
}

Potrebbero piacerti anche