|
1.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\"");
2.在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); |
|