Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
###########
#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;
}
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);
# }
}
################################################################################
###########
#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&" "¶ms[2]);
break;
case "move":
rc = dos_system("move "&file_name&" "¶ms[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;
}