WinRunner的问题整理

发表于:2007-04-22来源:作者:点击数: 标签:问题整理winrunnerReal如何
1.WinRunner如何把Real类型转化为指数表示方法 答:指数类型转化为real类型,可以通过下边的代码 var = 5.3569E+10; pause(var); #显示 53569000000 Real类型转化为指数表示方式 var = sprintf("%e",53568544768); pause(var); #displays 5.356854e+010 2.什

 1.WinRunner如何把Real类型转化为指数表示方法
 
  答:指数类型转化为real类型,可以通过下边的代码

clearcase/" target="_blank" >cccccc>var = 5.3569E+10;
pause(var);
#显示 53569000000


  Real类型转化为指数表示方式

var = sprintf("%e",53568544768);
pause(var);
#displays 5.356854e+010

  2.什么是同步点,怎样用它?他和Wait有什么不同?
    答: 从功能上他们都可以实现脚本和被测试程序同步的问题,不过同步点有window/object,bitmap方式,她等待的是某个等待的对象窗体,bitmap的出现,一定程度她也可以作为验证点wait这点上无法实现相同的效果。有的脚本中即使你加入wait,但是你无法知道下边的对象窗体图片是否就是成需要运行的正确出现的

  3.tl_step和tl_step_once的区别
  答:tl_step和tl_step_once都是把运行状态信息放到运行结果中去,区别在如果连接TD,TL_STEP把每步状态信息都插入到测试结果中去,tl_step_once如果连接td,只是插入一次运行步骤的名字

代码例子:
--------------------------------------------------------------------------------

for (i=1;i<4;i++){
tl_step("Step", PASS, "reporting step, #" &i);
tl_step_once("Step Once", PASS, "reporting step once, #" &i);
}

--------------------------------------------------------------------------------

WR中的报告:
Step: Step, Status: PASS, Description: reporting step, #1
Step: Step Once, Status: PASS, Description: reporting step once, #1
Step: Step, Status: PASS, Description: reporting step, #2
Step: Step Once, Status: PASS, Description: reporting step once, #2
Step: Step, Status: PASS, Description: reporting step, #3
Step: Step Once, Status: PASS, Description: reporting step once, #3

TD中的报告:
Step: Step, Status: PASS, Description: reporting step, #1
Step: Step Once, Status: PASS, Description: reporting step once, #1
Step: Step, Status: PASS, Description: reporting step, #2
Step: Step, Status: PASS, Description: reporting step, #3

 4.WinRunner和TD集成后脚本运行很慢是什么原因呢?
  答:安装TD和WinRunner服务器上需要独占100GByte,TD需要10OGHZ时钟速度16GB RAM的处理平台

 5.WR是否支持vs.net
  根据Mercury的介绍,他们的对.Net的支持转移到QuickTest Pro上了,如果你需要自动化测试.Net程序(不是web的),建议用

 QuickTestPro。也就是说wr不支持vs.net开发的程序 6.我对比两个文件file1.txt和file2.txt,文本内容如下
file1.txt 内容如下:
10523 8315 6804 8387 3643 4550 3457 3649

file2.txt内容如下:
190176 155737 117417 145194 65314 81431 64522 63324

代码如下:file_compare("C:\\file1.txt","C:\\file2.txt","save");

  6. 为什么每次对比这两个文件结果都是通过的。
  答:这个问题的原因在于它在前面的脚本中对文件进行了操作,没有关闭,所以这段代码运行总是通过

 7.如何在winRunner中用Windows的API函数
在使用该API函数前需要先加载该函数然后声明API函数,代码如下

load_dll("user32.dll");
extern int PostMessageA(in long, in long, in long, in long);
win_get_info("{class:window, MSW_class:AfxMDIFrame42, label:\"!WinRunner.*\"}", "handle", hWnd);
PostMessageA(hWnd, 16, 0, 0);

 请在尝试以上代码的时候,保存脚本,呵呵!

 8.怎样处理跟踪键盘操作?
  答:下边的代码希望对你有帮助

