WR中的数据驱动和脚本调用
上一篇 / 下一篇 2006-12-28 23:49:21 / 个人分类:Winrunner 技术
使用数据驱动来测试Windows自带的计算器,并调用一个Compiled Module进行比较实际结果和预期结果是否相符,将其写入指定文件中。
(an'D^)^+Q6f`c051Testing软件测试网iBSP(l` p%{下述脚本在WR 7.6上调试通过。51Testing软件测试网w2O-w l*dbV/k|
.a9|Ov#X,c&I#e
h#hg0#################################################################################
ZL%z+C}(W0#scrīpt Name: calcDataDriver
z/dQm[L/Kh0#Test Type: Main Test
| t{"ZO7[l)V-Iu0#51Testing软件测试网RYGT1{g|a(A
#Function Descrīption: Using Data Driver to test calc.exe, and call a compiled #module to compare the Actual Result with the Expected Result. 51Testing软件测试网+D&r1eF]*cZ9}$dl[]
#################################################################################
I
e8{E0_!b}051Testing软件测试网+iT9mMD%T
k7E0q
if (load("compareResult")==1)
%DB7Kf8J0{51Testing软件测试网S_Y,[!I#^%xs1\
report_msg("Compiled Module failed to load!");51Testing软件测试网M
?tU;LJ*R
texit;
#l/r}
M(NVz~0}51Testing软件测试网^$Y&D\d2|
if(GUI_load("C:\\calc.gui")!= E_OK)51Testing软件测试网7aKk Y.UJ_
{51Testing软件测试网$A%O
{g%hR{x
report_msg("GUI failed to load!");
c-ywOO0 texit;51Testing软件测试网9i dr.h4i!m'}
}
J/YX2k@-|R0myResultLog = "C:\\myResultLog.txt";
-LY.s7K*? ~Y:d/L(C0table = "C:\\data_text.xls";51Testing软件测试网9Vj#kg%och0a
rc = ddt_open(table, DDT_MODE_READ);51Testing软件测试网k"Wf&X2gU
if (rc!= E_OK && rc != E_FILE_OPEN){51Testing软件测试网On4IB F1K2eaU*~_
pause("Cannot open table.");
La h$F
~_^:Ul0 texit;51Testing软件测试网:F$nN;N)H J3d
}
f LHGn6P_#B
Z9k0if(invoke_application("C:\WINDOWS\system32\calc.exe","","C:\WINDOWS\system32\calc.exe",SW_SHOWNORMAL)!=E_OK){
\JYaP u?*gQ'kP0 report_msg("程序未正常打开");51Testing软件测试网)Y&bf|)R"l
texit;
_oWv+B]H0}51Testing软件测试网;un3o9lLN{*Y;D
else{51Testing软件测试网T&u+V+o7CA^
ddt_get_row_count(table,table_RowCount);51Testing软件测试网Rh,w)w9j
for(table_Row = 1; table_Row <= table_RowCount; table_Row ++)
1x!FO!G$g`\y&Tf1{0 {51Testing软件测试网;g+X
oM!]%q8n4[f
ddt_set_row(table,table_Row);
,W.o(LsGA8RxD&m0 str1 = ddt_val(table,"Data1");
l(C!gzp]0 n1 = length(str1);51Testing软件测试网 PfN q5M
# 计算器
A R,@'DkW0 set_window ("计算器", 1);51Testing软件测试网N I^Y.~/OV:DLG
#判断驱动表中的数字是否为个位数,并根据实际情况键入相应数字。51Testing软件测试网vI!L7P3d
mvxr@
if ( n1 > 1){
#GiElzPq%J$H4B0 for(i=1;i<=n1;i++){
m)Y$_@1KGcf0 inputData1 = substr(str1,i,1);51Testing软件测试网d XbYG
button_press(inputData1);
Q s;sa
G.[0 }51Testing软件测试网]/x&a-o0R
B
}
!N;W,B`;b1z&z&h]T0 else{
5}s v`/? Z!l0 button_press(str1);51Testing软件测试网)McEcL
}
J:P2B
@LW0#键入操作符 51Testing软件测试网ZUsU`R+@M/S
button_press (ddt_val(table,"Operator"));51Testing软件测试网MC"yE7b:MB?
51Testing软件测试网T.HV+D/y
d5ck+z.Jo
str2 = ddt_val(table,"Data2");51Testing软件测试网E;J-Fn:f ha8i
n2 = length(str2);
WR^4jNf|0V_0 if ( n2 > 1){51Testing软件测试网+Ch7uz|i/I"L.]
for(i=1;i<=n2;i++){
8y'K'|U\+Q-Sb*@0 inputData2=substr(str2,i,1);
h
?d)p:O6Le HD0 button_press(inputData2);
1[;BQn8]Qy?0 }
1?9j)C&^#Z@${0 }51Testing软件测试网0`#M["Iv7v&p{8r
else{
g)nf3]-oc"yuGW.^0 button_press(str2);
/}!j-`#`:~0 }
-`
^9X X2z0 button_press ("=");
N2D1y0{RIZ$A0 edit_get_text ("Edit",actResult);
#QdAJE*L,~
GI0#比较实际结果和预期结果,并将最终结果写入指定文件中。
n*I&gd_d8?[ t0 compareResult(actResult,ddt_val(table,"expResult"),myResultLog);51Testing软件测试网$B$V`Yrg
51Testing软件测试网0X!h7|XV6|"W5yRa}