我的地盘我做主! 博客:http://tester2test.cnblogs.com/   msn:win_soft@163.com

一段Winrunner的样例脚本

上一篇 / 下一篇  2007-03-13 17:02:00 / 个人分类:性能测试

TyO+C|4?0#########################################################################################################51Testing软件测试网D3?hw`0h0G
#51Testing软件测试网S'g Siv| a
# Test Name     : Date Boundary51Testing软件测试网;V}6C{M6] ~K7I
# Subject          : Open Order Form
"bIil] {0#51Testing软件测试网?VJY#S
# Description    : Checks that the input of illegal values in the Flight Date is blocked and that error messages
a%?R}?AL8f0#    appear.  The following input should be tested:51Testing软件测试网E8B6l&D0n+s@N_[-^
#     1. Flight Date Edit field is disabled when button is unchecked51Testing软件测试网3MdMaK?
#     2. Characters (not accepted)
sp lqHf` MuL0#     3. More than six numbers (not accepted)51Testing软件测试网5k sJ.RGl
#     4. Less than six numbers (OK is disabled)51Testing软件测试网Lj/px1I^
#     5. Invalid Month51Testing软件测试网Ke+rBNbQ)Au(J
#     6. Invalid date of the month51Testing软件测试网u2UF'@;uNZ"\
#     7. No entry
3E2? i'H:@rkc0i:@\E!{0#
*am9d'c;{;C0#51Testing软件测试网A"j$lH-Hlq
#########################################################################################################51Testing软件测试网bo:l&~S7W6Q#pd:W p

51Testing软件测试网fdd3X{6d-_

#static variables:51Testing软件测试网_~ Em`
static ret_val,date_str,i;51Testing软件测试网t P5Ae$k/S0i7U*r)Y"C
# Constant declaration51Testing软件测试网 o,Qy`8D;rEZ
static const DISABLED = FALSE;51Testing软件测试网6FV[N~9t

51Testing软件测试网@ Or,C7w,Wd3q\D

# Variable declaration.  Can be anything the user wants.
3[rK$l?&Z&s?8J!H0static date_string_of_chars  = "as/cd/ef";     # Used in STEP 2.  Characters (Not accepted).
0q3K|:? K0static date_seven_numbers = "12/34/567"; # Used in STEP 3.  More than six numbers not accepted.51Testing软件测试网aheN8y5M5H
static date_invalid_month    = "13/20/95";   # Used in STEP 5.  Invalid month.
a/lMWf3r0|E0static date_invalid_day        = "12/32/95";   # Used in STEP 6.  Invalid date of month.

X(V,U.l#h0 51Testing软件测试网 ^!zVd i J1W-fgo

static lib_path = getvar("testname") & "\\..\\flt_lib";51Testing软件测试网g%aXU4Bo1@

51Testing软件测试网/v;~1Ms"v2x

# Static function reinitialize ().  Reinitializes Flight Date to OFF and clears the edit field.
Dh+U#}6a,w3y|}0static function reinitialize ()51Testing软件测试网/?v x }4bP
{
]8aY6y X+o%M;P0 auto ret_val;51Testing软件测试网*`)dG7J!J5P
 set_window ("Open Order");51Testing软件测试网 | Z3TJ.|%HX,f+@ f
 obj_get_info ("FlightDateEdit", "enabled", ret_val);
(Q9h"GL'j0@Ke0 if (ret_val == TRUE) {
v$vgn$^B T0     set_window ("Open Order");51Testing软件测试网 rY/a v!f{!f]
  edit_set_insert_pos ("FlightDateEdit", 0, 0);
'?_(RcYC U0  type ("");
/cB[ dHW`A0 }51Testing软件测试网;z*{ p2jbV-xX
}51Testing软件测试网?$LIt|!y[u4b F

51Testing软件测试网6Nhh/lyl

# Static function insert_date ().  Inserts the date into the FlightDateEdit field.51Testing软件测试网&U w3X ?l*_cC
static function insert_date (in date)
{;ieA5Mm0{
G,X`_cKK\ F ~0 set_window ("Open Order");51Testing软件测试网/o~9n4L%gVUxqf
 edit_set_insert_pos("FlightDateEdit",0,0);
v{;M _;a { nY^0 type(date);51Testing软件测试网O;J/mtkA4fv
}51Testing软件测试网7?aSSS/A _

51Testing软件测试网7a5@R9~;u+\@M

reload(lib_path);

;c-l.B J5n8Q ]h"T0

Z}4A7FoC0# Open the flight application51Testing软件测试网,y%Rf-Rq8E
rc = open_flight();
V[{p bM#o^"~0if (rc == E_GENERAL_ERROR){
xN ^e@?3e4H9X$cu0  tl_step(initialization, FAIL,couldnt_open_flight);
B2mw7QT+e?sW0 clean_up();
[&}k z Ai)r#U5N|4n0 texit;
+QTrt!w0}51Testing软件测试网,e Q4n(X#Ey}

51Testing软件测试网o1I6_ R_1V6N(X-p'{

 51Testing软件测试网)uA3{B7Z!a1[

!O ]hf.U3GMw D-E0# Initialization.51Testing软件测试网Nv rB2cp
open_OpenOrderForm ();51Testing软件测试网-KRK?o[z

%X;Fi%r$x#Ca051Testing软件测试网!`9DvqM gJb8C#Fc
# STEP 1.  Flight Date Edit is disabled51Testing软件测试网dS6d3vT%A:K-p

51Testing软件测试网Z{@L%m

set_window ("Open Order");

Z T^?!kg+O)g,a0

@Q du$]y9s,ZV0# Checking to see if the edit field is disabled when button is unchecked
-G&o/sr@-AgU0obj_get_info ("FlightDateEdit", "enabled", ret_val);51Testing软件测试网dDND]&h#|e
if (ret_val == DISABLED)51Testing软件测试网B D-[[B zb7xs
 tl_step (disabled, PASS, flight_date_disabled);
&sl aBF*YlT0else
l2I(m L^w2G-dq0 tl_step (disabled, FAIL, flight_date_not_disabled);
1~l UW0V0reinitialize ();51Testing软件测试网e4Qxr"A

/nRv1NB)CW(y051Testing软件测试网8U I.Z8]H'Q2~ Xf
# STEP 2.  Characters (not accepted)51Testing软件测试网k$G qL,B],q Qy

51Testing软件测试网%aA6H(B+b_O

button_set ("Flight Date", ON);

5sr_Xi*R#o)R0 51Testing软件测试网\R2}vs7\9| s%vQqZ

# Inserting a date of characters using variable, "date_string_of_chars", defined above.
"f6xZ'`%cS0insert_date (date_string_of_chars);
7Rm)t%P:he cqz0edit_get_text ("FlightDateEdit", date_str);51Testing软件测试网+Q-B0J9oxj

51Testing软件测试网8A BwJBtw y@@

# Checking to see if application handled illegal open order procedure51Testing软件测试网*i2j!R~&U
if (date_str == "__/__/__")51Testing软件测试网F(x9Q%|w#^v
 tl_step (characters, PASS, chars_not_accepted);51Testing软件测试网Sr Fhf
else
&dRX v+~"iTr1mH0 tl_step (characters, FAIL, chars_accepted);
1^wi!_"n |W5X)r0reinitialize ();

-_0ci5QU8aQ0

V%aS+Hm,q0# STEP 3. More than six numbers (not accepted)51Testing软件测试网9E CU"w,`_cV9C^2j q

*~mwq gn-V0button_set ("Flight Date", ON);51Testing软件测试网@8a E9n@u
# Inserting a date consisting of more than six numbers using variable, "date_seven_numbers", defined above.
u4~p#`9]S tS0insert_date (date_seven_numbers);51Testing软件测试网nBAv,R0go4\_
edit_get_text ("FlightDateEdit", date_str);

7hM t#s1Z+j;S0Q0 51Testing软件测试网;A,L gv_

# Checking to see if application handled illegal open order procedure
"U*U+S"Zv q-h0if (date_str == "12/34/56")51Testing软件测试网L#k~+J.MX1]O
 tl_step(more_than_six, PASS, more_than_six_not_accepted);
.yu ^tN2N ^0else51Testing软件测试网C4b.m K['}cTt
 tl_step(more_than_six, FAIL, more_than_six_accepted);51Testing软件测试网:C6ygL2M/`z'Bn&r
reinitialize ();

)jJ:b9m @d0 51Testing软件测试网i$zE2XkE

# STEP 4. Less than six numbers (OK is disabled)

\EcQh2_ ^X~}0 51Testing软件测试网6\ Z3FfU

edit_set_insert_pos ("FlightDateEdit", 0, 0);51Testing软件测试网V4J%R-?}

:V6k Q#mz G-G TF0# Using for_loop to systematically check if OK button is disabled for any date with less than six numbers in it51Testing软件测试网)j#E._VKISZR
for (i = 1; i <= 6; i++) {
C.A6v Uk ^2kl Q0 type(i);
+k}H*F#cZ&mU qy0 if (button_check_enabled ("OK", TRUE) == E_OK)
k"bDyHz7k}'{N0  break;

9oO4v ['BXd0 51Testing软件测试网gI%]5d dp|

}51Testing软件测试网"w @,`#E&q4ni l

51Testing软件测试网{~o8zC `

#  The actual check to make sure that OK was disabled for date less than six numbers
w[9B_p'~E0ts_msg = sprintf(ok_not_disabled, i);
2E3eh&} c|J0if (i < 6)
%{ ~@?:{N"@0 tl_step (less_than_six, FAIL, ts_msg);
*P3@ f3nKR gt2{$Q0else
&baa6\)|i a0 tl_step (less_than_six, PASS, ok_disabled);51Testing软件测试网H5T4^$C*o z;t1C
reinitialize ();51Testing软件测试网\{,gi0TD5Ib

'C5}L BHa7x:M^O7K0# STEP 5. Invalid Month51Testing软件测试网*er$fGI+p@ I _}

51Testing软件测试网Z.h kT-PP

set_window ("Open Order");51Testing软件测试网6jLhk Gm!Vt
# Inserting a date with an invalid month using variable, "date_invalid_month", defined above.
Z8_RTy7smyS5Vh0insert_date (date_invalid_month);

HL XJ1m#iK0

ZE"wfr7nxs0# Checking to verify that unless there is a valid month, an error message will pop up when trying to press "OK"
hK%Q7_J'z0set_window("Open Order");51Testing软件测试网;e(j D_a2w
button_press("OK");51Testing软件测试网J$c/q U4dEb~,J
if(win_exists("Flight Reservation Message",10) != E_OK){
Y%D D[(W'G/y V0 tl_step (invalid_month, FAIL, invalid_month_msg_popup);51Testing软件测试网'a#E+Q jR0X8z.I
 clear_main_window();51Testing软件测试网%F:\5C T [9_$C J9J
 open_OpenOrderForm ();
'QH J+X/LM0}51Testing软件测试网9R*M{q,y-TYYy
else{
4O`a WMhx$S-vh0 set_window("Flight Reservation Message");51Testing软件测试网2~+lvw OU
 static_get_text("Message", txt);
vh5X2pH8?0 if(txt !=invalid_month_entered_msg)
FfjPg"X%X0  tl_step (invalid_month, FAIL, invalid_month_wrong_msg);51Testing软件测试网7kal6N'p ]fKa
 else51Testing软件测试网kih:Q-@7U Vj
  tl_step (invalid_month, PASS, invalid_month_correct_msg);
3vX/Zwdy]0 button_press("OK");51Testing软件测试网 t4pV `ox
}
G ?t6\i%J:@D?0reinitialize ();

_1T!n6i F)KJ2G0

E/|X_~x }f051Testing软件测试网8v:efJA:m$V
# STEP 6.  Invalid day of month.

hc_ p%F'I5u6}3`u0

? M7@-W sLmd%L0set_window ("Open Order");
n%@(AI5X,JZ0p0# Inserting a date with an invalid day using variable, "date_invalid_day", defined above.
wP/D&\ a ~Tw l}z0insert_date (date_invalid_day);51Testing软件测试网};xW6b&b d#},n8xgf

51Testing软件测试网B8i0I|cG1`:t[

# Checking to verify that unless there is a valid day of the month the "OK" button will be disabled
O!gQv/i-c M'P0set_window("Open Order");
g1u\"O5HLf8o^U0button_press("OK");
P:M M(hAO0L9r4Z0if(win_exists("Flight Reservation Message",10) != E_OK){51Testing软件测试网.^Lo#s};D1H8C/O d
 tl_step (invalid_day, FAIL, invalid_day_no_err_msg);51Testing软件测试网D@ tkWH9P7f?
 clear_main_window();
Dx]n#qTl v~@0 open_OpenOrderForm ();51Testing软件测试网5\nY4~0a/Vx[
}51Testing软件测试网`O+o)Bge
else{
0R/G\[c C7i7j^H0 set_window("Flight Reservation Message");
-n:Cpf_A4p)op0 static_get_text("Message", txt);
tm%U]lDy0 if(txt !=invalid_day_entered_msg)51Testing软件测试网8kl"T/}4zo
  tl_step (invalid_day, FAIL, invalid_day_wrong_err_msg);51Testing软件测试网VQ7?zn a/o%X7@7U,M
 else
{ykZ7][M5Nf0  tl_step (invalid_day, PASS, invalid_day_not_accepted);51Testing软件测试网0r }-Ok9j8S+e'~
 button_press("OK");
v0f a wt:e"D Bad0}
8\ _*q5`+P0reinitialize ();

vT]*R.mL4wP0 51Testing软件测试网f6yr0{(C#xq,r'P


2d1f OF2Y4vI.~e0# STEP 7.  No Entry.

)b |P:wm!V mS0 51Testing软件测试网 ?S$P2El}u&}

set_window ("Open Order");
qD}A~+soK:C0# Inserting no date to see if OK is disabled.
?.b0nL:o'x;S0insert_date ("__/__/__");51Testing软件测试网I7Ck(Wt c

1|/o/|O7H|H0# Checking to see if OK is disabled without any date set in edit field51Testing软件测试网0T)?-_$O;M.Y~6h
if (button_check_enabled ("OK", TRUE) != E_OK)
6e?i$V|U8\+@0 tl_step (no_entry, PASS, ok_button_disabled);
0H)R9vJ2y0else
)Wb@z I0 tl_step (no_entry, FAIL, ok_button_enabled);51Testing软件测试网?|8X3VP0sUU%Fc.`

51Testing软件测试网u o2a,D pX:u Y:U

51Testing软件测试网1js&hh%bA@#s9G#{ Y
# Returning to initial state.
B f6i9K|0button_press ("Cancel");
a8K:hjxy0clean_up();51Testing软件测试网!V i(L,@f4_^ap_

51Testing软件测试网1V C l`6z


*ZK#Bru x'h0# End of test.51Testing软件测试网!Q2VS0A$xq/U_
51Testing软件测试网i V a6CS$}#^7V

51Testing软件测试网5M:H3d9Y;H*M3b3Ya!L

|-dCNl2VZ*pmJ0
测试者家园 2006-12-08 09:24 发表评论
51Testing软件测试网DOc0kG3M a(K+y9H f

"B,H hSy,P&~0Link URL: http://www.cnblogs.com/tester2test/archive/2006/12/08/586031.html

TAG:

 

评分:0

我来说两句

Open Toolbar