function GetKeyStatus(in vKey){
auto pid, thread_id, win_desc, hWnd, KeyState, win_log_name, win_full_desc, focused_obj_desc;
win_desc = "{active:1}";
if (win_exists(win_desc)==0) {
win_get_desc(win_desc, "", "", "", win_full_desc);
GUI_map_get_logical_name( win_full_desc, "", win_log_name, "bla");
win_get_info(win_desc, "handle", hWnd);
pid = GetWindowThreadProcessId(hWnd, NULL);
thread_id=GetCurrentThreadId();
AttachThreadInput(pid,thread_id,TRUE);
KeyState=GetKeyState (vKey);
AttachThreadInput(pid,thread_id,FALSE);
if (KeyState < 0)
return(0); # Key is pressed
else
return (1); # Key is not pressed
}
else
return (-1); # No active window found, so cannot determine key state
}

 9.WinRunner如何处理excel?
  答:其实解决方法有很多,这里列举两种。
  一.利用其他语言特性开发出dll提供给winrunner使用(vb,vc,delphi等)
  二.在其他环境中实现,用winrunner调用
  第一种我在这里不举例子了,第二种我利用vbs往excel中赋值给大家提供一种思路,代码如下:

'vbs中的代码
Dim ExcelApp
Dim itemX
if WScript.Arguments.Count < 2 then
r = msgbox("Requires 2 arguments", 48, "change_sheet")
else
dim fso
set fso = createobject("scripting.filesystemobject")
xlBook = fso.GetAbsolutePathName(WScript.Arguments(0))
xlSheet = WScript.Arguments(1)
set fso = Nothing
Set ExcelApp = CreateObject("Excel.Application")
ExcelApp.Workbooks.Open(xlBook)
Set itemX = ExcelApp.ActiveWorkbook.Worksheets.Item(xlSheet)
itemX.Activate

excelApp.ActiveWorkbook.Worksheets(xlSheet).Range("A1").Select
excelapp.ActiveCell.FormulaR1C1 = "1"
excelApp.ActiveWorkbook.Worksheets(xlSheet).Range("B1").Select
excelapp.ActiveCell.FormulaR1C1 = "2"
excelApp.ActiveWorkbook.Worksheets(xlSheet).Range("c1").Select
excelapp.ActiveCell.FormulaR1C1 = "3"

ExcelApp.ActiveWorkbook.Save()
ExcelApp.ActiveWorkbook.Close(1)
ExcelApp.Quit()

Set itemX = Nothing
Set ExcelApp = Nothing

end if

winrunner中的调用代码:
dos_system("wscript \"C:\\excel_sheet.vbs\" \"C:\\SheetBook.xls\" \"Sheet2\"");

 10.在WinRunner中如何实现得到transaction时间?
  答:一般情况下transaction的时间只能在最后结果中得到,如何在脚本得到这个时间呢,下边的代码可以

 帮助你:

public transactions[];
function start_my_transaction(in transaction_name)
{
transactions[transaction_name] = get_time();
tl_step("Start transaction: \"" & transaction_name & "\"",PASS,"Timestamp: " &

transactions[transaction_name]);
return (transactions[transaction_name]);
}
function end_my_transaction(in transaction_name)
{
auto end_time = get_time();
auto rc;
if(transactions[transaction_name] == "")
{
tl_step("End transaction: \"" & transaction_name & "\"",FAIL,"Transaction was

never started.");
rc = -1;
}
else
tl_step("End transaction: \"" & transaction_name & "\"",PASS,"Elapsed Time: "

& (rc = end_time - transactions[transaction_name]));
delete transactions[transaction_name];
return rc;
}

start_my_transaction("my_transaction");
wait(2);
rc = end_my_transaction("my_transaction");
pause("Elapsed time = " & rc);

原文转自:http://www.ltesting.net