Winrunner TSL命令简介
201、tab_get_item ( tab, item_num, out_item );返回tab选项的名称
202、tab_get_selected ( tab, out_item, out_num );返回选定的tab选项的名称和个数
203、tab_select_item ( tab, item );选择tab选项
204、tab_wait_info ( tab, property, value, time );等待tab属性的值
205、tbl_activate_cell ( table, row, column );双击表里某个单元
206、tbl_activate_col ( table, column );双击表里某列
207、tbl_activate_header ( table, column );双击表里某列标题
208、tbl_activate_row ( table, row );双击表里某行
209、tbl_deselect_col ( table, column );取消选择表的某列
210、tbl_deselect_cols_range ( table, from_column, to_column );取消选择表里某几列
211、tbl_deselect_row ( table, row );取消选择表里某行
212、tbl_deselect_rows_range ( table, from_row, to_row );取消选择表里某几行
213、tbl_extend_col ( table, column );往表里当前列加一列
214、tbl_extend_cols_range ( table, from_column, to_column );往表里当前列加多列
215、tbl_extend_row ( table, row );往表里当前行前加一行
216、tbl_extend_rows_range ( table, from_row, to_row );往表里当前行加多行
217、tbl_get_cell_data ( table, row, column, out_text );返回表里指定单元的内容
218、tbl_get_cols_count ( table, out_cols_count );返回表的列数
219、tbl_get_column_name ( table, col_index, out_col_name );返回表里指定列的标题名称
220、tbl_get_column_names ( table, out_col_names, out_cols_count );返回表里列的名称和个数
221、tbl_get_rows_count ( table, out_rows_count );返回表的行数
222、tbl_get_selected_cell ( table, out_row, out_column );返回表里焦点所在单元
223、tbl_get_selected_row ( table, row );返回当前焦点所在行
224、tbl_select_cells_range ( table, start_row, start_col, end_row, end_col );在表里点击选定的几个单元
225、tbl_select_col_header ( table, column );选定指定的列的标题
226、tbl_select_cols_range ( table, from_column, to_column );在表里选定指定的几列
227、tbl_select_rows_range ( table, from_row, to_row );在表里选定指定的几行
228、tbl_set_cell_data ( table, row, column, data );设置表里某单元的内容
229、tbl_set_cell_focus ( table, row, column );设置表里焦点到某个单元
230、tbl_set_selected_cell ( table, row, column );在表里选定指定的单元
231、tbl_set_selected_col ( table, column );在表里选定指定的列
232、tbl_set_selected_row ( table, row );在表里选定指定的行
233、obj_click_on_text ( object, string [ ,search_area [ , string_def [ , mouse_button ] ] ] );点击一个对象的文本
234、obj_find_text ( object, string, result_array [, search_area [, string_def ] ] );返回一个对象字符串的位置
235、obj_get_text ( object, out_text [, x1, y1, x2, y2 ] );从对象里读取文本
236、obj_move_locator_text ( object, string [ , search_area [ , string_def ] ] );在对象里把鼠标焦点落在字符串
237、win_find_text ( window, string, result_array [, search_area [, string_def ] ] );在一个窗口返回字符串位置
238、win_click_on_text (window, string [ ,search_area [ , string_def [ , mouse_button ] ] ] );在窗口搜索文本
239、win_get_text ( window, out_text [, x1, y1, x2, y2] );从窗口指定的区域读取文本
240、win_move_locator_text ( window, string [ ,search_area [ ,string_def ] ] );在窗口里把鼠标焦点落在字符串
241、toolbar_button_press ( toolbar, button, mouse_button );点击工具栏按钮
242、toolbar_get_button ( toolbar, button_num, out_text );返回工具栏按钮名称
243、toolbar_get_button_info ( toolbar, button, property, out_value );返回工具栏按钮属性值
244、toolbar_get_button_num ( toolbar, button, out_num );返回工具栏按钮位置
245、toolbar_get_buttons_count ( toolbar, out_num );返回工具栏按钮的个数
246、toolbar_select_item ( toolbar, toolbar_item_chain [, mouse_button ] );选择类菜单工具栏的某项
247、web_browser_invoke ( browser, site );调用ie打开某个站点
248、web_cursor_to_image ( image, x, y );移动鼠标指针到某个图片
249、web_cursor_to_label ( label, x, y );移动鼠标指针到某个标签
250、web_cursor_to_link ( link, x, y );移动鼠标指针到某个链接
251、web_cursor_to_obj ( object, x, y );移动鼠标指针到某个对象
252、web_event ( object, event_name [, x , y ] );在指定对象运行一个事件
253、web_file_browse ( object );点击浏览按钮
254、web_file_set ( object, value );在文件类型的对象设置文本值
255、web_find_text ( frame, text_to_find, result_array [, text_before, text_after, index, show ] );返回帧内文本位置
256、web_frame_get_text ( frame, out_text [, text_before, text_after, index ] );返回帧内文本的内容
257、web_frame_get_text_count ( frame, regex_text_to_find, count );返回帧内标准表达式的事件个数
258、web_frame_text_exists ( frame, text_to_find [, text_before, text_after ] );检查帧内指定的文本字符串是否存在
259、web_get_run_event_mode ( out_mode );返回当前的运行模式
260、web_get_timeout ( out_timeout );返回winrunner响应web的最大等待时间
261、web_image_click ( image, x, y );点击一个图片链接或图片
262、web_label_click ( label );点击指定的标签
263、web_link_click ( link );点击朝文本链接
264、web_link_valid ( name, valid );检查url链接是否有效
265、web_obj_get_child_item ( object, table_row, table_column, object_type, index, out_object );返回对象的子对象的物理描述
266、web_obj_get_child_item_count ( object, table_row, table_column, object_type, object_count );返回对象的子对象的个数
267、web_obj_get_info ( object, property_name, property_value );返回对象属性的值
268、web_obj_get_text ( object, table_row, table_column, out_text [, text_before, text_after, index] );返回对象的文本字符串
269、web_obj_get_text_count ( object, table_row, table_column, regex_text_to_find, count ); 返回对象内标准表达式的事件个数
270、web_obj_text_exists ( object, table_row, table_column, text_to_find [, text_before, text_after] );在对象里如果该文本存在,返回该文本
271、web_refresh ( frame );winrunner重新连接指定的帧
272、web_restore_event_default ( );重新设置全部事件为默认值
273、web_set_event ( class, event_name, event_type, event_status );设置事件状态
274、web_set_run_event_mode ( mode );设置事件运行模式
275、web_set_timeout ( timeout );设置winrunner响应web的最大时间
276、web_set_tooltip_color ( fg_color, bg_color );设置webtest工具条的颜色
277、web_sync ( timeout );等待帧的导航完成
278、web_tbl_get_cell_data ( table, row, column, starting_pos, out_text, out_actual_text_length );
返回web表内指定单元的内容,开始于指定的字符
279、web_url_valid ( URL, valid );检查url是否有效
280、tbl_get_cell_data ( table, row, column, out_text );返回table里指定单元的内容(加载webtest)
281、tbl_get_cols_count ( table, out_cols_count );返回表的列数(加载webtest)
282、tbl_get_column_name ( table, col_index, out_col_name );返回表里指定列的标题的名称(加载webtest)
283、tbl_get_rows_count ( table, out_rows_count );返回表的行数(加载webtest)
284、web_password_encrypt ( password );将web页面的密码加密
285、set_window ( window [,time] );激活窗口并确定等待时间
286、win_activate ( window );激活窗口
287、win_check_bitmap ( window, bitmap, time [, x, y, width, height ] );比较窗口的位图
288、win_check_gui ( window, checklist, expected_results_file, time );比较窗口的gui数据
289、win_check_info ( window, property, property_value [, timeout ] );检查被请求的窗口属性
290、win_click_help ( window );在窗口点击帮助按钮
291、win_click_on_text (window, string [ ,search_area [ , string_def [ , mouse_button ] ] ] );在窗口搜索文本
292、win_close ( window );关闭窗口
293、win_drag (source_window, x, y [, mouse_button ] );从源窗口拖动对象
294、win_drop ( target_window, x, y );拖动对象到目标窗口
295、win_exists ( window [, time ] );检查窗口是否显示在屏幕上
296、win_find_text ( window, string, result_array [, search_area [, string_def ] ] );返回窗口里字符串的位置
297、win_get_desc ( window, obligatory, optional, selector, out_desc );返回窗口的物理描述
298、win_get_info ( window, property, out_value );返回窗口属性的值
299、win_get_text ( window, out_text [, x1, y1, x2, y2] );从窗口指定区域读取文本300、win_highlight ( window [, flashes ] );高亮显示窗口
WinRunner 编码规范
发布: 2008-9-25 15:49 | 作者: 网络转载 | 来源: 本站原创 | 查看: 14次 | 进入软件测试时代论坛讨论
1 路径不能写死
从一台机器拷贝到另一台机器上之后,WinRunner的脚本需要能够正常的运行。测试脚本所依赖的所有的东东(gui maps, text files, compiled modules, dll’s)都要和测试脚本有一样的父级目录。
例外:
如果确实有需要的话,指向K drive中的永久文件的路径可以写死。(警告:当脚本在不同的机器上运行,读取存放在K drive中的同样的文件的时候,有可能会出现问题。)
错误的示范:
reload("C:\\WR_TESTS\\Acceptance_6\\acceptance_functions");
正确的示范:
reload(getvar("testname") & "\\..\acceptance_functions");
2 采用缩进格式增强代码的可读性
错误的示范:
for(counter = count - 24; counter < count - 1; counter++)
{
list_get_item("ListBox",counter,item);
str = str & item & "\r\n";
}
正确的示范一:
for(counter = count - 24; counter < count - 1; counter++)
{
list_get_item("ListBox",counter,item);
str = str & item & "\r\n";
}
正确的示范二:
for(counter = count - 24; counter < count - 1; counter++){
list_get_item("ListBox",counter,item);
str = str & item & "\r\n";
}
3 尽量避免将测试外部环境的依赖写死不要将一些随着外部测试环境的变化而改变的信息写死。包括有:安装目录、DSN名、数据库服务器名、数据库用户名、数据库密码。最好在测试脚本的开始就将这些东东定义为变量,这样你就没有必要在环境变化后,在整个脚本中作多次的修改,只要改一个地方就好了。
错误的示范一:
set_window("SQLServer Login",10);
edit_set("Login ID:", "sa");
edit_type("Password:", "password");
正确的示范一:
db_username = "sa";
db_password = "password";
set_window("SQL Server Login",10);
edit_set("Login ID:", db_username);
edit_type("Password:", db_password);
错误的示范二:
invoke_application("C:\\iAvenue\\Windows\\UAdmin.exe","","c:\\Power_d b",SW_SHOW);
正确的示范二:
install_dir = "c:\\iAvenue\\Windows";
invoke_application(install_dir & "\\UAdmin.exe","",getvar("testname") & "\\..\Power_db",SW_SHOW);
WinRunner 脚本标准格式
发布: 2008-9-25 16:59 | 作者: 网络转载 | 来源: 网络转载 | 查看: 22次 | 进入软件测试时代论坛讨论
目录结构
存放目录要求:
1、根目录与项目名称相同,如江西移动BOSS测试目录为JXBOSS
2、根目录下应该是按子项目存放,如SALES、ACCOUNT。如果有公共脚本,存放在Share 目录下面
3、子项目下面应该根据功能/TestCase 来存放,如果有公共脚本也应该存放在Share 目录下
4、为存取及备份方便,目录不能使用中文。使用的名称应该尽量与开发保持一致
5、GUI 文件应该存放在脚本的同一目录,并且名称相同
6、正确性测试(使用完全正确数据来检查程序功能是否完成)目录名称规定为validity
以下是一个目录例子
JxBoss
-Sales
--ChangeSimCard
--validity
--CheckSimNoExistAnIdError
--Share
--Share
-Account
脚本要求
注释要求
脚本创建及修改说明注释
每个脚本的开头注释格式如下:
#脚本名称:文件名称
#创建人:创建人
#创建日期:格式为YYYY/MM/DD
#功能:脚本完成的功能描述
#运行前要求:运行前的要打开的窗口及状态要求、数据库中的数据要求、被测试程序运行目录等
#参考文档:描述录制代码是参考的有关设计测试文档
#修改历史:
# 修改人:
# 修改时间:格式为YYYY/MM/DD
# 主要修改内容:
注意创建人及修改人必须是中文完整姓名,不允许使用其它任何名称。运行前的要求一定要描述清楚
子功能注释
在各小段功能前应该加入功能注释,注意不能只是WinRunner自己产生的注释
如:
# insert a record
# Flight Reservation
set_window ("Flight Reservation", 1);
obj_mouse_click ("Button", 13, 16, LEFT);
obj_type ("MSMaskWndClass","101002");
list_select_item ("Fly From:", "London"); # Item Number 2;
list_select_item ("Fly To:", "Paris"); # Item Number 3;
obj_mouse_click ("FLIGHT", 56, 22, LEFT);
注释可以使用英文或中文。
修改代码说明注释
在具体修改的代码附近应该加入如下注释
#修改人
#修改日期
#修改原因/增加功能
注释可以放在一行中,简单修改可以忽略“修改原因/增加功能”,复杂修改应该不能忽略(简单及复杂标准待定)
代码要求
路径要求
代码中使用的路径都应该使用相对路径,不允许出现类似“d:\\”、“\\”下的代码,应该使用类似“..\\..\\”的代码。
在Script 里面打开和关闭GUI
各Script 的GUI 的文件应该分开保存在与Script 保存在同一个目录,应该使用用 GUI_load 在SCRIPT 开始以前就装载GUI,在SCRIPT 开始增加:
if (GUI_load(".\\login.gui")!=0)
{
pause ("Can't load login.gui");
texit;
}
在SCRIPT 完毕的时候加入
GUI_close(".\\login.gui");
关闭GUI,注意代码中的路径一定要使用相对路径。
错误报告
在使用错误报告的时候,应该注意包括出错的脚本文件名称,这样当脚本文件被其他脚
本调用时候,也能很清楚在什么地方没有通过。Report_msg 的参数格式定义为“文件名称:
错误描述”。同时鉴于WinRunner 的Check 函数不能提供清楚的错误报告,要求错误报告使
用以方式
if ( win_check_bitmap("Flight Reservations", "Img1", 1)!=E_OK) {
report_msg("DateCheck:月份输入错误提示不对!");
}
附件:一个完整的例子
#脚本名称:DateCheck
#创建人:谢慧强
#创建日期:2002/09/08
#功能:检查FLIGHTA 程序在输入错误月份的时候提示是否正确
#运行前要求:要求FLIGHA 进入定票窗口(New_Order 状态)且无任何数据输入
# 或者FLIGHTA 没有运行,这时候要求FLIGHTA。EXE 位
# 于E:\\Program Files\\Mercury
Interactive\\WinRunner\\samples\\flight\\app\\flight1a.exe #参考文档:无
#修改历史:
# 修改人:谢慧强
# 修改时间:2002/09/09
# 主要修改内容:不采用位图方式,改为直接判断字符串内容
#load gui file
#Flight Reservation
if (GUI_load(".\\DateCheck.gui")!=0)
{
report_msg ("DataCheck:Can't load .\\DateCheck.gui");
texit;
}
#Check windows exists ,if don't exist ,call login to open it.
# Flight Reservation
if (win_exists("Flight Reservation")!=E_OK){
#pause ("Windows Flight Reservation don't exist");
#texit;
call "..\\login\\login"();
}
#input error month
win_activate ("Flight Reservation");
set_window ("Flight Reservation", 3);
obj_mouse_drag ("Button_4", 17, 6, 17, 7, LEFT);
obj_type ("MSMaskWndClass","301212");
list_select_item ("Fly From:", "Denver"); # Item Number 0;
#check message bitmap
# Flight Reservations_1
set_window ("Flight Reservations", 3);
#2002/09/09 谢慧强
#if ( win_check_bitmap("Flight Reservations", "Img1", 1)!=E_OK) #static_check_info("Invalid month Entered.The month must be greater than 01 and less than
12.(static)","enabled",1);
if (static_check_info("CheckMessage","label","Invalid month Entered.The month must be
greater than 01 and less than 12.")!=E_OK)
#2002/09/09 谢慧强修改结束
{
report_msg("DateCheck:月份输入错误提示不对!");
}
button_press ("确定");
#close gui file
GUI_close(".\\DateCheck.gui");