0% found this document useful (0 votes)
321 views122 pages

Learn QTP

I) QuickTest Professional (QTP) is a test automation tool launched in 2002 that allows users to create automated tests using a keyword-driven approach and supports testing of graphical user interfaces, web applications, and some non-UI operations. QTP supports various programming languages and testing frameworks and can be integrated with other HP testing tools. It provides features like object repositories, data-driven testing capabilities using Excel-like data tables, and visual/expert test script views.

Uploaded by

bkrishnasah
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
321 views122 pages

Learn QTP

I) QuickTest Professional (QTP) is a test automation tool launched in 2002 that allows users to create automated tests using a keyword-driven approach and supports testing of graphical user interfaces, web applications, and some non-UI operations. QTP supports various programming languages and testing frameworks and can be integrated with other HP testing tools. It provides features like object repositories, data-driven testing capabilities using Excel-like data tables, and visual/expert test script views.

Uploaded by

bkrishnasah
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 122

QuickTest Professional 10.

00
I) Basic features of QTP......................................................................................................2 Version History of QTP...............................................................................................3 QTP supports almost all industry leadin tec!nolo ies" #ut #y default it does not support" $it! respect to add in license it supports...........................................................3 T!is menu pro%ides &ecord" &un options and &un settin options ..............................1' (#)ect &epository* ........................................................................................................1+ It is a stora e place of QTP $!ere $e can store t!e o#)ects information and it also acts as interface #et$een t!e test script and t!e ,-T in order to identify t!e o#)ects durin e.ecution........................................................................................................................1+ VB /cript...........................................................................................................................'0 1.3 Hostin 1n%ironments and /cript 1n ines..................................................................'2 1.' ,%aila#le /cript 1n ines .........................................................................................'3 '.1 Variant /u#types......................................................................................................02 '.2 ,rit!metic (perators*..................................................................................................03 2) ,ddition (perator 45)....................................................................................................03 3) /u#traction (perator 46).................................................................................................03 7) 8oncatenation (perator 49)..........................................................................................03 '.3 8omparison (perators.................................................................................................0' '.' 8oncatenation (perators .............................................................................................0' 2) 8oncatenation (perator 49)..........................................................................................0' '.0 :o ical (perators.........................................................................................................0' 1) ;ot.............................................................................................................................0' 2) ,nd............................................................................................................................0' 3) (r ..............................................................................................................................0' ') <or.............................................................................................................................0' 7.1 =akin >ecisions -sin If...T!en...1lse.................................................................02 +) :oopin T!rou ! 8ode.................................................................................................2' +.1 -sin >o :oops.......................................................................................................20 ?e can use >o...:oop statements to run a #lock of statements an indefinite num#er of times. T!e statements are repeated eit!er $!ile a condition is True or until a condition #ecomes True. ...............................................................................................................20 +.2 ?!ile...?end /tatement..............................................................................................22 1.ample*........................................................................................................................22 +.3 @or...;e.t /tatement....................................................................................................23 +.' @or 1ac!...;e.t /tatement...........................................................................................23 10) VB /cript Procedures..............................................................................................27 11.1 /u# Procedures.......................................................................................................27 11.' -sin /u# and @unction Procedures in 8ode........................................................30 13) 1rrors...........................................................................................................................73 13.1 VB/cript &un6time 1rrors.........................................................................................73 13.2 VB/cript /ynta. 1rrors.............................................................................................73

I) Basic features of QTP


o o o o o o o o o o o QTP Launched in 2002 (Nov). By Mercury Interactive. Later taken over by HP, in 200 . QTP i! an "b#ect Ba!ed Te!tin$ Too%. QTP i! &or &unctiona% and 'e$re!!ion Te!tin$. It &o%%o(! )ey(ord driven a**roach. It !u**ort! +indo(! "*eratin$ ,nviron-ent on%y. It !u**ort! ./I ba!ed (.ra*hica% u!er inter&ace) and +eb ba!ed 0**%ication! 0uto-ation, doe! not !u**ort 1/I (1o--and u!er inter&ace) 0**%ication!. It ha! -u%ti%in$ua% !u**ort. (It !u**ort! ,n$%i!h, 1hine!e, 2a*ane!e, )orean, etc %an$ua$e! (ith re!*ect to %icen!e.) It ha! ada*ted Micro!o&t 3i!ua% Ba!ic 4cri*tin$ edition &or *ro$ra--in$ and e5ce% %ike !*read !heet &or 6ata driven te!tin$. 4QL (4tructured 7uery %an$ua$e) e-bedded or in!erted (ith QTP, !o (e can u!e 4QL !tate-ent! direct%y &ro- QTP. It can be inte$rated (ith other Too%! %ike +in'unner and Qua%ity 1enter. It can be u!ed &or u!er inter&ace (/I) te!t ca!e auto-ation and !o-e %i-ited (Non /I) Te!t ca!e auto-ation %ike 8i%e !y!te- o*eration! and 6ata ba!e o*eration!. It (a! derived &ro- 0!tra QuickTe!t (-other too% o& QTP). It !u**ort! I, (Internet ,5*%orer) on%y &or recordin$ te!t!, &or e5ecution it !u**ort! other bro(!er! %ike Mo9i%%a and 0"L, o*era ,tc a*art &ro- I,. QTP i! a 6e!kto* 0**%ication (I:Tier;4tand a%one). QTP ha! t(o ty*e! o& Licen!e, <. 4eat or Node %ocked Licen!e, 2. 1oncurrent or &%oat %icen!e. 4eat %icen!e &or one !y!te- and 1oncurrent Licen!e, (e can u!e &or any !y!te- but one u!er at any ti-e. I& (e (ant -u%ti*%e concurrent %icen!e! (e can *urcha!e. o QTP ha! /NI code !u**ort.

o o o o

Version History of QTP


0!tra Quick te!t (Mother too% o& QTP) <.0 to =.0 Quick Te!t Pro&e!!iona% =.> ? Nov 2002 >.= ? 200@ A.0 ? 200B A.2, A.@ ?200= C.0,C.<:200> C.2: 200 -ercury interactive C.= ?200A H.P <0.00 ?200C 2anuary

Add-In Manager
QTP !u**ort! a%-o!t a%% indu!try %eadin$ techno%o$ie!, but by de&au%t it doe! not !u**ort, (ith re!*ect to add in %icen!e it !u**ort!. 6e&au%t 0dd: in! o& QTP areD 0ctive5 3i!ua% ba!ic +eb.

"ther avai%ab%e 0dd In! areD .N,T, 2ava, Peo*%e !o&t, 4iebe%, T, (Ter-ina% ,-u%ator!), 40P &or ./I, 4a* &or +eb, "rac%e 0**!, +eb 4ervice! etc. 6urin$ QTP %aunchin$ it !ho(! 0dd in -an$er dia%o$ bo5, 0dd in Man$er %i!t! out a%% avai%ab%e 0dd In! in the co-*any. /!er need! to !e%ect a**ro*riate 0dd In! &or hi! a**%ication or 0/T. "ne can !e%ect -ore than one 0dd In! a%!oE i& (e !e%ect unnece!!ary 0dd In! QTP *er&or-ance (i%% be reduced.

Launching QTP
+e can %aunch QTP BF !e%ectin$ de!kto* icon other(i!e !tart G *ro$ra-!G QTP Pro&e!!iona% G QTP. 6urin$ %aunchin$ it !ho(! 0dd:In Mana$er.

Add-in manager window 4e%ect a**ro*riate 0dd In! and c%ick okay. Quick Te!t Launche!

'

II) Key

!ements of QTP Too! "indow

QTP Too! "indow #) Test Pane$

It i! *ro$ra--in$ inter&ace o& QTP, u!ed &or creatin$, editin$, vie(in$ and de%etin$ te!t !cri*t!. Test$ It i! a !et o& !tate-ent! or !et o& one or -ore action!. (It i! a %oca% conce*t) Action$ It i! a !et o& 4tate-ent!. (It i! a %oca% conce*t) %tatement$ 0 -ini-a% e5ecutab%e unit. 4tate-ent! -ay have key(ord!. ()ey(ord !uch a! &unction, -ethod, !tate-ent etc). It i! a $%oba% conce*t. Te!t *ane ha! 2 vie(!. &'ert (iew: Te!t in 3B !cri*t &or-at.

QTP Test Pane- &'ert View Key word (iew: Te!t in Icon ba!ed ./I &or-at.

QTP Test Pane-Keyword View Note<D Here in te!t *ane Te!t i! !a-e but vie(! are di&&erent, i& you *er&or- any -odi&ication! in one vie( tho!e auto-atica%%y re&%ect! in another vie(. Note 2D Technica% u!er! u!e e5*ert vie( and bu!ine!! u!er u!e key (ord vie(. Note @D /!er can cu!to-i9e Te!t *ane vie( o*tion!. Navi$ationD Too%! MenuG vie( o*tion!G (e can u!e &ont !i9e and co%or! etc. )) Acti(e %creen It ha! an o*tiona% e%e-ent o& QTP, it take! !na* !hot! o& every !tate-ent that u!er *er&or-ed action or o*eration on 0/T.

It can be u!ed &or under!tandin$ and editin$ the te!t ea!i%y. Navi$ationD 3ie( -enuGactive !creen (&or %aunchin$ and c%o!in$) 1on&i$urin$ active !creenD vie(Go*tion!Gactive !creen tabGincrea!e ;6ecrea!e ca*ture %eve%, a**%y and okay. Note <D .enera%%y novice te!ter! u!e thi! &eature but it occu*ie! %ot o& -e-ory !*ace on QTP.

Acti(e %creen

*) +ata Ta,!e It ha! an inte$rated !*read !heet (,5ce% %ike), u!ed &or 6ata driven te!tin$. Navi$ationD 3ie( -enuG6ata tab%e (&or %aunchin$ and c%o!in$) 6ata driven Te!tin$D Te!tin$ the !a-e ta!k(4) or !a-e o*eration (ith -u%ti*%e !et! o& te!t data. It can be u!ed in t(o (ay!. <. ,nter te!t data direct%y into 6ata Tab%e and u!e. 2. I-*ortin$ data &ro- e5terna% &i%e! (8%at &i%e!, e5ce% !heet!, etc) and 6ata ba!e! (M4 acce!!, 47% 4erver, orac%e, etc.) It ha! t(o ty*e! o& !heet!. <. .%oba% 4heet: &or entire te!t ;u!ed &or a%% action! in the te!t. 2. 0ction 4heet!: &or !*eci&ic action on%y. 6ata tab%e avai%ab%e in 2 (ay!D <. 6e!i$n ti-e data tab%e. (0ttached (ith every te!t) 2. 'un ti-e data tab%e. (0vai%ab%e in re!u%t (indo() 'un ti-e i! a carbon co*y o& de!i$n ti-e data tab%e. QTP ha! 6ata tab%e -ethod! &or *er&or-in$ o*eration! on data tab%e.

QTP Too! window- +ata Ta,!e -) +e,ug Viewer It i! u!ed &or %ocatin$ and recti&yin$ or &i5in$ error!. It can be u!ed &or debu$$in$ the te!t! by !te*:by:!te* e5ecution. +e u!e !te* into, !te* over and !te* out co--and! &or debu$$in$. (debu$ co--and!)

10

Throu$h 6ebu$ vie(er u!er can (atch variab%e! and chan$e va%ue! o& variab%e! te-*orari%y. Navi$ationD 3ie( -enuGdebu$ vie(er (&or %aunchin$ and c%o!in$)

QTP Too! "indow-+e,ug Viewer .) Missing /esources It can be u!ed &or !ho(in$ -i!!in$ re!ource! tho!e attached to current te!t !uch a! (recovery !cenario!, %ibrary &i%e! etc).

11

Navi$ationD 3ie( -enu G-i!!in$ re!ource! (&or %aunchin$ and c%o!in$) 0) Information Thi! *ane !ho(! !ynta5 error! auto-atica%%y durin$ !avin$ the te!t. Navi$ationD vie( -enuG in&or-ation

QTP Too! "indow-Information Pane 1) QTP 2ommands QTP 1o--and! are avai%ab%e in @ (ay!.

12

<. Menu o*tion! 2. Too% Bar o*tion! @. 4hort cut key! (&or 4o-e i-*ortant o*eration! on%y)

3i!e menu$ Throu$h &i%e -enu u!er can create, !ave te!t!, o*en e5i!tin$ te!t!, e5*ort te!t! in 9i* &or-at. dit Menu$ It *rovide! editin$ o*tion! and rena-in$, de%etin$ and !*%ittin$ action!. View menu$ Throu$h thi! -enu (e can %aunch and c%o!e, active !creen, 6ata Tab%e, 6ebu$ vie(er, in&or-ation, -i!!in$ re!ource! etc. Insert Menu$ Throu$h thi! -enu u!er can in!ertin$ check *oint!, out *ut va%ue!, !ynchroni9in$ *oint!. In thi! -enu !te* $enerator avai%ab%e, u!in$ thi! u!er can $enerate recordab%e and non:recordab%e !cri*t!. Throu$h in!ert -enu u!er can in!ert 3B 4cri*t conditiona% and %oo* !tate-ent! and tran!action *oint! (4tart and ,nd).

13

Throu$h in!ert -enu u!er can create ne( action!, ca%% e5i!tin$ action! and co*y e5i!tin$ action!. Automation Menu$ Thi! -enu *rovide! 'ecord, 'un o*tion! and 'un !ettin$ o*tion! Throu$h thi! -enu (e can !tart nor-a% recordin$, ana%o$ recordin$ and Lo( %eve% recordin$. Throu$h thi! -enu (e can !to* recodin$, runnin$ and a%!o (e run te!t!. /esources Menu$ Thi! -enu *rovide! ob#ect re*o!itory and recovery !cenario! o*tion!. Throu$h thi! -enu (e can create ;-odi&y;de%ete ob#ect! in&or-ation and (e can a!!ociate re*o!itorie!. Throu$h thi! -enu (e can create, -odi&y and de%ete recovery !cenario!. 6ebu$ MenuD Thi! -enu *rovide! debu$ co--and! &or !te* by !te* e5ecution. Throu$h thi! -enu (e can in!ert;re-ove;break *oint!. Too!s Menu$ Thi! -enu *rovide! Too%! !ettin$! o*tion, vie( o*tion! and ob#ect identi&ication con&i$uration. Throu$h thi! -enu (e can !et too% o*tion! a! (e%% a! te!t *ane vie( o*tion!. In thi! -enu ob#ect !*y o*tion avai%ab%e, throu$h thi! (e can $et ob#ectH! in&or-ation.(Pro*ertie! and va%ue!) In thi! -enu 3irtua% ob#ect o*tion avai%ab%eE throu$h thi! o*tion (e can create virtua% ob#ect!. "indow Menu$ Thi! -enu *rovide! QTP too% (indo( !ty%e !ettin$!. He!' Menu$ Thi! -enu *rovide! QTP he%* a! (e%% a! 3B 4cri*t he%*. Throu$h thi! -enu (e can contact technica% !u**ort *eo*%e and (e can !end &eedback. Throu$h thi! -enu (e can check &or u*date! and do(n%oad or in!ta%% direct%y.

1'

III) QTP Testing Process


P!anning o o o o o 0na%y9in$ the 0/T .eneratin$;4e%ectin$ Te!t ca!e! &or 0uto-ation 1o%%ectin$ Te!t 6ata 0uto-ation 8ra-e(ork I-*%e-entation QTP Too% 4ettin$! 1on&i$uration

4enerating Tests o o o 'ecordin$ )ey(ord driven -ethodo%o$y 6e!cri*tive Pro$ra--in$

nhancing Tests o o o o o o o o o o o In!ertin$ 1heck*oint! In!ertin$ "ut*ut va%ue! 0ddin$ 1o--ent! 4ynchroni9ation Para-eteri9ation In!ertin$ 8%o( 1ontro% 4tate-ent! 1a%%in$ 8unction!;0ction! .eneratin$ 4te*! thou$h 4te* .enerator In!ertin$ Tran!action Point! /!in$ 'e$u%ar ,5*re!!ion! /!in$ ,nviron-ent 3ariab%e!

+e,ugging Tests o o o o 6ebu$ 1o--and! I Break Point! 4te* by !te* e5ecution +atchin$ 3ariab%e! 1han$in$ va%ue! o& variab%e!

/unning Tests o o o Nor-a% ,5ecution Batch ,5ecution 0"M 4cri*tin$

10

o o

Te!t! 'unnin$ throu$h &ra-e(ork 4chedu%ed ,5ecution

Ana!y5ing /esu!ts o o o o QTP 'e!u%t (indo( 6e&inin$ our o(n 'e!u%t! ,5*ortin$ 'e!u%t! 6e%etin$ 'e!u%t!

/e'orting +efects o o o Manua% 6e&ect 'e*ortin$ Too% ba!ed 6e&ect 'e*ortin$ +orkin$ (ith Qua%ity 1enter

Ana!y5ing the A6T Be&ore (e be$in creatin$ a te!t, (e need to ana%y9e our a**%ication and deter-ine our te!tin$ need!. 8ir!t, deter-ine the deve%o*-ent environ-ent! in (hich our a**%ication contro%! (ere deve%o*ed, !uch a! +eb, 2ava, or .N,T, !o that (e can %oad the re7uired QuickTe!t add:in!. Then deter-ine the &unctiona%ity that (e (ant to te!t. To do thi!, con!ider the variou! activitie! that cu!to-er! *er&or- in our a**%ication to acco-*%i!h !*eci&ic ta!k!. +hich ob#ect! and o*eration! are re%evant &or the !et o& bu!ine!! *roce!!e! that need to be te!tedJ +hich o*eration! re7uire cu!to-i9ed key(ord! to *rovide additiona% &unctiona%ityJ +hi%e (e are thinkin$ about the bu!ine!! *roce!!e! (e (ant to te!t, con!ider ho( (e can divide the!e *roce!!e! into !-a%%er unit!, (hich (i%% be re*re!ented by our te!tK! action!. ,ach action !hou%d e-u%ate an activity that a cu!to-er -i$ht *er&or(hen u!in$ your a**%ication. 0! (e *%an, try to kee* the a-ount o& !te*! (e *%an to inc%ude in each action to a -ini-u-. 1reatin$ !-a%%, -odu%ar action! he%*! -ake our te!t! ea!ier to read, &o%%o(, and -aintain.

12

/ecording and /unning$


In QTP there are @ recordin$ -ode! avai%ab%e &or *re*arin$ Te!t!. #7 8orma! /ecording It record! /!er Mou!e and )eyboard o*eration! on 0/T (ith re!*ect to ob#ect!, but unab%e to record continuou! -ou!e o*eration! %ike 6i$ita% 4i$nature!, $ra*h!, *aint! etc. 6urin$ recordin$ QTP $enerate! 3b4cri*t !tate-ent! in Te!t Pane, 4i-u%taneou!%y it !tore! ob#ect! in&or-ation into ob#ect re*o!itory. Navi$ationD 0uto-ationG'ecord "r 4e%ect 'ecord o*tion on auto-ation too%bar "r /!e !hort cut key (8@) 4te*! &or *re*arin$ a Te!t (throu$h 'ecordin$)D <. Put 0/T in ba!e !tate 2. 4e%ect 'ecord "*tion @. It !ho(! 'ecord and 'un 4ettin$!, 4e%ect ty*e o& ,nviron-ent (+indo(! or +eb) B. 4e%ect 'ecord "*tion (It !ho(! t(o "*tion! D <. 'ecord and 'un Te!t on any o*en (indo( ba!ed a**%ication! 2. 'ecord and 'un on%y on I& (e !e%ect &ir!t o*tion it record! on any o*ened a**%ication on 6e!kto*. I& (e !e%ect 4econd o*tion, it a!k! &or the *ath o& the 0/T, 0&ter Providin$ the *ath it record! on%y on that *articu%ar a**%ication.) =. >. . A. 1%ick ") Per&or- action! on 0/T 4to* recordin$. 4ave the Te!t

)7 Ana!og /ecording$ It record! the e5act -ou!e and keyboard o*eration!. +e can u!e thi! -ode &or recordin$ continuou! -ou!e o*eration!. It i! not u!e&u% &or recordin$ nor-a% o*eration! (hy becau!e it doe! not $enerate !te*! &or each o*eration, $enerate! tota% u!er action! in a Track 8i%e. The Track &i%e i! not editab%e. Navi$ationD <. )ee* too% under recordin$ -ode

13

2. 0uto-ation G0na%o$ 'ecordin$ "' /!e 4hort cut )ey (4hi&t L 0LTL8@) 4te*! &or *re*arin$ a T,4T (throu$h 0na%o$ 'ecordin$)D <. 2. @. B. Launch 0/T (or (e can %aunch 0/T throu$h QTP) 4e%ect 'ecord o*tion 0uto-ationG0na%o$ 'ecordin$ 0na%o$ 'ecordin$ 4ettin$! 6ia%o$ bo5 o*en!

(In this Dialog box two options available. 1. Record relative to the screen 2. Record relative to the following window If we select first option QTP records User operations with respect to Des top co! ordinates. If we select "econd option# we have to show the window ($UT%# after showing the &indow it records with respect to that window co!ordinates.% =. 4e%ect any one o*tion in the dia%o$ bo5 and c%ick 4tart 0na%o$ record. >. It record! /!er action! . 4to* 'ecordin$ *7 Low Le(e! /ecording It record! !o-e o*eration! on Non:!u**orted environ-ent! a*art &ro- Nor-a% o*eration!. Thi! -ode record! at the ob#ect %eve% and record! a%% run ti-e ob#ect! a! (indo( or (inob#ect Te!t ob#ect!. /!e Lo( Leve% 'ecordin$ &or recordin$ in an environ-ent not reco$ni9ed by QTP. Navi$ationD <. )ee* too% under recordin$ -ode 2. 0uto-ation GLo( Leve% 'ecordin$ 4te*! &or *re*arin$ a T,4T (throu$h Lo( Leve% 'ecordin$)D <) Launch 0/T (or (e can %aunch 0/T throu$h QTP) 2) 4e%ect 'ecord o*tion @) 0uto-ationG Lo( Leve% 'ecordin$ B) Per&or- o*tion! on 0/T =) 4to* 'ecordin$ >) 4ave the Te!t

17

9,:ect /e'ository
9,:ect /e'ository$ It i! a !tora$e *%ace o& QTP (here (e can !tore the ob#ect! in&or-ation and it a%!o act! a! inter&ace bet(een the te!t !cri*t and the 0/T in order to identi&y the ob#ect! durin$ e5ecution. 9,:ect$ "b#ect i! !o-ethin$, (hich ha! !tructure and *ro*ertie!. %oftware o,:ects$ +e ca%% (indo(!, +ebPa$e!, button!, edit bo5e!, check bo5e! etc.. a! !o&t(are ob#ect!. Ty'es of 9,:ect in QTP$ There are &our ty*e! o& ob#ect avai%ab%e in QTP. <. 2. @. B. 'un ti-e ob#ect! Te!t ob#ect! /ti%ity ob#ect! 0uto-ation ob#ect!;/!er de&ined ob#ect!.

/un time o,:ects$ The ob#ect! *re!ent in the 0/T. ,5D Button!, %ink!, etcM Test 9,:ects$ 'e&erence! o& 'un ti-e ob#ect!. ,5D +in,dit, +inButton, +ebButton, Link, etcM NoteD Te!t ob#ect! na-e! vary &ro- one environ-ent to another. ,5D 'un ti-e ob#ect! Te!t ob#ect! in Te!t ob#ect! in 3B (indo(! ,nviron-ent ,nviron-ent button! +inButton 3BButton ,dit bo5 +in,dit 3B,dit 1heck bo5 +incheckbo5 3bcheckbo5

Te!t ob#ect! in (eb ,nviron-ent +ebButton +eb,dit +ebcheckbo5

6ti!ity o,:ects They are QTP re!erved ob#ect! u!ed &or te!tin$ and re!u%t re*ortin$. ,5D <. 4y!te-/ti% &or %aunchin$;c%o!in$ the a**%ication.

1+

2. 'e*orter &or de&inin$ re!u%t!. @. 4ervice! &or in!ertin$ tran!action *oint! B. ,nviron-ent &or u!in$ environ-ent variab%e! Automation o,:ects;6ser defined o,:ects /!er can create ob#ect!E tho!e can be u!ed &or *er&or-in$ !*eci&ic o*eration!. ,5D 1reatin$ ob#ect! in &i%e !y!te- ob#ect c%a!!, adodb.connection c%a!!, dictionary ob#ect c%a!!, e5ce%. 0**%ication c%a!! etc. There are t(o ty*e! o& re*o!itory avai%ab%e in QTP. <. Loca% re*o!itory (.MT' e5ten!ion) 2. 4hared re*o!itory(.T4' e5ten!ion) Loca! /e'ository$ QTP create! a Loca% 'e*o!itory &or every action auto-atica%%y durin$ 'ecordin$. That cannot be !hared a-on$ te!t!. /!er can add !o-e -ore ob#ect! to Loca% re*o!itory /!er can *er&or- rena-e, de%ete o*eration! in %oca% re*o!itory. 0! it i! QTP interna% &i%e u!er no need to !ave -odi&ication!. Navi$ationD 'e!ource -enuGob#ect re*o!itory (4hort cut key 1tr%L')

20

QTP- Loca! /e'ository %hared /e'ository$ /!er (Te!t ,n$ineer) create! !hared re*o!itory by addin$ ob#ect!. That can be !hared a-on$ nu-ber o& te!t!. /!in$ thi! -ethod u!er can *er&or- -odi&ication! on ob#ect! ea!i%y. 9'erations on 9,:ect /e'ository Adding o,:ects a. Loca% 'e*o!itoryD Navi$ationD o*en %oca% re*o!itory (re!ource -enuGob#ect re*o!itory) Gob#ect!G0dd ob#ect! to Loca%G!ho( the ob#ectGc%ick ok (No need to !ave !e*arate%y, it !ave! auto-atica%%y) B. 4hared 'e*o!itoryD Navi$ationD 'e!ource -enuGob#ect re*o!itory -ana$erGob#ectG0dd ob#ect!G!ho( the (indo(;ob#ectGc%ick ok

21

o o o o

4e%ected ob#ect on%y 6e&au%t ob#ect ty*e! 0%% ob#ect! ty*e! 4e%ected ob#ect ty*e!

(If we select first option it stores "elected ob'ects onl(# if we select second option it stores all defa)lt ob'ects# if we select third option it stores $ll ob'ects incl)ding static ob'ects# if we select fo)rth option# we have to select ob'ect classes then it stores that class ob'ects# we can select *ore than one class also.% /enaming o,:ects a. Loca% 'e*o!itoryD 'e!ource! G ob#ect re*o!itory G!e%ect ob#ect and ri$ht c%ick Gchoo!e rena-e o*tion G-odi&y the na-eGre%ea!e the -ou!e.Gc%o!e re*o!itory b. 4hared 'e*o!itoryD 'e!ource! Gob#ect re*o!itory -ana$erG&i%eGo*enGbro(!e *ath o& the re*o!itory &i%e G&i%eGenab%e editin$G!e%ect ob#ect I'i$ht c%ickGchoo!e rena-e o*tionG-odi&y the na-e G re%ea!e -ou!eG!ave the &i%e I c%o!e re*o!itory -ana$er. +e!eting o,:ects a. Loca% 'e*o!itoryD 'e!ource! G ob#ect re*o!itory G!e%ect ob#ect and ri$ht c%ick Gchoo!e de%ete o*tion Gcon&ir- de%etionG. Gc%o!e re*o!itory b. 4hared 'e*o!itoryD 'e!ource! Gob#ect re*o!itory -ana$erG&i%eGo*enGbro(!e *ath o& the re*o!itory &i%e G&i%eGenab%e editin$G!e%ect ob#ect I'i$ht c%ickGchoo!e de%ete o*tionGcon&ir- the de%etion G!ave the &i%e I c%o!e re*o!itory -ana$er. Associating o,:ects re'ositories to an action 'e!ource!G0!!ociate re*o!itorie!Gc%ick add icon (L)Gbro(!e *ath o& the re*o!itoryG0!!ociate (ith an actionGc%ick ok Merging /e'ositories 'e!ource! G ob#ect re*o!itory -ana$erGtoo%!Gob#ect re*o!itory -er$e too% Gbro(!e *ath o& the &ir!t re*o!itoryG bro(!e *ath o& the !econd re*o!itoryGc%ick okGc%ick c%o!eG!ave the -er$ed re*o!itoryGc%o!e the re*o!itory -ana$er. NoteD 0&ter -er$in$ a%!o, !ource re*o!itory &i%e! (i%% be avai%ab%e, i& (e do not (ant !ource &i%e! (e can de%ete.

22

+efining new test o,:ects Navi$ationD "b#ectG6e&ine ne( te!t ob#ect G4e%ect ,nviron-entG4e%ect 1%a!! o& the ob#ectG,nter na-e o& the ob#ectG1%ick 0ddGc%ick c%o!eG4e%ect ob#ect G!e%ect *ro*erty na-eGenter va%ue (%ike thi! !e%ect one by one *ro*ertie! and enter va%ue!)G!ave NoteD Thi! &eature can be u!ed &or *re*arin$ te!t! be&ore the 0/T i! ready. %'ying o,:ects 8or $ettin$ ob#ect! in&or-ation, (Te!t ob#ect! na-e!, *ro*erty I 3a%ue!) QTP i! *rovidin$ a &eature ca%%ed "b#ect 4*y, u!in$ thi! (e can $et ob#ect! in&or-ation. Navi$ationGToo%!Gob#ect !*yGtake hand icon I 4ho( the ob#ectG$et in&or-ation ("b#ect 4*y !ho(! the !*eci&ic ob#ect! a%% avai%ab%e *ro*ertie! (ith their va%ue!) NoteD 0! "b#ect !*y i! an i-*ortant &eature, it can be avai%ab%e in @ 0rea!.(<. In too%! Menu 2. In %oca% re*o!itory @. In 'e*o!itory -ana$er) View 9'tions Locate in 'e*o!itory Thi! &eature can be u!ed &or identi&yin$ ob#ect! &ro- a**%ication to re*o!itory. Navi$ationD 3ie(GLocate in re*o!itory G!ho( the ob#ectGc%ick "kGit %ocate! !*eci&ied ob#ect in the re*o!itory. Hi$h%i$ht in 0**%ication Thi! &eature can be u!ed &or identi&yin$ ob#ect! &ro- re*o!itory to a**%ication. Navi$ationD 4e%ect ob#ect in the re*o!itory Gvie(Ghi$h%i$ht in a**%icationGit hi$h%i$ht! !*eci&ied ob#ect! in the a**%ication. &'orting /e'ository to an <ML fi!e +e can e5*ort our re*o!itory &i%e to an 5-% &i%e. Navi$ationD 8i%e Ge5*ort Te!t ob#ect! to NML ,nter the &i%e na-e and 4ave (ith 5-% e5ten!ion. Im'orting /e'ository from <ML fi!e +e can i-*ort NML &i%e to our re*o!itory. Navi$ationD 8i%eGi-*ort &ro- NML Gbro(!e *ath o& the NML &i%e Git %oad! ob#ect!. NoteD The *ur*o!e o& thi! &eature i! ,ditin$ ob#ect! in&or-ation out!ide o& the QTP

23

+escri'ti(e Programming
,nterin$ ; Providin$ ob#ect! in&or-ation direct%y into the te!t !cri*t i! ca%%ed 6e!cri*tive Pro$ra--in$. In thi! -ethod o& !cri*t creation, (e no need to have "b#ect 'e*o!itorie!. Ad(antages$ a) 6e!cri*tive Pro$ra--in$ ba!ed Te!t !cri*t! are &a!ter in e5ecution than 'e*o!itory ba!ed Te!t !cri*t!. b) 4cri*t! are *ortab%e ((e can run the!e !cri*t! &ro- any -achine ea!i%y) c) Maintenance i! ea!y (%e!! a-ount o& re!ource!) d) +e can !tart Te!t ,5ecution *roce!! even thou$h 0**%ication i! not ready. 6e!cri*tive *ro$ra--in$ i! ba!ica%%y 2 ty*e!. <. 4tatic Pro$ra--in$ 2. 6yna-ic Pro$ra--in$

%tatic Programming
In thi! !ty%e o& !cri*t $eneration, (e *rovide ob#ect! in&or-ation direct%y into the !cri*t. ,5D Invokea**%ication O1DPPro$ra- 8i%e!PHPPQuickTe!t Pro&e!!iona%P!a-*%e!P&%i$htPa**P&%i$htBa.e5eO dia%o$(Ote5tDQLo$inO).0ctivate dia%o$(Ote5tDQLo$inO).+inedit(Oattached te5tDQ0$ent Na-eDO).4et Oa!d&O dia%o$(Ote5tDQLo$inO).+inedit(Oattached te5tDQPa!!(ordDO).4et O-ercuryO dia%o$(Ote5tDQLo$inO).+inbutton(Ote5tDQ")O,O(idthDQ>0O).1%ick NoteD <. 6ia%o$, +in,dit and +inButton ? Te!t "b#ect! 2. te5t, attached te5t : Pro*erty na-e! @. Lo$in, 0$ent Na-eD, Pa!!(ordD, ") : Pro*erty va%ue! or Lo$ica% Na-e! o& the "b#ect B. 0ctivate, 4et, 4et!ecure, 1%ick : Method! Note2D I& (e &ee% one *ro*erty in&or-ation i! not !u&&icient &or reco$ni9in$ the ob#ect uni7ue%y, then (e can *rovide -ore *ro*ertie! in&or-ation by !e*aratin$ (ith co--a!.

2'

Note @D I& (e (ant to $et ob#ect! in&or-ation (Te!t ob#ect!, *ro*ertie! and va%ue!), (e can u!e ob#ect !*y &eature. Thi! &eature i! avai%ab%e in Too%! Menu, in %oca% re*o!itory and in re*o!itory -ana$er. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: I& (e (ant -aintain =9,:ects information> in centra%i9ed %ocation then (e can u!e 2onstants. 4te*!D 2reating 2onstants$ 2onst Lo$inQOte5tDQLo$inO, 0$entQOattached te5tDQ0$ent Na-eDO 2onst P(d QOattached te5tDQPa!!(ordDO, "kQOte5tDQ")O NoteD (e can dec%are no o& 1on!tant! in a %ine by !e*aratin$ (ith 1a-a! (,), i& (e take other %ine then (e have to u!e 2onst 4tate-ent a$ain. 2reating a Li,rary fi!e P%ace 1on!tant! in Note*ad and !ave a! .(,s fi!e 0!!ociate the Library &i%e to QTP (8i%e:G4ettin$!:G'e!ource!:G 1%ick add (L) icon:G Bro(!e *ath o& the Library &i%e:G1%ick 0**%y and c%ick "k button! "ther(i!e, (e can %oad the %ibrary &i%e durin$ run:ti-e 4ynta5D ,5ecute8i%e RPath o& the Library &i%e(.vb!)S 0&ter that create the Te!t 4cri*t u!in$ 1on!tant! 2reating the Test %cri't using 2onstants$ Invokea**%ication O1DPPro$ra- 8i%e!PHPPQuickTe!t Pro&e!!iona%P!a-*%e!P&%i$htPa**P&%i$htBa.e5eO 6ia%o$(Lo$in).0ctivate 6ia%o$(Lo$in).+inedit(0$ent).4et Oa!d&O 6ia%o$(Lo$in).+inedit(P(dO).4et O-ercuryO 6ia%o$(Lo$in).+inbutton("k).1%ick Ad(antages$ I& (e -aintain "b#ect In&or-ation in the centra%i9ed %ocation, then (e can hand%e -odi&ication! ea!i%y. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

20

+ynamic Programming
In thi! !ty%e o& !cri*t $eneration, &ir!t (e create de!cri*tion ob#ect!, *rovide *ro*ertie! in&or-ation and u!e de!cri*tion ob#ect! in the te!t !cri*t. 2reating Pro'erties 2o!!ection 9,:ects 4et 4et 4et 4et oLo$inQde!cri*tion.1reate o0$entQde!cri*tion.1reate oPa!!(ordQde!cri*tion.1reate o"kQde!cri*tion.1reate

ntering Pro'erties Information into 9,:ects oLo$in(Ote5tO).va%ueQOLo$inO oLo$in(O(idthO).va%ueQ@20 oLo$in(Ohei$htO).va%ueQ20B o0$ent(Oattached te5tO).va%ueQO0$ent Na-eDO oPa!!(ord(Oattached te5tO).va%ueQOPa!!(ordDO o"k(Ote5tO).va%ueQO")O 4enerating Tests using Pro'erties co!!ection 9,:ects Invokea**%ication O1DPPro$ra- 8i%e!PHPPQuickTe!t Pro&e!!iona%P!a-*%e!P&%i$htPa**P&%i$htBa.e5eO 6ia%o$(oLo$in).0ctivate 6ia%o$(oLo$in).+inedit(o0$ent).4et Oa!d&O 6ia%o$(oLo$in).+inedit(oPa!!(ord).4et O-ercuryO 6ia%o$(oLo$in).+inbutton(o")).1%ick Note<D 1reate 6e!cri*tion ob#ect! and *ut into one %ibrary &i%e, by a!!ociatin$ that %ibrary &i%e, (e can $enerate te!t!. Note2D 6yna-ic *ro$ra--in$ i! !o-e di&&icu%t in *re*aration than !tatic *ro$ra--in$ but -aintenance i! very ea!y.

::::::::::::::::::::::::::::::::::::::::::::::::::::
In thi! !ty%e o& !cri*t creation a%!o, (e can -aintain "b#ect! in&or-ation in the 1entra%i9ed %ocation by *uttin$ co%%ection ob#ect! in a Library &i%e.

::::::::::::::::::::::::::::::::::::::::::::::::::::

22

Methods or 9'erations
Acti(ate$ It activate! dia%o$ bo5e!;+indo(! 4ynta5D "b#ect hierarchy. 0ctivate ,5D 6ia%o$(RLo$inS).0ctivate +indo((R8%i$ht 'e!ervationS).0ctivate 2!ic? MethodD It c%ick! on an ob#ect (Button!) 4ynta5D "b#ect hierarchy. 1%ick ,5D 6ia%o$(RLo$inS).+inbutton(RokS).c%ick 2!ose MethodD It c%o!e! the (indo(,6ia%o$ bo5, Bro(!er (indo( etc. 4ynta5D "b#ect hierarchy. 1%o!e ,5D +indo((R8%i$ht 'e!ervationS).1%o!e Bro(!er(RBro(!erS).1%o!e 6BL 1LI1)D It 6oub%e c%ick! the ob#ect. %et MethodD It can be u!ed in three (ay!. a. 8or !ettin$ the va%ue o& an edit bo5 4ynta5D "b#ect Hierarchy. 4,T R3a%ueS ,5D 6ia%o$ (RLo$inS).+in,dit(R0$ent Na-eS).4et Ra!d&S b. 4e%ectin$ a 'adio Button 4ynta5D "b#ect Hierarchy. 4et ,5D +indo((O8%i$ht 'e!ervationO).+in'adioButton(OBu!ine!!O).4et c. 4e%ectin$;6e!e%ectin$ check bo5e! 4ynta5Dob#ect Hierarchy.4et R"N;o&&S ,5D +indo( (O8%i$ht 'e!ervationO). 6ia%o$(O"*en "rderO).+in1heckBo5(O"rder No.O).4et O"NO %e!ect MethodD It i! u!ed &or !e%ectin$ an ite- &ro- a co-bo bo5 or %i!t bo5. 4ynta5D "b#ect hierarchy.!e%ect Rite-S ,5D 0. +indo((O8%i$ht 'e!ervationO).+in1o-boBo5(O8%y 8ro-DO).4e%ect OLondonO

23

B. +indo((O8%i$ht 'e!ervationO).6ia%o$(O8%i$ht! Tab%eO).+inLi!t(O8ro-O).4e%ect O<2= 2 4etVisi,!ete&t$ It return! Te5t &ro- the !*eci&ied area. 4ynta5D 3ariab%e Qob#ect hierarchy.$etvi!ib%ete5t ,5D 5Q+indo((O8%i$ht 'e!ervationO).+in1o-boBo5(O8%y 8ro-DO)..et3i!ib%eTe5t -!$bo5 5 4et/o'ro'ertyD It return! current ob#ect *ro*erty va%ue. It can be u!ed &or $ettin$ any ob#ectH!, any *ro*erty va%ue. 4ynta5D 3ariab%e Q ob#ect hierarchy.$etro*ro*erty (R*ro*erty na-eS) ,5D 5Q+indo((O8%i$ht 'e!ervationO).+in,dit(OTicket!DO)..et'"Pro*erty (O(idthO) -!$bo5 5 8a(igate MethodD It o*en! a !*eci&ied /'L in the Bro(!er. 4ynta5D ob#ect hierarchy.navi$ate R/'LS ,5D Bro(!er(OFahooTO).Navi$ate Ohtt*D;;(((.$oo$%e.co.inO 4etitemscount$ It return! nu-ber o& ite-! in a co-bobo5. 4ynta5D 3ariab%eQob#ect hierarchy.$etite-!count ,5D 5Q+indo((O8%i$ht 'e!ervationO).+in1o-boBo5(O8%y 8ro-DO)..etIte-!1ount -!$bo5 5 4etcontent$ It return! a%% ite-! &ro- a co-bobo5. 4ynta5D variab%eQob#ect hierarchy..et1ontent ,5D 5Q+indo((O8%i$ht 'e!ervationO).+in1o-boBo5(O8%y 8ro-DO)..et1ontent -!$bo5 5 &ist 'ro'ertyD It check! (hether the ob#ect i! avai%ab%e or not. 4ynta5D "b#ect hierarchy.e5i!t(ti-e in !econd!) ,5D +indo((O8%i$ht 'e!ervationO).,5i!t(=)

27

nhancing Tests
0&ter $eneratin$ the ba!ic te!t, (e have to enhance the te!t in order to Te!t the 0/T (ith re!*ect to re7uire-ent!. There are !evera% -ethod! avai%ab%e in QTP &or enhancin$ the T,4T.

<. In!ertin$ 1heck Point! 2. In!ertin$ "ut*ut 3a%ue! @. 0ddin$ 1o--ent! B. In!ertin$ 8%o( 1ontro% 4tate-ent! =. 4ynchroni9ation >. Para-eteri9ation . .eneratin$ 4te*! throu$h 4te* .enerator A. In!ertin$ Tran!action Point!D(4tart and ,nd)

Inserting 2hec?'oints
1heck *oint i! a veri&ication *oint, it take! e5*ected re!u%t &ro- the u!er and co-*are! (ith actua% re!u%t! durin$ e5ecution and *rovide! te!t re!u%t!.

There are ## 2hec?'oints a(ai!a,!e in QTP$


<. 4tandard check *oint 2. Te5t check *oint @. Te5t area check *oint B. Bit -a* check *oint =. 6ata ba!e check *oint >. 0cce!!ibi%ity check *oint . NML 1heck *oint (&ro- 0**%ication) A. NML 1heck *oint (&ro- 'e!ource) C. Pa$e check *oint <0. I-a$e check*oint <<. Tab%e check*oint Note <D 8ro- > to << check*oint! are on%y &or +eb.

2+

Note 2D 8ro- C to << check*oint! are hidden check*oint!, (e can in!ert the!e check*oint! throu$h !tandard check*oint.

#7 %tandard 2hec?'oint$
It check! ob#ect *ro*erty va%ue!. +e can u!e thi! check*oint &or checkin$ any *ro*erty va%ue. 8a(igation for Inserting standard chec?'oint )ee* too% under recordin$ -ode G *%ace cur!or in de!ired %ocation G In!ert G check *oint G 4tandard check*oint G 4ho( the ob#ect G c%ick okay G !e%ect *ro*erty and enter e5*ected re!u%t! I c%ick "k and !to* 'ecordin$. 8a(igation for diting standard chec?'oint

4e%ect 1heck*oint !tate-ent and ri$ht c%ick G choo!e check*oint *ro*ertie! o*tion G -odi&y the va%ue G c%ick "k. 8a(igation for +e!eting standard chec?'oint$ 4e%ect 1heck*oint !tate-ent! and ri$ht c%ick G choo!e de%ete o*tion. Inserting %tandard chec? 'oints through acti(e screen$ 3ie( G 0ctive 4creen G*%ace cur!or in de!ired %ocation GP%ace -ou!e *ointer on active !creen I ri$ht c%ickG choo!e in!ert !tandard check*oint o*tion G c%ick ok G enter e5*ected re!u%t G c%ick ok NoteD In!ertin$ 4tandard check *oint! throu$h key(ord vie( !a-e a! in e5*ert vie(. 8ote$ +e can in!ert !tandard check*oint! in @ (ay!. <. 2. @. Throu$h e5*ert vie(, Throu$h key(ord vie(, Throu$h 0ctive !creen.

)) Te&t 2hec?'oint$
It 1heck! ob#ectH! te5t *ro*erty va%ue in di&&erent (ay!. 8a(igation$ )ee* too% under 'ecordin$ -ode GIn!ert -enu G check*oint G Te5t check*oint G 4ho( the ob#ect G c%ick ok G 4e%ect o*tion! 4=atc! caseA i nore spaces" e.act matc!" te.t not displayed.)

30

+e can !e%ect one or -ore o*tion! G c%ick ok I !to* 'ecordin$.

*) Te&t Area 2hec?'oint$


It check! the te5t area *re!ent in the a**%ication. Navi$ationD )ee* too% under 'ecordin$ -ode G In!ert -enuG 1heck*oint G Te5t area check*oint G Mark the area o& te5t G !e%ect one or -ore o*tion! 4=atc! case" i nore spaces" e.act matc!" te.t not displayed.) 1%ick ok and !to* recordin$.

B. Bitma' chec?'oint$
It co-*are! bit-a*!E (e can co-*are co-*%ete bit-a*! a! (e%% a! *art o& the bit-a*!. 8a(igationD )ee* too% under 'ecordin$ -ode G In!ert -enu G 1heck*oint G Bit-a* check*oint G !ho( the Bit-a* Gc%ick ok G!e%ect Rcheck on%y !e%ected areaS o*tion i& (e (ant to co-*are *art o& the bit-a* G c%ick ok G!to* recordin$.

=. +ata,ase chec?'oint$
It check! 1ontent o& the back end 6ataba!e. 8a(igation$ In!ert G check*oint G 6ataba!e check*oint Gchoo!e R!*eci&y 4QL !tate-ent -anua%%yS o*tion Gc%ick ne5t G c%ick create G !e%ect -achine data !ource G 4e%ect 64N (QTU&%i$ht@2) G c%ick ok G enter 4QL !tate-ent (!e%ect V &roorder!) G &ini!h G c%ick ok. 8ote$ here (e do not need to *ut too% under 'ecordin$ -ode and (e do not need 0/T !ince data i! &ro- backend.

07 Accessi,i!ity chec? 'oint$


It check! (hether the (eb*a$e in our (eb a**%ication i! deve%o*ed accordin$ to +@1 (+or%d +ide +eb con!ortiu-) 'u%e! and 'e$u%ation! or not. It i! a con&i$urab%e check*oint, accordin$ to our re7uire-ent!, (e can cu!to-i9e. 2onfiguring accessi,i!ity chec?'oint$ Too%! -enuG o*tion! G(eb G advanced G check;uncheck ite-! G c%ick a**%y G c%ick ok In(igi!ation$

31

)ee* too% under recordin$ -ode (ith (eb environ-ent Gin!ertGcheck*ointGacce!!ibi%ity check*ointG!ho( the (eb*a$eGc%ick okGc%ick okG!to* recordin$. 'e!u%t 1riteriaD a) I& ite- i! avai%ab%e but not accordin$ to +@1 ru%e! then &ai%. b) I& an ite- i! avai%ab%e, accordin$ to +@1 ru%e! then Pa!!. c) I& an ite- i! not avai%ab%e then re!u%t (ou%d be *a!!

17 <ML 2hec? 'oint @from A''!ication)


It check! content o& the NML &i%e. Navi$ationD )ee* too% under 'ecordin$ -ode in (eb environ-ent G in!ert -enu G check*oint (&ro- a**%ication)G !ho( the 5-% *a$e! Gc%ick ok G !to* 'ecordin$.

A7 <ML 2hec? 'oint @from /esource)


It check! content o& the NML &i%e. Navi$ationD In!ert -enu G check*oint G5-% check*oint (&ro- re!ource) G bro(!e *ath o& the NML 8i%e G c%ick ok G c%ick ok. NoteD <. I& NML &i%e i! an individua% and *ath avai%ab%e, and then (e can $o &or in!ertin$ 5-% check*oint &ro- re!ource. NoteD 2. I& NML &i%e i! *art o& (eb a**%ication, !e*arate *ath i! not avai%ab%e then (e can choo!e in!ertin$ NML check*oint! &ro- a**%ication.

B7 Page chec?'oint$
It check! nu-ber o& Link!, I-a$e! and Loadin$ ti-e in a (eb *a$e. It i! a hidden check*ointE (e can in!ert thi! throu$h !tandard check*oint. 8a(igation$ )ee* too% under 'ecordin$ -ode (ith (eb environ-ent G In!ert -enu G check*oint G 4tandard check*oint G!ho( the (eb *a$e G c%ick ok G c%ick ok G !to* recordin$.

<0.

Image chec?'oint$

It check! I-a$e *ro*erty va%ue!. 8a(igation$ )ee* too% under 'ecordin$ -ode (ith (eb environ-ent G In!ert -enu G check*oint G!tandard check*oint G !ho( the i-a$e G !e%ect i-a$e G c%ick ok G c%ick ok G!to* recordin$.

32

<<.

Ta,!e chec?'oint$

It check! content o& the (eb tab%e!. Navi$ationD )ee* too% under 'ecordin$ -ode under (eb environ-ent G In!ert -enu G check*oint G !tandard check*oint G!ho( the (eb tab%e G c%ick ok G!to* recordin$.

Inserting 9ut'ut Va!ues


It i! a !te* in (hich one or -ore va%ue! are ca*tured durin$ te!t e5ecution. The va%ue! can %ater be u!ed a! in*ut at a di&&erent *oint in the run !e!!ion or (e can u!e a! in*ut &or another te!t. It i! !tored in run ti-e data tab%eE it i! %ocated in QTP re!u%t (indo( and can be retrieved %ater.

Ty'es of 9ut'ut Va!ues$


#7 4tandard out*ut va%ue )7 Te5t out*ut va%ue *7 Te5t area out*ut va%ue -7 6ataba!e out*ut va%ue .7 NML out*ut va%ue (8ro- 0**%ication) 07 NML out*ut va%ue (8ro- 'e!ource)

#) %tandard out'ut (a!ue$


+e can u!e !tandard out*ut va%ue! to out*ut the *ro*ertie! va%ue! o& -o!t ob#ect!. 8a(igation$ )ee* too% under 'ecordin$ -ode G In!ert -enu Gout*ut va%ueG !tandard out*ut va%ue G !ho( the ob#ect G c%ick ok G !e%ect *ro*erty G -odi&y the co%u-n na-e (i& re7uired) G c%ick ok Gc%ick ok G!to* recordin$.

33

)) Te&t out'ut (a!ue$


+e can u!e Te5t out*ut va%ue! to out*ut te5t !trin$! di!*%ayed in an a**%ication. +hen creatin$ a te5t out*ut va%ue (e can out*ut a *art o& the ob#ect! te5t and (e can a%!o !*eci&y te5t be&ore and a&ter o*tion!. 8a(igation$ )ee* too% under recordin$ -odeG In!ert -enuG out*ut va%ue G te5t out*ut va%ue G !ho( the te5t G!e%ect one o& the o*tion(out*ut te5t;te5t be&ore;te5t a&ter) G c%ick -odi&y i& you (ant to chan$e the co%u-n na-e G c%ick ok G c%ick ok.G check in runti-e tab%e a&ter runnin$ it.

*) Te&t Area out'ut (a!ue$


+e can u!e te5t area out*ut va%ue! to out*ut te5t !trin$! di!*%ayed (ithin a de&ined area o& the !creen. 8a(igation$ )ee* too% under recordin$ -ode G in!ert -enu Gout*ut va%ue G te5t area out*ut va%ue GMark the te5t area Gc%ick -odi&y the co%u-n na-e i& nece!!ary G c%ick ok G a$ain c%ick ok G check in run ti-e tab%e a&ter runnin$ it..

-) +ata,ase out'ut (a!ue$


+e can u!e 6ataba!e out*ut va%ue! to out*ut the va%ue o& the content! o& databa!e ce%%!. 8a(igation$ In!ert -enuG out*ut va%ue G 6ataba!e out*ut va%ueG choo!e !*eci&y 4QL !tate-ent! -anua%%y Gc%ick ne5t Gc%ick create G4e%ect Machine 6ata !ource G 4e%ect 6river (QTU&%i$ht@2) G c%ick ok G enter 4QL !tate-ent (!e%ect V&roorder!) G c%ick &ini!h G !e%ect data ce%%! G c%ick ok G 'un and it (i%% ca*ture and !ee the re!u%t! in run ti-e tab%e.

.) <ML out'ut (a!ue @from a''!ication)$


(e can u!e NML out*ut va%ue! to out*ut the va%ue! o& NML e%e-ent! in NML docu-ent!. Navi$ationD )ee* too% under recordin$ -ode (ith (eb environ-ent G In!ert -enu G out*ut va%ue G NML out*ut va%ue &ro- a**%ication G 4ho( the NML docu-ent G !e%ect e%e-ent! G c%ick ok G!to* recordin$.

0) <ML out'ut Va!ue @3rom /esource)$


+e can u!e NML out*ut va%ue! to out*ut the va%ue! o& docu-ent!. NML e%e-ent! in NML

3'

8a(igation$ In!ert -enu Gout*ut va%ueG NML out*ut va%ue &ro- re!ource G bro(!e *ath o& the NML &i%e G c%ick ok G !e%ect e%e-ent! Gc%ick ok.

Adding 2omments
Pur'ose of 2omments$
o o 8or -akin$ the !cri*t under!tandab%e 8or -akin$ the 4cri*t 6i!ab%e &ro- e5ecution

%ynta&$
<. /!e 0*o!tro*he (W) be&ore the !tate-ent 2. /!e ',M 1o--and (ith !in$%e !*ace be&ore the !tate-ent

2omment a B!oc? of %tatements$


Navi$ationD 4e%ect b%ock o& !tate-ent! G ,dit -enuG 0dvancedG 1o--ent b%ock "r 0&ter !e%ectin$ b%ock o& !tate-ent! u!e !hortcut key 1tr%LM

6ncomment a ,!oc? of statements$


Navi$ationD 4e%ect co--ent b%ockG,dit -enuG 0dvancedG/nco--ent b%ock "r 0&ter !e%ectin$ co--ent b%ock, /!e !hortcut key ctr%L!hi&tLM

Inserting 3!ow 2ontro! %tatements


QTP ada*ted 3B !cri*t en$ine &or a**%yin$ *ro$ra--in$ %o$ic to te!t!. +e can in!ert 3B !cri*t conditiona% !tate-ent! and %oo* !tate-ent! &or a**%yin$ the %o$ic. In 3B !cri*t there are 2 ty*e! o& conditiona% !tate-ent! and &our ty*e! o& %oo* !tate-ent! avai%ab%e.

30

%ynchroni5ation
It i! a *roce!! o& -atchin$ the !*eed! o& both QTP and 0/T in order to $et *ro*er e5ecution and re!u%t!.

"here %ynchroni5ation is reCuired$


6urin$ te!t e5ecution QTP $ive! in!truction! one by one (ith !a-e !*eed, but 0/T take! %e!! ti-e &or !o-e o*eration! e5ecution and -ore ti-e &or !o-e o*eration! e5ecution, that ti-e (e -ay not $et *ro*er e5ecution and re!u%t!. In order to $et *ro*er re!u%t! in bet(een QTP I 0/T !ynchroni9ation i! re7uired. There are se(era! methods a(ai!a,!e in QTP for synchroni5ation7 <. In!ertin$ +ait !tate-ent!. 2. In!ertin$ 4ynchroni9ation *oint!. @. Increa!in$ Too% de&au%t !ynchroni9ation ti-e. B. 4ync Method ("n%y &or +,B) =. ,5i!t Pro*erty

Inserting "ait %tatements$


+e can in!ert (ait !tate-ent! in our te!t in order to -ake QTP to (ait unti% 0/T co-*%ete! current o*eration. %ynta&$ +ait(ti-e in !econd!) NoteD I& (e in!ert (ait !tate-ent! QTP (ait! u* to -a5i-u- ti-e even thou$h o*eration i! co-*%eted.

Inserting %ynchroni5ation 'oint$


P%ace cur!or in de!ired %ocationGkee* too% under recordin$ -ode G In!ert -enu G 4ynchroni9ation *oint G !ho( the ob#ect G c%ick ok G !e%ect *ro*erty na-e I 3a%ue (True)Genter ti-e in Mi%%e !econd!Gc%ick okG4to* recordin$. NoteD i& (e in!ert 4ynchroni9ation *oint!, it doe! not (ait u* to -a5i-u- ti-e, a&ter co-*%etion o& the current o*eration!, it $oe! to ne5t !te* i--ediate%y. %ynta&$ ob#ect hierarchy.(ait*ro*erty R*ro*erty na-eS,va%ue,ti-e in -i%%i !econd!.

32

Increasing Too! defau!t synchroni5ation time$


Navi$ationD 8i%eG!ettin$!Grun tabGincrea!e ob#ect !ynchroni9ation ti-e outGa**%yGok NoteD I& (e increa!e QTP too% de&au%t ti-e that can be a**%ied &or a%% !tate-ent! in the te!t, but QTP doe! not (ait u* to -a5i-u- ti-e unnece!!ari%y, 0&ter co-*%etion o& one !tate-ent e5ecution it $oe! to ne5t !tate-ent i--ediate%y.

%ync Method$ (on%y &or +,B)


+ait! &or the bro(!er to co-*%ete current navi$ation. 4ynta5D "b#ect Hirearchy.4ync ,5D Bro(!er(OFahooT Too%barO).Pa$e(OFahooT Too%barO).4ync

%e!ecting an a''ro'riate Method$


<. 4u**o!e in our te!t one or -ore !tate-ent! on%y are takin$ -ore ti-e &or e5ecution then !e%ectin$ RIn!ertin$ !ynchroni9ation -ethodS i! better. 2. 4u**o!e in our te!t -ore !tate-ent! are takin$ -ore ti-e &or e5ecution then !e%ectin$ Rincrea!in$ too% ti-e outS . @. 0bove t(o are %oca% &eature! but (ait !tate-ent i! 3b!cri*t &eature, even thou$h !o-e dra(back! are there in u!in$ (ait !tate-ent, it i! better to u!e (ait !tate-ent in &unction!.

Inserting Transaction Points


+e can in!ert Tran!action *oint! &or -ea!urin$ Tran!action ti-e. It i! a *er&or-ance conce*t but QTP !u**ort! -ea!urin$ tran!action ti-e *er u!er on%y. 4ynta5D 4ervice!.4tartTran!action Ona-e o& the tran!actionO ::::::: !tate-ent! ::::::::: :::::::: !ervice!.,ndTran!action Ona-e o& the tran!actionO NoteD +e can in!ert -u%ti*%e tran!action! *oint! in a te!t.

33

Parameteri5ation
Pa!!in$ *ara-eter!, throu$h thi! conce*t (e can *a!! -u%ti*%e va%ue!. +e u!e *ara-eteri9ation in 6ata 6riven Te!tin$.

+ata +ri(en Testing$ Te!tin$ the 4a-e o*eration (ith -u%ti*%e !et! o& te!t
data. Ty'es of Parameteri5ation$ +e can *ara-eteri9e te!t! in !evera% (ay!. <. Throu$h Loo* 4tate-ent! 2. 6yna-ic Te!t 6ata 4ub-i!!ion @. Throu$h 6ata Tab%e B. 8etchin$ Te!t 6ata direct%y &ro- ,5terna% &i%e! (8%at &i%e! I 4*read!heet!) =. 8etchin$ Te!t 6ata direct%y &ro- 6ataba!e! (M4 0ce!!, orac%e etc). >. .ettin$ Te!t 6ata &ro- &ront end ob#ect!.

#7 Through Loo' %tatements$


+e can u!e %oo* !tate-ent! &or *a!!in$ !e7uentia% nu-ber! I Lo$ica% Nu-ber!. NoteD +e canHt $enerate 4trin$!. 8or ordernoQ< to <0 !te* < K &or one incre-ent !te* key(ord i! not -andatory +indo((O8%i$ht 'e!ervationO).0ctivate +indo((O8%i$ht 'e!ervationO).+inButton(OButtonO).1%ick +indo((O8%i$ht 'e!ervationO).6ia%o$(O"*en "rderO).+in1heckBo5(O"rder No.O).4et O"NO +indo((O8%i$ht 'e!ervationO).6ia%o$(O"*en "rderO).+in,dit(O,ditO).4et orderno +indo((O8%i$ht 'e!ervationO).6ia%o$(O"*en "rderO).+inButton(O")O).1%ick Ne5t

)7+ynamic Test +ata %u,mission$


Throu$h Loo* 4tate-ent! (e can $ive !trin$! a%!o but every ti-e u!er ha! to enter data. 8or 5Q< to @ 0$ent Qin*utbo5(Oenter an 0$ent Na-eO) Pa!!(ordQin*utbo5(Oenter a *a!!(ordO) invokea**%ication O1DPPro$ra- 8i%e!PMercury InteractivePQuickTe!t Pro&e!!iona%P!a-*%e!P&%i$htPa**P&%i$htBa.e5eO

37

6ia%o$(OLo$inO).0ctivate 6ia%o$(OLo$inO).+in,dit(O0$ent Na-eDO).4et 0$ent 6ia%o$(OLo$inO).+in,dit(O0$ent Na-eDO).Ty*e -icTab 6ia%o$(OLo$inO).+in,dit(OPa!!(ordDO).4et4ecure *a!!(ord 6ia%o$(OLo$inO).+inButton(O")O).1%ick +indo((O8%i$ht 'e!ervationO).1%o!e Ne5t

*7 Through +ata Ta,!e$


QTP add! one data tab%e (4*read!heet) &or every te!t, (e can u!e 6ata Tab%e &or 6ata 6riven Te!tin$. It has * ty'es of usage a. ,nterin$ te!t data direct%y into data tab%e and u!e b. I-*ortin$ te!t data &ro- e5terna% 8%at &i%e! c. I-*ortin$ te!t data &ro- e5terna% 4*read !heet! d. I-*ortin$ te!t data &ro- 6ata ba!e!. 0. ,nterin$ te!t data direct%y into data tab%e and u!e. 4te*!D .enerate the ba!ic te!tGo*en data tab%e(3ie(G6ata Tab%e) 1%ick on co%u-n headerGenter the na-e o& the &ie%d (%ike thi! (e can create nu-ber o& co%u-n!) G ,nter 6ataGconnect the data to te!t (variable+datatable(,col)*n na*e-# "heet id% .xa*ple/ agent+datatable(,agent-#1% Pass para*eters.% 'un the te!t. 0$ent Q 6atatab%e(O0$entO,<) *(dQ6atatab%e (OPa!!(ordO,<) invokea**%ication O1DPPro$ra- 8i%e!PMercury InteractivePQuickTe!t Pro&e!!iona%P!a-*%e!P&%i$htPa**P&%i$htBa.e5eO 6ia%o$(OLo$inO).0ctivate 6ia%o$(OLo$inO).+in,dit(O0$ent Na-eDO).4et 0$ent 6ia%o$(OLo$inO).+in,dit(O0$ent Na-eDO).Ty*e -icTab 6ia%o$(OLo$inO).+in,dit(OPa!!(ordDO).4et4ecure *(d 6ia%o$(OLo$inO).+inButton(O")O).1%ick +indo((O8%i$ht 'e!ervationO).1%o!e

3+

b7 Im'orting test data from e&terna! fi!es$ "*en 6ata Tab%e (vie(G6ata tab%e)G*%ace -ou!e *ointer on data tab%e and ri$ht c%ickG&i%eGi-*ort &ro- &i%eG1%ick okGBro(!( *ath o& the &i%e(it i-*ort! data &rothe &%at &i%e) 1onnectin$ Te!t 6ata to QTP Te!t a! above and run the te!t.

c7 Im'orting test data from e&terna! %'read sheets$


"*en 6ata Tab%e (vie(G6ata tab%e)G*%ace -ou!e *ointer on data tab%e and ri$ht c%ickG&i%eGi-*ort &ro- &i%eG1%ick okGBro(!e *ath o& the e5ce% !heet (it i-*ort! data &ro- the e5ce% !heet) 1onnectin$ Te!t 6ata to QTP Te!t a! above and run the te!t. 6. I-*ortin$ te!t data &ro- 6ata ba!e!D Throu$h 6ata tab%e (e can i-*ort Te!t 6ata &ro- 6ata ba!e!, but &ir!t (e have to create ;$et the 64N(6ata !ource Na-e)I (e have to u!e 4QL 1o--and!. #7 2reating a Test +ata,ase$ o'en M% Access @or we can use any other data,ase)7 4tart *ro$ra-!GM4 "&&iceGM4 0cce!!G&i%e Gne(G4e%ect b%ank 6ataba!eGenter na-e o& the databa!eG4ave (ith -db e5ten!ion. 1reatin$ Tab%e!D 4e%ect 1reate tab%e in de!i$n vie(G,nter &ie%d na-e(0$ent)and 4e%ect data ty*e(te5t) Like thi! (e can create nu-ber o& &ie%d!G!aveIenter tab%e na-e. ,nterin$ 6ata into Tab%e!D 4e%ect tab%eGenter the data. 2reating +%8 D im'orting data Navi$ationD vie(Gdata tab%eGP%ace -ou!e *ointer on 6ata tab%eG!heetGi-*ortG&ro- databa!e(6ataba!e 7uery (i9ard o*en!)Gchoo!e W!*eci&y 4QL !tate-ent! -anua%%yGc%ick ne5t Gc%ick createGc%ick ne(G!e%ect driver ty*eGc%ick ne5t Gbro(!e *ath to !toreG enter 64N Na-eG1%ick 4aveGc%ick ne5tGc%ick &ini!hG!e%ectGbro(!e the databa!eI !e%ectGc%ick okGc%ick okG!e%ect 64NGc%ick okGenter 4QL !tate-ent (!e%ect V&ro- %o$in)Gc%ick &ini!h. NoteD 64N 1reation i! one ti-e activity, by u!in$ the 64N (e can $et data &or nu-ber o& te!t!.

-7 3etching Test +ata direct!y from 3!at fi!es


.)7 3etching Test +ata direct!y from &ce! %heets

0) 3etching Test +ata direct!y from +ata,ases

'0

n(ironment Varia,!es in QTP


The!e are $%oba% variab%e!E i& (e (ant to u!e !o-e variab%e! $%oba%%y (8ro- nu-ber o& te!t!) dec%arin$ a! $%oba% variab%e! i! better. I& (e dec%are a! %oca% variab%e! in nu-ber o& te!t!, -odi&ication! are di&&icu%t. Ty'es of n(ironment (aria,!es$

<. Bui!t in (aria,!es$ The!e are !y!te- de&ined variab%e!, (e can acce!! &ro- a%% te!t! but the!e are de!i$ned a! read on%y. 2. 6ser defined (aria,!es$ 3ariab%e! that (e *rede&ine in the active e5terna% environ-ent variab%e! &i%e. +e can create a! -any &i%e! a! (e (ant and (e can chan$e va%ue! o& variab%e!. 6sage of en(ironment (aria,!es$ 4ynta5D 3ariab%e Q ,nviron-ent(Renviron-ent variab%e na-eS) ,5D NQ,nviron-ent (R0ctionNa-eS) M!$bo5 5 &am'!e %cri't$ Product6ir Qenviron-ent (OProduct6irO) a**Q OP!a-*%e!P&%i$htPa**P&%i$htBa.e5eO 4y!te-uti%.'un Product6ir I a** 6ia%o$(OLo$inO).0ctivate 6ia%o$(OLo$inO).+in,dit(O0$ent Na-eDO).4et O$creddyO 6ia%o$(OLo$inO).+in,dit(OPa!!(ordDO).4et4ecure OBb@cA>&2<0 &&=>=cc<C=ba>c2B @C0C<b>=>B0 O 6ia%o$(OLo$inO).+inButton(O")O).1%ick 2reating user defined en(ironment (aria,!es$ Navi$ationD 8i%e G !ettin$! G ,nviron-ent G !e%ect variab%e ty*e a! u!er de&ined G c%ick add icon (L) G enter variab%e na-e I 3a%ue G c%ick ok (%ike thi! (e can create nu-ber o& variab%e!) G c%ick e5*ort G bro(!e *ath I enter &i%e na-e, !ave (ith 5-% e5ten!ion G c%ick ok. Associating en(ironment (aria,!e fi!e$ Navi$ationD 8i%e G !ettin$! G,nviron-ent G !e%ect variab%e ty*e a! u!er de&ined G check R%oad variab%e! and va%ue! &ro- the e5terna% &i%eS G bro(!e *ath o& the 5-% &i%e G c%ick a**%y I ok.

'1

"r "e can !oad en(ironment fi!e direct!y ,nviron-ent.%oad&ro-&i%eS*ath o& the 5-% &i%eS 6sage of user defined n(ironment (aria,!es$

0!!ociate environ-ent &i%e to current te!tD 3ariab%e Q ,nviron-ent (R3ariab%e Na-eS) NQenviron-ent (RcityS) M!$bo5 5 Modifying n(ironment fi!es$

4e%ect NML &i%eGo*en (ith note*adG-odi&y the va%ue!G4ave.

'2

Actions
Action$ 0 4et o& 4tate-ent! &or *er&or-in$ a Ta!k or Ta!k!. +e divide our te!t into action! to !trea-%ine the *roce!! o& te!tin$. Pur'ose of Actions$ 8or better under!tandabi%ity 8or reu!in$ co-*onent! Ty'es of Actions$ <) Non 'e u!ab%e action! 2) 'e u!ab%e action! @) ,5terna% action! 9'erations on Actions$ X 1reatin$ 0ction! X 4*%ittin$ 0ction! X 'ena-in$ 0ction! X 6e%etin$ 0ction! X 1a%%in$ an 0ction X 1o*yin$ an 0ction X Makin$ an 0ction 'eu!ab%e;Non 'eu!ab%e 2reating an Action$ In!ertGca%% to ne( actionGenter na-e o& the actionGc%ick ok 4te*!D <. 1reate re7uired action!(e5 %o$in, in!ert,de%te) 2. Pre*are 4cri*t! &or tho!e action!. %'!itting an action$ Navi$ationD P%ace cur!or in de!ired %ocationG,dit -enuGactionG!*%it actionG,nter 0ction < na-e I action 2 na-e. 4te*!D <. .enerate tota% te!t in the de&au%t action 2. 4*%it into -eanin$&u% action!.

'3

NoteD 0t a ti-e (e can !*%it one action! into 2 action!. /enaming actions$ 4e%ect de!ired action in action dro* do(n bo5G edit -enuGactionGrena-e actionG-odi&y the na-eGc%ick ok. +e!eting Actions$ 4e%ect de!ired action in action dro* do(n bo5Gedit -enuGactionGde%ete actionGcon&ir- de%etion. 2a!!ing an action$ In!ertGca%% to e5i!tin$ actionGbro(!e *ath o& the te!tG!e%ect de!ired actionGc%ick ok. NoteD / canHt edit 2o'ying an actionD In!ertGca%% to co*y o& actionGbro(!e *ath o& the te!tG!e%ect de!ired actionGc%ick ok. NoteD (e can edit thi! action. Ma?ing an action reusa,!e$ 4e%ect Non 'eu!ab%e action Gedit GactionGaction *ro*ertie!Gcheck reu!ab%e action check bo5 Gc%ick ok.

''

VB %cri't
@3undamenta!s and 3eatures)
#) Introduction )) 2omments *) VB %cri't Varia,!es -) VB %cri't +ata Ty'es .) VB %cri't 9'erators 0) In'ut;9ut'ut 9'erations 1) 2onstants A) 2onditiona! %tatements B) Loo' through 2ode #E) VB %cri't Procedures ##) Procedures #)) VB%cri't synta& ru!es and guide!ines #*) rrors

#7E Introduction
3B4cri*t i! a !cri*tin$ %an$ua$e.

'0

0 !cri*tin$ %an$ua$e i! a %i$ht(ei$ht *ro$ra--in$ %an$ua$e. 3B4cri*t i! a %i$ht ver!ion o& Micro!o&tK! *ro$ra--in$ %an$ua$e 3i!ua% Ba!ic.

+hen a 3B4cri*t i! in!erted into a HTML docu-ent, the Internet bro(!er (i%% read the HTML and inter*ret the 3B4cri*t. The 3B4cri*t can be e5ecuted i--ediate%y, or at a %ater event. Micro!o&t 3i!ua% Ba!ic 4cri*tin$ ,dition brin$! active !cri*tin$ to a (ide variety o& environ-ent!, inc%udin$ +eb c%ient !cri*tin$ in Micro!o&t Internet ,5*%orer and +eb !erver !cri*tin$ in Micro!o&t Internet In&or-ation 4ervice. <.< +indo(! 4cri*t Ho!t (+4H) It i! a +indo(! ad-ini!tration too%. +4H create! an environ-ent &or ho!tin$ !cri*t!. That i!, (hen a !cri*t arrive! at your co-*uter, +4H *%ay! the *art o& the ho!t Y it -ake! ob#ect! and !ervice! avai%ab%e &or the !cri*t and *rovide! a !et o& $uide%ine! (ithin (hich the !cri*t i! e5ecuted. 0-on$ other thin$!, +indo(! 4cri*t Ho!t -ana$e! !ecurity and invoke! the a**ro*riate !cri*t en$ine +indo(! 4cri*t Ho!t i! bui%t into Micro!o&t +indo(! CA, 2000, and Mi%%enniu,dition! and hi$her ver!ion!.

0 +indo(! !cri*t i! a te5t &i%e. +e can create a !cri*t (ith any te5t editor a! %on$ a! (e !ave our !cri*t (ith a +4H:co-*atib%e !cri*t e5ten!ion (.#!, vb!, or .(!&). The -o!t co--on%y avai%ab%e te5t editor i! a%ready in!ta%%ed on our co-*uter Y Note*ad. +e can a%!o u!e your &avorite HTML editor, 3b!,dit, Micro!o&t 3i!ua% 1LL, or 3i!ua% Inter6ev. #7) 2reating a scri't with 8ote'ad <. 4tart Note*ad. 2. +rite your !cri*t. 8or e5a-*%e *ur*o!e!, ty*e M!$bo5 OHe%%o 3B 4cri*tO 3. 4ave thi! te5t &i%e (ith a .vb! e5ten!ion (in!tead o& the de&au%t .t5t e5ten!ion). 8or e5a-*%e, He%%o.vb! B. Navi$ate to the &i%e you #u!t !aved, and doub%e:c%ick it. =. +indo(! 4cri*t Ho!t invoke! the 3B 4cri*t en$ine and run! your !cri*t. In the e5a-*%e, a -e!!a$e bo5 i! di!*%ayed (ith the -e!!a$e OHe%%o 3B 4cri*tO

#7* Hosting

n(ironments and %cri't

ngines

4cri*t! are o&ten e-bedded in +eb *a$e!, either in an HTML *a$e (on the c%ient !ide) or in an 04P *a$e (on the !erver !ide). In the ca!e o& a !cri*t e-bedded in an HTML *a$e, the en$ine co-*onent that inter*ret! and run! the !cri*t code i! %oaded by the +eb bro(!er, !uch a! Internet ,5*%orer. In the ca!e o& a !cri*t e-bedded in an 04P *a$e, the en$ine that inter*ret! and run! the !cri*t code i! bui%t into Internet In&or-ation 4ervice! (II4).

'2

+indo(! 4cri*t Ho!t e5ecute! !cri*t! that e5i!t out!ide an HTML or 04P *a$e and that !tand on their o(n a! te5t &i%e!. <.B 0vai%ab%e 4cri*t ,n$ine! .enera%%y, (e (rite !cri*t! in either Micro!o&t 24cri*t or 3B4cri*t, the t(o !cri*t en$ine! that !hi* (ith Micro!o&t +indo(! CA, 2000 and Mi%%enniu- ,dition!. +e can u!e other !cri*t en$ine!, !uch a! Per%, ',NN, and Python, (ith +indo(! 4cri*t Ho!t. 0 !tand:a%one !cri*t (ritten in 24cri*t ha! the .#! e5ten!ionE a !tand:a%one !cri*t (ritten in 3B4cri*t ha! the .vb! e5ten!ion. The!e e5ten!ion! are re$i!tered (ith +indo(!. +hen (e run one o& the!e ty*e! o& &i%e!, +indo(! !tart! +indo(! 4cri*t Ho!t, (hich invoke! the a!!ociated !cri*t en$ine to inter*ret and run the &i%e.

)7E 2omments
The co**ent ar$u-ent i! the te5t o& any co--ent (e (ant to inc%ude.

'3

)7E Pur'ose of comments$ o o +e can u!e co--ent! &or -akin$ the !cri*t under!tandab%e. +e can u!e co--ent! &or -akin$ one or -ore !tate-ent! di!ab%e &roe5ecution.

)7# %ynta& /em co--ent ($fter the Rem e(word# a space is re0)ired before co**ent.% "r A'ostro'he @F) !y-bo% be&ore the co--ent )7) 2omment;6ncomment a ,!oc? of statements o o 4e%ect b%ock o& !tate-ent and u!e !hort cut key 1tr% L M (for co**ent% 4e%ect co--ent b%ock and u!e !hort cut key 1tr% L 4hi&t L M (for )nco**ent%

*7E VB %cri't Varia,!es


0 variab%e i! a convenient *%aceho%der that re&er! to a co-*uter -e-ory %ocation (here (e can !tore *ro$ra- in&or-ation that -ay chan$e durin$ the ti-e our !cri*t i! runnin$.

'7

*7# +ec!aring Varia,!es +e dec%are variab%e! e5*%icit%y in our !cri*t u!in$ the +im !tate-ent, the Pu,!ic !tate-ent, and the Pri(ate !tate-ent. 8or e5a-*%eD 6i- city 6i- 5 +e dec%are -u%ti*%e variab%e! by !e*aratin$ each variab%e na-e (ith a co--a. 8or e5a-*%eD 6i- 5, To*, Botto-, Le&t, 'i$ht

+e can a%!o dec%are a variab%e i-*%icit%y by !i-*%y u!in$ it! na-e in our !cri*t. That i! not $enera%%y a $ood *ractice becau!e (e cou%d -i!!*e%% the variab%e na-e in one or -ore *%ace!, cau!in$ une5*ected re!u%t! (hen our !cri*t i! run. 8or that rea!on, the 9'tion &'!icit !tate-ent i! avai%ab%e to re7uire e5*%icit dec%aration o& a%% variab%e!. The 9'tion *7) 9'tion &'!icit !tate-ent !hou%d be the &ir!t !tate-ent in our !cri*t. &'!icit

8orce! e5*%icit dec%aration o& a%% variab%e! in a !cri*t.

9'tion &'!icit K 8orce e5*%icit variab%e dec%aration. 6i- My3ar K 6ec%are variab%e. MyInt Q <0 K /ndec%ared variab%e $enerate! error. My3ar Q <0 K 6ec%ared variab%e doe! not $enerate error. *7* 8aming /estrictions for Varia,!es

3ariab%e na-e! &o%%o( the !tandard ru%e! &or na-in$ anythin$ in 3B4cri*t. 0 variab%e na-eD Mu!t be$in (ith an a%*habetic character. 1annot contain an e-bedded *eriod. Mu!t not e5ceed 2== character!. Mu!t be uni7ue in the !co*e in (hich it i! dec%ared.

*7- %co'e of Varia,!es o 0 variab%eK! !co*e i! deter-ined by (here you dec%are it.

'+

o o

+hen (e dec%are a variab%e (ithin a *rocedure, on%y code (ithin that *rocedure can acce!! or chan$e the va%ue o& that variab%e I& (e dec%are a variab%e out!ide a *rocedure, (e -ake it reco$ni9ab%e to a%% the *rocedure! in our !cri*t. Thi! i! a !cri*t:%eve% variab%e, and it ha! !cri*t: %eve% !co*e.

*7. Life Time of Varia,!es o o o The %i&eti-e o& a variab%e de*end! on ho( %on$ it e5i!t!. The %i&eti-e o& a !cri*t:%eve% variab%e e5tend! &ro- the ti-e it i! dec%ared unti% the ti-e the !cri*t i! &ini!hed runnin$. 0t *rocedure %eve%, a variab%e e5i!t! on%y a! %on$ a! you are in the *rocedure.

*70 Assigning Va!ues to Varia,!es 3a%ue! are a!!i$ned to variab%e! creatin$ an e5*re!!ion a! &o%%o(!D The variab%e i! on the %e&t !ide o& the e5*re!!ion and the va%ue you (ant to a!!i$n to the variab%e i! on the ri$ht. 8or e5a-*%eD B Q 200 1ity Q RHyderabadS *71 %ca!ar Varia,!es and Array Varia,!es 0 variab%e containin$ a !in$%e va%ue i! a !ca%ar variab%e. 0 variab%e containin$ a !erie! o& va%ue!, i! ca%%ed an array variab%e. 0rray variab%e! and !ca%ar variab%e! are dec%ared in the !a-e (ay, e5ce*t that the dec%aration o& an array variab%e u!e! *arenthe!e! () &o%%o(in$ the variab%e na-e. ,5a-*%eD 6i- 0(@) 0%thou$h the nu-ber !ho(n in the *arenthe!e! i! @, a%% array! in 3B4cri*t are 9ero: ba!ed, !o thi! array actua%%y contain! B e%e-ent!.

+e a!!i$n data to each o& the e%e-ent! o& the array u!in$ an inde5 into the array. Be$innin$ at 9ero and endin$ at <0, data can be a!!i$ned to the e%e-ent! o& an array a! &o%%o(!D 0(0) 0(<) 0(2) 0(@) Q Q Q Q 2=> @2B <00 ==

00

4i-i%ar%y, the data can be retrieved &ro- any e%e-ent u!in$ an inde5 into the *articu%ar array e%e-ent you (ant. 8or e5a-*%eD 4o-e3ariab%e Q 0(B) 0rray! arenKt %i-ited to a !in$%e di-en!ion. Fou can have a! -any a! >0 di-en!ion!, a%thou$h -o!t *eo*%e canKt co-*rehend -ore than three or &our di-en!ion!. 0rray! arenKt %i-ited to a !in$%e di-en!ion. +e can have a! -any a! >0 di-en!ion!, a%thou$h -o!t *eo*%e canKt co-*rehend -ore than three or &our di-en!ion!. In the &o%%o(in$ e5a-*%e, the MyTab%e variab%e i! a t(o:di-en!iona% array con!i!tin$ o& > ro(! and << co%u-n!D 6i- MyTab%e(=, <0)

In a t(o:di-en!iona% array, the &ir!t nu-ber i! a%(ay! the nu-ber o& ro(!E the !econd nu-ber i! the nu-ber o& co%u-n!.

*7A +ynamic Arrays +e can a%!o dec%are an array (ho!e !i9e chan$e! durin$ the ti-e our !cri*t i! runnin$. Thi! i! ca%%ed a dyna-ic array.

The array i! initia%%y dec%ared (ithin a *rocedure u!in$ either the +im !tate-ent or u!in$ the /e+im !tate-ent. Ho(ever, &or a dyna-ic array, no !i9e or nu-ber o& di-en!ion! i! *%aced in!ide the *arenthe!e!. 8or e5a-*%eD 6i- My0rray() 'e6i- 0nother0rray() To u!e a dyna-ic array, you -u!t !ub!e7uent%y u!e /e+im to deter-ine the nu-ber o& di-en!ion! and the !i9e o& each di-en!ion.

In the &o%%o(in$ e5a-*%e, /e+im !et! the initia% !i9e o& the dyna-ic array to 2=. 0 !ub!e7uent /e+im !tate-ent re!i9e! the array to @0, but u!e! the Preser(e key(ord to *re!erve the content! o& the array a! the re!i9in$ take! *%ace. 'e6i- My0rray(2=) 'e6i- Pre!erve My0rray(@0)

01

There i! no %i-it to the nu-ber o& ti-e! (e can re!i9e a dyna-ic array, a%thou$h i& (e -ake an array !-a%%er, (e %o!e the data in the e%i-inated e%e-ent!.

-7E VB %cri't +ata Ty'es


3B4cri*t ha! on%y one data ty*e ca%%ed a Variant. 0 Variant i! a !*ecia% kind o& data ty*e that can contain di&&erent kind! o& in&or-ation, de*endin$ on ho( it i! u!ed. Becau!e Variant i! the on%y data ty*e in 3B4cri*t, it i! a%!o the data ty*e returned by a%% &unction! in 3B4cri*t. B.< 3ariant 4ubty*e! Beyond the !i-*%e nu-eric or !trin$ c%a!!i&ication!, a Variant can -ake &urther di!tinction! about the !*eci&ic nature o& nu-eric in&or-ation. 8or e5a-*%e, (e can have nu-eric in&or-ation that re*re!ent! a date or a ti-e. +hen u!ed (ith other date or ti-e data, the re!u%t i! a%(ay! e5*re!!ed a! a date or a ti-e. +e can a%!o have a rich variety o& nu-eric in&or-ation ran$in$ in !i9e &ro- Boo%ean va%ue! to hu$e &%oatin$:*oint nu-ber!. The!e di&&erent cate$orie! o& in&or-ation that can be contained in a Variant are ca%%ed !ubty*e!. Mo!t o& the ti-e, (e can #u!t *ut the kind o& data (e (ant in a Variant, and the Variant behave! in a (ay that i! -o!t a**ro*riate &or the data it contain!. The &o%%o(in$ tab%e !ho(! !ubty*e! o& data that a Variant can contain.

%u,ty'e ,-*ty

+escri'tion Variant i! uninitia%i9ed. 3a%ue i! 0 &or nu-eric variab%e! or a 9ero: %en$th !trin$ (OO) &or !trin$ variab%e!. Variant intentiona%%y contain! no va%id data. 1ontain! either True or 8a%!e. 1ontain! inte$er in the ran$e 0 to 2==. 1ontain! inte$er in the ran$e :@2, >A to @2, > . :C22,@@ ,20@,>A=,B .=A0A to C22,@@ ,20@,>A=,B .=A0 . 1ontain! inte$er in the ran$e :2,<B ,BA@,>BA to 2,<B ,BA@,>B . 1ontain! a !in$%e:*reci!ion, &%oatin$:*oint nu-ber in the ran$e :@.B02A2@,@A to :<.B0<2CA,:B= &or ne$ative va%ue!E <.B0<2CA,:B= to @.B02A2@,@A &or *o!itive va%ue!. 1ontain! a doub%e:*reci!ion, &%oatin$:*oint nu-ber in the ran$e :<. C >C@<@BA>2@2,@0A to :B.CB0>=>B=AB<2B ,:@2B &or ne$ative va%ue!E B.CB0>=>B=AB<2B ,:@2B to <. C >C@<@BA>2@2,@0A &or *o!itive va%ue!. 1ontain! a nu-ber that re*re!ent! a date bet(een 2anuary <, <00 to 6ece-ber @<, CCCC. 1ontain! a variab%e:%en$th !trin$ that can be u* to a**ro5i-ate%y 2 bi%%ion character! in %en$th. 1ontain! an ob#ect.

Nu%% Boo%ean Byte Inte$er 1urrency Lon$ 4in$%e 6oub%e

6ate (Ti-e) 4trin$ "b#ect

02

,rror

1ontain! an error nu-ber.

+e can u!e conver!ion &unction! to convert data &ro- one !ubty*e to another. In addition, the 3arTy*e &unction return! in&or-ation about ho( your data i! !tored (ithin a Variant.

.7E VB %cri't 9'erators


"*erator! are u!ed &or *er&or-in$ -athe-atica%, co-*ari!on and %o$ica% o*eration!. 3B4cri*t ha! a &u%% ran$e o& o*erator!, inc%udin$ arith-etic o*erator!, co-*ari!on o*erator!, concatenation o*erator!, and %o$ica% o*erator!. -7# 9'erator Precedence +hen !evera% o*eration! occur in an e5*re!!ion, each *art i! eva%uated and re!o%ved in a *redeter-ined order ca%%ed o*erator *recedence. +e can u!e *arenthe!e! to override the order o& *recedence and &orce !o-e *art! o& an e5*re!!ion to be eva%uated be&ore other!. "*eration! (ithin *arenthe!e! are a%(ay! *er&or-ed be&ore tho!e out!ide. +ithin *arenthe!e!, ho(ever, !tandard o*erator *recedence i! -aintained. +hen e5*re!!ion! contain o*erator! &ro- -ore than one cate$ory, arith-etic o*erator! are eva%uated &ir!t, co-*ari!on o*erator! are eva%uated ne5t, and %o$ica% o*erator! are eva%uated %a!t. 1o-*ari!on o*erator! a%% have e7ua% *recedenceE that i!, they are eva%uated in the %e&t:to:ri$ht order in (hich they a**ear. 0rith-etic and %o$ica% o*erator! are eva%uated in the &o%%o(in$ order o& *recedence. -7) Arithmetic 9'erators$ 9'erator <) ,5*onentiation "*erator (Z) 2) Mu%ti*%ication "*erator (V) @) 6ivi!ion "*erator (;) B) Inte$er 6ivi!ion "*erator (P) =) Mod "*erator >) 0ddition "*erator (L) ) 4ubtraction "*erator (:) A) 1oncatenation "*erator (I) +escri'tion 'ai!e! a nu-ber to the *o(er o& an e5*onent. Mu%ti*%ie! t(o nu-ber!. 6ivide! t(o nu-ber! and return! a &%oatin$:*oint re!u%t. 6ivide! t(o nu-ber! and return! an inte$er re!u%t. 6ivide! t(o nu-ber! and return! on%y the re-ainder. 4u-! t(o nu-ber!. 8ind! the di&&erence bet(een t(o nu-ber! or indicate! the ne$ative va%ue o& a nu-eric e5*re!!ion. 8orce! !trin$ concatenation o& t(o e5*re!!ion!.

03

-7* 2om'arison 9'erators /!ed to co-*are e5*re!!ion!. 9'erator <) Q 2) [G @) [ B) G +escri'tion ,7ua% to Not e7ua% to Le!! than .rater than 9'erator =) [Q >) GQ ) I! +escri'tion Le!! than or e7ua% to .reater than or e7ua% to "b#ect e7uiva%ence

-7- 2oncatenation 9'erators "*erator <) 0ddition "*erator @G) 6e!cri*tion 4u-! t(o nu-ber!. If Then <) Both e5*re!!ion! are nu-eric 0dd. 2) Both e5*re!!ion! are !trin$! 1oncatenate. @) "ne e5*re!!ion i! nu-eric and 0dd. the other i! a !trin$ 8orce! !trin$ concatenation o& t(o e5*re!!ion!.

2) 1oncatenation "*erator (D)

-7. Logica! 9'erators 9'erator <) Not 2) 0nd @) "r B) Nor =) ,7v >) I-* +escri'tion Per&or-! %o$ica% ne$ation on an e5*re!!ion. Per&or-! a %o$ica% con#unction on t(o e5*re!!ion!. Per&or-! a %o$ica% di!#unction on t(o e5*re!!ion!. Per&or-! a %o$ica% e5c%u!ion on t(o e5*re!!ion!. Per&or-! a %o$ica% e7uiva%ence on t(o e5*re!!ion!. Per&or-! a %o$ica% i-*%ication on t(o e5*re!!ion!. %ynta& re!u%tQ 8ot e5*re!!ion re!u%tQ e5*re!!ion< And e5*re!!ion2 re!u%tQ e5*re!!ion< 9r e5*re!!ion2 re!u%tQ e5*re!!ion< <or e5*re!!ion2 re!u%tQ e5*re!!ion< C( e5*re!!ion2 re!u%tQ e5*re!!ion< Im' e5*re!!ion2

0) In'ut;9ut'ut 9'erations
07# In'utBo& 3unction 6i!*%ay! a *ro-*t in a dia%o$ bo5, (ait! &or the u!er to in*ut te5t or c%ick a button, and return! the content! o& the te5t bo5.

0'

&am'!e$ 6i- In*ut In*ut Q In'utBo&@O,nter your na-eO) M!$Bo5 (OFou enteredD O I In*ut) 07) MsgBo& 3unction 6i!*%ay! a -e!!a$e in a dia%o$ bo5, (ait! &or the u!er to c%ick a button, and return! a va%ue indicatin$ (hich button the u!er c%icked. &am'!e$ 6i- My3ar My3ar Q MsgBo& @OHe%%o +or%dTOH >=H OM!$Bo5 ,5a-*%eO) K My3ar contain! either < or 2, de*endin$ on (hich button i! c%icked. 1) VB %cri't 2onstants 0 con!tant i! a -eanin$&u% na-e that take! the *%ace o& a nu-ber or !trin$ and never chan$e!. 17# 2reating 2onstants +e create u!er:de&ined con!tant! in 3B4cri*t u!in$ the 2onst !tate-ent. /!in$ the 2onst !tate-ent, (e can create !trin$ or nu-eric con!tant! (ith -eanin$&u% na-e! and a!!i$n the- %itera% va%ue!. 2onst statement 6ec%are! con!tant! &or u!e in *%ace o& %itera% va%ue!. &am'!e$ 1on!t My4trin$ Q OThi! i! -y !trin$.O 1on!t My0$e Q BC 1on!t 1uto&&6ate Q \>:<:C \ Note that 4trin$ %itera% i! enc%o!ed in 7uotation -ark! (O O). 'e*re!ent 6ate %itera%! and ti-e %itera%! by enc%o!in$ the- in nu-ber !i$n! (\). +e dec%are -u%ti*%e con!tant! by !e*aratin$ each con!tant na-e and va%ue (ith a co--a. 8or e5a-*%eD 1on!t *riceQ <00, cityQ RHyderabadS, 5Q 2

A) 2onditiona! %tatements
+e can contro% the &%o( o& our !cri*t (ith conditiona% !tate-ent! and %oo*in$ !tate-ent!. /!in$ conditiona% !tate-ent!, (e can (rite 3B4cri*t code that -ake! deci!ion! and re*eat! action!. The &o%%o(in$ conditiona% !tate-ent! are avai%ab%e in 3B4cri*tD

00

#) IfIThenI !se %tatement )) %e!ect 2ase %tatement A.< Makin$ 6eci!ion! /!in$ I&...Then...,%!e The If777Then777 !se !tate-ent i! u!ed to eva%uate (hether a condition i! True or 3a!se and, de*endin$ on the re!u%t, to !*eci&y one or -ore !tate-ent! to run. /!ua%%y the condition i! an e5*re!!ion that u!e! a co-*ari!on o*erator to co-*are one va%ue or variab%e (ith another. If777Then777 !se !tate-ent! can be ne!ted to a! -any %eve%! a! you need. A7#7# /unning a %tatements if a 2ondition is True (!in$%e !tate-ent) To run on%y one !tate-ent (hen a condition i! True, u!e the !in$%e:%ine !ynta5 &or the If777Then777 !se !tate-ent. +im my+ate my+ate J K);#*;BAK If my+ate L 8ow Then my+ate J 8ow A7#7) /unning %tatements if a 2ondition is True (-u%ti*%e !tate-ent!)

To run -ore than one %ine o& code, (e -u!t u!e the -u%ti*%e:%ine (or b%ock) !ynta5. Thi! !ynta5 inc%ude! the ,nd I& !tate-ent. 6i- 5 5Q 20 I& 5G<0 Then -!$bo5 OHe%%o ..1.'eddyO -!$bo5 O5 va%ue i!D OI5 -!$bo5 OBye ByeO ,nd I& A7#7* /unning 2ertain %tatements if a 2ondition is True and /unning 9thers if a 2ondition is 3a!se

+e can u!e an If777Then777 !se !tate-ent to de&ine t(o b%ock! o& e5ecutab%e !tate-ent!D one b%ock to run i& the condition i! True, the other b%ock to run i& the condition i! 3a!se. &am'!e$ 6i- 5 5Q In*utbo5 (O ,nter a va%ueO) I& 5G<00 Then M!$bo5 OHe%%o ..1.'eddyO M!$bo5 ON i! a Bi$ Nu-berO M!$bo5 ON va%ue i!D OIN ,%!e M!$bo5 O.1'O

02

M!$bo5 ON i! a 4-a%% Nu-berO M!$bo5 ON va%ue i!D OIN ,nd I& A7#7- +eciding Between %e(era! A!ternati(es 0 variation on the If777Then777 !se !tate-ent a%%o(! u! to choo!e &ro- !evera% a%ternative!. 0ddin$ !seIf c%au!e! e5*and! the &unctiona%ity o& the If777Then777 !se !tate-ent !o (e can contro% *ro$ra- &%o( ba!ed on di&&erent *o!!ibi%itie!. &am'!e$ 6i- 5 5Q In*utbo5 (O ,nter a va%ueO) I& 5G0 and 5[Q<00 Then M!$bo5 OHe%%o ..1.'eddyO M!$bo5 ON i! a 4-a%% Nu-berO M!$bo5 ON va%ue i! OI5 ,%!e I8 5G<00 and 5[Q=00 Then M!$bo5 OHe%%o .1'O M!$bo5 ON i! a Mediu- Nu-berO ,%!e I8 5G=00 and 5[Q<000 Then M!$bo5 OHe%%o 1handra Mohan 'eddyO M!$bo5 ON i! a Lar$e Nu-berO ,%!e M!$bo5 OHe%%o 4irO M!$bo5 ON i! a .rand Nu-berO ,nd I& ,nd I& ,nd I& A7#7. &ecuting a certain ,!oc? of statements when two ; more conditions are True @8ested If777) &am'!e$ 6i- 4tate, 'e$ion 4tateQIn*utbo5 (O,nter a 4tateO) 'e$ionQIn*utbo5 (O,nter a 'e$ionO) I& !tateQ O0PO Then I& 'e$ionQ OTe%an$anaO Then -!$bo5 OHe%%o ..1.'eddyO -!$bo5 O6i!t count i! <0O ,%!e i& 'e$ionQ O'aya%a!e-aO Then -!$bo5 OHe%%o .1'O -!$bo5 O6i!t count i! BO

03

,%!e I& 'e$ionQ O1o!ta%O Then -!$bo5 OHe%%o 1handra -ohan 'eddyO -!$bo5 O6i!t count i! CO ,nd ,nd ,nd ,nd I& I& I& I&

A7) Ma?ing +ecisions with %e!ect 2ase The %e!ect 2ase !tructure *rovide! an a%ternative to If777Then777 !seIf &or !e%ective%y e5ecutin$ one b%ock o& !tate-ent! &ro- a-on$ -u%ti*%e b%ock! o& !tate-ent!. 0 %e!ect 2ase !tate-ent *rovide! ca*abi%ity !i-i%ar to the If777Then777 !se statement, but it -ake! code -ore e&&icient and readab%e. &am'!e$ "*tion e5*%icit 6i- 5,y, "*eration, 'e!u%t 5Q In*utbo5 (O ,nter 5 va%ueO) yQ In*utbo5 (O,nter y va%ueO) "*erationQ In*utbo5 (O,nter an "*erationO) 4e%ect 1a!e "*eration 1a!e OaddO 'e!u%tQ cdb% (5)Lcdb% (y) M!$bo5 OHe%%o ..1.'eddyO M!$bo5 O0ddition o& 5,y va%ue! i! OI'e!u%t 1a!e O!ubO 'e!u%tQ 5:y M!$bo5 OHe%%o ..1.'eddyO M!$bo5 O4ub!traction o& 5,y va%ue! i! OI'e!u%t 'e!u%tQ 5Vy M!$bo5 OHe%%o ..1.'eddyO M!$bo5 OMu%ti*%ication o& 5,y va%ue! i! OI'e!u%t 1a!e OdivO 'e!u%tQ 5;y M!$bo5 OHe%%o ..1.'eddyO M!$bo5 O6ivi!ion o& 5,y va%ue! i! OI'e!u%t 'e!u%tQ 5 -od y M!$bo5 OHe%%o ..1.'eddyO M!$bo5 OMod o& 5,y va%ue! i! OI'e!u%t 1a!e Oe5*oO

1a!e O-u%O

1a!e O-odO

07

'e!u%tQ 5Zy M!$bo5 OHe%%o ..1.'eddyO M!$bo5O,5*onentation o& 5,y va%ue! i! OI'e!u%t 1a!e ,%!e M!$bo5 OHe%%o ..1.'eddyO -!$bo5 O+ron$ "*erationO

,nd 4e%ect A7* 9ther &am'!es

A7*7# "rite a 'rogram for finding out whether the gi(en year is a !ea' year or notM 6i- 5year 5yearQin*utbo5 (O,nter FearO) I& 5year -od BQ0 Then -!$bo5 OThi! i! a Lea* yearO ,%!e -!$bo5 OThi! i! N"TO ,nd I& [email protected] +rite a *ro$ra- &or &indin$ out (hether the $iven nu-ber i!, ,ven nu-ber or "dd nu-berJ +im num numJin'ut,o& @N nter a num,erN) If num mod )JE Then msg,o& NThis is a (en 8um,erN !se msg,o& NThis is a 9dd 8um,erN nd If A7*7* /ead two num,ers and dis'!ay the sumM 6i- nu-<,nu-2, !unu-<Qin*utbo5 (O,nter nu-<O) nu-2Qin*utbo5 (O,nter nu-2O) re0)ire !u-Q 1db% (nu-<) L 1db% (nu-2) 1if we want add two strings conversion -!$bo5 (O4u- i! O I!u-) A7*7- /ead PHTH/ (a!ues and 2a!cu!ate the %im'!e InterestM 6i- *,t, r, !i *Qin*utbo5 (O,nter Princi*%eO) tQin*utbo5 (O,nter Ti-eO) rQin*utbo5 (O,nter 'ate o& Intere!tO) !iQ (*VtVr);<00 K *Q *rinci*%e a-ount, tQti-e in year!, rQ rate o& intere!t

0+

-!$bo5 (O4i-*%e Intere!t i! O I!i)

A7*7. /ead 3our digit num,erH ca!cu!ate D dis'!ay the sum of the num,er or dis'!ay rror message if the num,er is not a four digit num,erM 6i- nu-, !unu-Qin*utbo5 (O,nter a 8our di$it nu-berO) I& Len(nu-) Q B Then !u-Q0 !u-Q!u-Lnu- -od <0 nu-Qnu-;<0 nu-Q %e&t (nu-, @) !u-Q!u-Lnu- -od <0 nu-Qnu-;<0 nu-Q %e&t (nu-, 2) !u-Q!u-Lnu- -od <0 nu-Qnu-;<0 nu-Q %e&t (nu-, <) !u-Q!u-Lnu- -od <0 -!$bo5 (O4u- i! O I!u-) e%!e -!$bo5 ONu-ber, you entered i! not a B di$it nu-berO ,nd I& A7*70 /ead any 3our digit num,er and dis'!ay the num,er in re(erse orderM 6i- nu-,rev nu-Q in*utbo5(O,nter a nu-berO) I& %en(nu-)QB Then revQrevV<0 L nu- -od <0 nu-Qnu-;<0 nu-Q %e&t(nu-,@) revQrevV<0 L nu- -od <0 nu-Qnu-;<0 nu-Q %e&t(nu-,2) revQrevV<0 L nu- -od <0 nu-Qnu-;<0 nu-Q %e&t(nu-,<) revQrevV<0 L nu- -od <0 -!$bo5 O'ever!e "rder o& the nu-ber i! OIrev ,%!e ,nd I& A7*71 /ead - su,:ects mar?sO ca!cu!ate the Tota! mar?s and gradeM @a) If a(erage mar?s 4reater than or eCua! to 1.H grade is +istinction ,) If a(erage mar?s 4reater than or eCua! to 0E and !ess than 1. H then -!$bo5 ONu-ber, you entered i! not a B di$it nu-berO

20

grade is 3irst c) If a(erage mar?s 4reater than or eCua! to .E and !ess than 0E H then grade is %econd d) If a(erage mar?s 4reater than or eCua! to -E and !ess than .E H then grade is Third e) Mini-u- -ark! @= &or any !ub#ect, other(i!e Kno $rade &ai%K) 6i- e,-,*,c, tot eQin*utbo5 (O,nter en$%i!h Mark!O) -Qin*utbo5 (O,nter -ath! Mark!O) *Qin*utbo5 (O,nter *hy!ic! Mark!O) cQin*utbo5 (O,nter che-i!try Mark!O) totQ cdb%(e) L cdb%(-) L cdb%(*) L cdb%(c) -!$bo5 tot I& cdb%(e) GQ@= and cdb%(-) GQ@= and cdb%(*) GQ@= and cdb%(c) GQ@= and tot GQ@00 Then -!$bo5 O.rade i! 6i!tinctionO e%!e I& cdb%(e) GQ@= and cdb%(-) GQ@= and cdb%(*) GQ@= and cdb%(c) GQ@= and tot GQ2B0 and tot[@00 Then -!$bo5 O.rade i! 8ir!tO e%!e I& cdb%(e) GQ@= and cdb%(-) GQ@= and cdb%(*) GQ@= and cdb%(c) GQ@= and tot GQ200 and tot[2B0 Then -!$bo5 O.rade i! 4econdO e%!e I& cdb%(e) GQ@= and cdb%(-) GQ@= and cdb%(*) GQ@= and cdb%(c) GQ@= and tot GQ<>0 and tot[200 Then -!$bo5 O.rade i! ThirdO e%!e -!$bo5 ONo .rade, 8ai%O ,nd ,nd ,nd ,nd I& I& I& I&

[email protected] 6i!*%ay "dd nu-ber! u* to nJ 6i- nu-,n nQIn*utbo5 (O,nter a 3au%eO) 8or nu-Q < to n !te* 2 -!$bo5 nuNe5t A7*7B +is'!ay (en num,ers u' to nM

6i- nu-,n nQIn*utbo5 (O,nter a 3au%eO) 8or nu-Q 2 to n !te* 2

21

-!$bo5 nuNe5t A7*7#E dis'!ay natura! numers u' to n and write in a te&t fi!eM 6i- nu-, n, &!o, -y&i%e nQ in*utbo5 (O,nter any 3a%ueO) nu-Q< 8or nu-Q < to n !te* < 4et &!oQ createob#ect (O!cri*tin$.&i%e!y!te-ob#ectO) !et -y&i%eQ&!o.o*ente5t&i%e (O,DP$cr.t5tO, A, true) -y&i%e.(rite%ine nu-y&i%e.c%o!e Ne5t A7## +is'!ay 8atura! num,ers in re(erse order u' to nM 6i- nu-,n nQIn*utbo5 (O,nter a 3au%eO) 8or nu-Qn to < !te* :< -!$bo5 nuNe5t A7#) +is'!ay 8atura! num,ers sum u' to nM @using 3or7778e&t Loo') 6i- nu-, n, !unQ in*utbo5 (O,nter a 3a%ueO) !u-Q0 8or nu-Q < to n !te* < !u-Q !u-LnuNe5t -!$bo5 !uA7#* +is'!ay 8atura! num,ers sum u' to nM @using "hi!e777"end Loo') 6i- nu-, n, !unQ in*utbo5 (O,nter a 3a%ueO) +hi%e nu- [Qcdb% (n) !u-Q !u-Lnunu-Qnu-L< +end -!$bo5 !uA7#- +is'!ay 8atura! num,ers sum u' to nM @using +o7776nti!777Loo') 6i- nu-, n, !unQ in*utbo5 (O,nter a 3a%ueO) !u-Q0 nu-Q< 6o !u-Q !u-Lnunu-Qnu-L< Loo* /nti% nu- Qcdb% (nL<)

22

-!$bo5 !uA7#. "rite a 3unction for 8atura! 8um,ers sum u' to nM 8unction NNu-1ou (n) 6i- nu-, !u!u-Q0 8or nu-Q < to n !te* < !u-Q !u-LnuNe5t -!$bo5 !u,nd 8unction A.<> 3eri&y (eather the entered <0 di$it va%ue i! a nu-eric va%ue or notJ 6i- a,5,y,9,nunu-QIn*utbo5 (O,nter a Phone Nu-berO) d<Q %e&t (nu-,<) d<0Q'i$ht (nu-,<) d2Q-id (nu-, 2, %en d@Q-id (nu-, @, %en dBQ-id (nu-, B, %en d=Q-id (nu-, =, %en d>Q-id (nu-, >, %en d Q-id (nu-, , %en dAQ-id (nu-, A, %en dCQ-id (nu-, C, %en

(<)) (<)) (<)) (<)) (<)) (<)) (<)) (<))

I& i!nu-eric (d<) Q OTrueO and i!nu-eric (d2) Q OTrueO and i!nu-eric (d@) Q OTrueO and i!nu-eric (dB) Q OTrueOand i!nu-eric (d=) Q OTrueOand i!nu-eric (d>) Q OTrueOand i!nu-eric (d ) Q OTrueOand i!nu-eric (dA) Q OTrueOand i!nu-eric (dC) Q OTrueOand i!nu-eric (d<0) Q OTrueO Then -!$bo5 OIt i! a Nu-eric 3a%ueO e%!e M!$bo5 OIt i! N"T Nu-ericO ,nd I& A.< 3eri&y (eather the entered va%ue i! a <0 di$it va%ue or not and Nu-eric va%ue or notJ (u!in$ -u%ti*%e i& condition!) 6i- a,5,y,9,nunu-QIn*utbo5 (O,nter a Phone Nu-berO) d<Q %e&t (nu-,<) d<0Q'i$ht (nu-,<) d2Q-id (nu-, 2, %en d@Q-id (nu-, @, %en dBQ-id (nu-, B, %en d=Q-id (nu-, =, %en d>Q-id (nu-, >, %en d Q-id (nu-, , %en dAQ-id (nu-, A, %en

(<)) (<)) (<)) (<)) (<)) (<)) (<))

23

dCQ-id (nu-, C, %en (<)) I& %en (nu-) Q<0 Then I& i!nu-eric (d<) Q OTrueO and i!nu-eric (d2) Q OTrueO and i!nu-eric (d@) Q OTrueO and i!nu-eric (dB) Q OTrueOand i!nu-eric (d=) Q OTrueOand i!nu-eric (d>) Q OTrueOand i!nu-eric (d ) Q OTrueOand i!nu-eric (dA) Q OTrueOand i!nu-eric (dC) Q OTrueOand i!nu-eric (d<0) Q OTrueO Then -!$bo5 OIt i! a Nu-eric 3a%ueO ,nd I& ,nd I& I& %en (nu-) [G <0 Then M!$bo5 OIt i! N"T va%id Nu-ber O ,nd I&

B) Loo'ing Through 2ode


o o o o Loo*in$ a%%o(! u! to run a $rou* o& !tate-ent! re*eated%y. 4o-e %oo*! re*eat !tate-ent! unti% a condition i! 3a!seE "ther! re*eat !tate-ent! unti% a condition i! True. There are a%!o %oo*! that re*eat !tate-ent! a !*eci&ic nu-ber o& ti-e!.

2'

The fo!!owing !oo'ing statements are a(ai!a,!e in VB%cri't$ +o777Loo'$ Loo*! (hi%e or unti% a condition i! True. "hi!e777"end$ Loo*! (hi%e a condition i! True. 3or7778e&t$ /!e! a counter to run !tate-ent! a !*eci&ied nu-ber o& ti-e!. 3or ach7778e&t$ 'e*eat! a $rou* o& !tate-ent! &or each ite- in a co%%ection or each e%e-ent o& an array.

C.< /!in$ 6o Loo*! "e can use 6o...Loo* statements to run a ,!oc? of statements an indefinite num,er of times7 The statements are re'eated either whi!e a condition is True or unti! a condition ,ecomes True7 B7#7# /e'eating %tatements "hi!e a 2ondition is True 'e*eat! a b%ock o& !tate-ent! (hi%e a condition i! True or unti% a condition beco-e! True

a) +o "hi!e condition 4tate-ent! ::::::::::: ::::::::::: Loo' "r, (e can u!e thi! be%o( !ynta5D

&am'!e$ 6i- 5 6o +hi%e 5[= 5Q5L< M!$bo5 OHe%%o ..1.'eddyO M!$bo5 OHe%%o QTPO Loo* ,) +o 4tate-ent! ::::::::::: ::::::::::: Loo' "hi!e condition &am'!e$ 6i- 5 5Q< 6o M!$bo5 OHe%%o ..1.'eddyO M!$bo5 OHe%%o QTPO 5Q5L< Loo* +hi%e 5[= B7#7) /e'eating a %tatement 6nti! a 2ondition Becomes True

20

c) +o 6nti! condition 4tate-ent! ::::::::::: ::::::::::: Loo' "r, (e can u!e thi! be%o( !ynta5D &am'!e$ 6i- 5 6o /nti% 5Q= 5Q5L< M!$bo5 O..1.'eddyO M!$bo5 OHe%%o QTPO Loo* "r, (e can u!e thi! be%o( !ynta5D d) +o 4tate-ent! ::::::::::: ::::::::::: Loo' 6nti! condition "r, (e can u!e thi! be%o( !ynta5D

&am'!e$ 6i- 5 5Q< 6o M!$bo5 RHe%%o ..1.'eddyS M!$bo5 OHe%%o QTPO 5Q5L< Loo* /nti% 5Q= B7) "hi!e777"end %tatement ,5ecute! a !erie! o& !tate-ent! a! %on$ a! a $iven condition i! True. 4ynta5D "hi!e condition 4tate-ent! ::::::::::: ::::::::::: "end ,5a-*%eD 6i- 5 5Q0 +hi%e 5[= 5Q5L<

22

-!$bo5 OHe%%o ..1.'eddyO -!$bo5 OHe%%o QTPO +end B7* 3or7778e&t %tatement 'e*eat! a $rou* o& !tate-ent! a !*eci&ied nu-ber o& ti-e!. %ynta&$ 3or co)nter J start to end P%te' stepQ state*ents 8e&t

&am'!e$ 6i- 5 8or 5Q < to = !te* < M!$bo5 OHe%%o ..1.'eddyO Ne5t B7- 3or ach7778e&t %tatement

'e*eat! a $rou* o& !tate-ent! &or each e%e-ent in an array or co%%ection. %ynta&$ 3or ach ite* In arra( 4tate-ent! 8e&t &am'!e$ 6i- a,b,5 (@) aQ20 bQ@0 5(0)Q O0ddition i! OI aLb 5(<)QO4ub!traction i! O I a:b 5(2)Q OMu%ti*%ication i! O I aVb 5(@)Q O6ivi!ion i! O I a;b 8or ,ach e%e-ent In 5 -!$bo5 e%e-ent Ne5t &am'!e$

23

My0rray Q 0rray(OoneO,Ot(oO,OthreeO,O&ourO,O&iveO) 3or ach e%e-ent In My0rray -!$bo5 e%e-ent 8e&t <0) 3B 4cri*t Procedure! In 3B4cri*t, there are t(o kind! o& *rocedure!E the %u, *rocedure and the 3unction *rocedure. <<.< 4ub Procedure! 0 %u, *rocedure i! a !erie! o& 3B4cri*t !tate-ent! (enc%o!ed by %u, and !tate-ent!) that *er&or- action! but donKt return a va%ue. nd %u,

0 %u, *rocedure can take ar$u-ent! (con!tant!, variab%e!, or e5*re!!ion! that are *a!!ed by a ca%%in$ *rocedure). I& a %u, *rocedure ha! no ar$u-ent!, it! %u, !tate-ent -u!t inc%ude an e-*ty !et o& *arenthe!e! (). %ynta&$ %u, Proced)re na*e () 4tate-ent! ::::::::::: ::::::::::: nd %u, "r %u, Proced)re na*e (ar$u-ent<, ar$u-ent2) 4tate-ent! ::::::::::: ::::::::::: nd %u, ,5a-*%eD < %u, 1onvertTe-*() te-* Q In*utBo5(OP%ea!e enter the te-*erature in de$ree! 8.O, <)

27

M!$Bo5 OThe te-*erature i! O I 1e%!iu!(te-*) I O de$ree! 1.O nd %u, ,5a-*%eD 2 ##7) 3unction Procedures 0 3unction *rocedure i! a !erie! o& 3B4cri*t !tate-ent! enc%o!ed by the 3unction and nd 3unction !tate-ent!. 0 3unction *rocedure i! !i-i%ar to a %u, *rocedure, but can a%!o return a va%ue. 0 3unction *rocedure can take ar$u-ent! (con!tant!, variab%e!, or e5*re!!ion! that are *a!!ed to it by a ca%%in$ *rocedure). I& a 3unction *rocedure ha! no ar$u-ent!, it! 3unction !tate-ent -u!t inc%ude an e-*ty !et o& *arenthe!e!. 0 3unction return! a va%ue by a!!i$nin$ a va%ue to it! na-e in one or -ore !tate-ent! o& the *rocedure. The return ty*e o& a 3unction i! a%(ay! a Variant. %ynta&$ 3unction Proced)re na*e () 4tate-ent! ::::::::::: ::::::::::: nd 3unction "r 3unction Proced)re na*e (ar$u-ent<, ar$u-ent2) 4tate-ent! ::::::::::: ::::::::::: nd 3unction ,5a-*%eD < 3unction 1e%!iu!(&6e$ree!)

2+

1e%!iu! Q (&6e$ree! : @2) V = ; C nd 3unction ,5a-*%eD 2 3unction ca%(a,b,c) ca% Q (aLbLc) nd 3unction ##7* 4etting +ata into and out of Procedures o o ,ach *iece o& data i! *a!!ed into our *rocedure! u!in$ an ar$u-ent. 0r$u-ent! !erve a! *%aceho%der! &or the data (e (ant to *a!! into our *rocedure. +e can na-e our ar$u-ent! any va%id variab%e na-e. +hen (e create a *rocedure u!in$ either the %u, !tate-ent or the 3unction !tate-ent, *arenthe!e! -u!t be inc%uded a&ter the na-e o& the *rocedure. 0ny ar$u-ent! are *%aced in!ide the!e *arenthe!e!, !e*arated by co--a!.

<<.B /!in$ 4ub and 8unction Procedure! in 1ode A 3unction in our code -u!t a%(ay! be u!ed on the ri$ht !ide o& a variab%e a!!i$n-ent or in an e5*re!!ion. 8or e5a-*%eD Te-* Q 1e%!iu!(&6e$ree!) :"r: M!$Bo5 OThe 1e%!iu! te-*erature i! O I 1e%!iu!(&6e$ree!) I O de$ree!.O

To ca%% a %u, *rocedure &ro- another *rocedure, ty*e the na-e o& the *rocedure a%on$ (ith va%ue! &or any re7uired ar$u-ent!, each !e*arated by a co--a. The 1a%% !tate-ent i! not re7uired, but i& you do u!e it, you -u!t enc%o!e any ar$u-ent! in *arenthe!e!. The &o%%o(in$ e5a-*%e !ho(! t(o ca%%! to the MyProc *rocedure. "ne u!e! the 2a!! !tate-ent in the codeE the other doe!nKt. Both do e5act%y the !a-e thin$.

1a%% MyProc(&ir!tar$, !econdar$) MyProc &ir!tar$, !econdar$

30

Notice that the *arenthe!e! are o-itted in the ca%% (hen the 2a!! !tate-ent i!nKt u!ed.

##) VB %cri't Bui!t in 3unctions


#) Asc 3unction K'eturn! 0N4I character code corre!*ondin$ to &ir!t %etter in a !trin$ 6i- va% va%QOhyderabadO va%Q0!c(va%)

31

-!$bo5 va% )) 2hr 3unction K'eturn! the character a!!ociated (ith the !*eci&ied 0N4I character code. 6i- va% va%Q>= va%Q1hr(va%) -!$bo5 va% K"ut*utD 0 *) +a te 3unction

It return! current !y!te- 6ate 6i- -y6ate -y6ateQ6ate -!$bo5 -y6ate -) A,s 3unction It return! ob!o%ute va%ue o& the $iven nu-ber. 6i- nunu-Q<= .=> nu-Q0b!(nu-) -!$bo5 nu- K"ut*utD <= .=> nu-Q:<= .=> nu-Q0b!(nu-) -!$bo5 nu- K"ut*utD <= .=> NoteD It *rovide *o!itive va%ue .) Array 3unction +e can enter %i!t o& va%ue! u!in$ thi! &unction ,5D 6i- var KLi!t o& !trin$! varQ0rray(OHyderabadO,O1hennaiO, ONe%%oreO) -!$bo5 var(0) Kout*utD Hyderabad

32

-!$bo5 var(<) Kout*utD 1hennai -!$bo5 var(2) Kout*utD Ne%%ore KLi!t o& nu-eric va%ue! varQ0rray(<00,200, @00) -!$bo5 var(0) Kout*utD <00 -!$bo5 var(<) Kout*utD 200 -!$bo5 var(2) Kout*utD @00 KLi!t o& -i5ed va%ue! varQ0rray(<00,OIndiaO, \0<:0=:20<0\) -!$bo5 var(0) Kout*utD <00 -!$bo5 var(<) Kout*utD India -!$bo5 var(2) Kout*utD 0<;0=;20<0 0) IsArray 3unction It check! (eather the $iven variab%e i! an 0rray or not 6i- var<, var2,5 KLi!t o& !trin$! var<Q0rray(OHyderabadO,O1hennaiO, ONe%%oreO) 5Qi!0rray(var<) KIt return! True;8a%!e %ike 'e!u%t -!$bo5 5 5Qi!0rray(var2) -!$bo5 5 1) Is+ate It check! (eather the $iven va%ue i! 6ate ty*e data or not ,5a-*%e!D 6i- -y6ate,5 -y6ateQ<00 5QI!6ate(-y6ate) -!$bo5 5 K"ut*utD 8a%!e

33

-y6ateQOIndiaO 5QI!6ate(-y6ate) -!$bo5 5 K"ut*utD 8a%!e -y6ateQ\<0;0=;20<0\ 5QI!6ate(-y6ate) -!$bo5 5 K"ut*utD True -y6ateQ\<0:0=:20<0\ 5QI!6ate(-y6ate) -!$bo5 5 K"ut*utD True -y6ateQ\<0:0=:<0\ 5QI!6ate(-y6ate) -!$bo5 5 K"ut*utD True -y6ateQ<0:0=:20<0 5QI!6ate(-y6ate) -!$bo5 5 K"ut*utD 8a%!e A) +ate+iff 3unction It *rovide! di&&erence bet(een t(o date!, ba!ed on interva% (day;-onth) 6i- 6ate<, 6ate2,5 6ate<Q\<0:<0:200A\ 6ate2Q\<0:0C:20<0\ 5Q6ate6i&&(OdO, date<,date2) Kd &or day -!$bo5 5K It !ubtract! date< &ro- date2 5Q6ate6i&&(O-O, date<,date2)K - &or -onth -!$bo5 5K It !ubtract! date< &ro- date2 5Q6ate6i&&(OyO, date<,date2) Kit con!ider! day! on%y -!$bo5 5K It !ubtract! date< &ro- date2

3'

NoteD throu$h thi! &unction, (e can day or -onth (i!e di&&rence on%y. B) Is8umeric It check! (eather the $iven va%ue i! nu-eric or not and It *rovide! True;8a%!e %ike 'e!u%t ,5a-*%eD 6i- va%,5 va%QO<00O 5QI!nu-eric(va%) -!$bo5 5 K"ut*utD True va%Q<00 5QI!nu-eric(va%) -!$bo5 5 K"ut*utD True 5QI!nu-eric(=00) -!$bo5 5 K"ut*utD True 5QI!nu-eric(OIndiaO) -!$bo5 5 K"ut*utD 8a%!e #E) Len 3unction It &ind! %e$n$h o& the 4trin$ ,5a-*%eD 6i- va%,5 va%QOHyderabadO 5QLen(va%) -!$bo5 5 K"ut*utD C va%Q<00 5QLen(va%) -!$bo5 5 K"ut*utD @ va%QOHydera<00O 5QLen(va%)

30

-!$bo5 5 K"ut*utD C va%QOhy]^VdeO 5QLen(va%) -!$bo5 5 K"ut*utD va%QO<00O 5QLen(va%) -!$bo5 5 K"ut*utD @ va%Q\<0:<0:20<0\ 5QLen(va%) -!$bo5 5 K"ut*utD <0 5QLen(O)ri!hnaO) -!$bo5 5 K"ut*utD 5QLen()ri!hna) -!$bo5 5 K"ut*utD 0 5QLen() -!$bo5 5 K"ut*utD ,rror ##) Left 3unction 'eturn! a !*eci&ied nu-ber o& charector! o& a $iven !trin$ &ro- %e&t !ide 4ynta5D variab%eQLe&t(!trin$,Len$h) ,5a-*%eD 6i- va%,5 va%QOHyderabadO 5QLe&t(va%,@) -!$bo5 5 K "ut*utD Hyd va%QOC2B A@ B AO 5QLe&t(va%,<)

32

-!$bo5 5 K "ut*utD C

va%QOHC2yderabadO 5QLe&t(va%,@) -!$bo5 5 K "ut*utD HC2 5QLe&t(C2B A@ B A,=) -!$bo5 5 K "ut*utD C2B A va%Q\<0:<0:<0\ 5QLe&t(va%,@) -!$bo5 5 K "ut*utD <0; #)) /ight 3unction 'eturn! a !*eci&ied nu-ber o& charector! o& a $iven !trin$ &ro- 'i$ht !ide ,5a-*%eD 6i- va%,5 va%QOHyderabadO 5Q'i$ht(va%,@) -!$bo5 5 K "ut*utD bad va%QOC2B A@ B AO 5Q'i$ht(va%,<) -!$bo5 5 K "ut*utD A va%QOHC2yderabadO 5Q'i$ht(va%,@) -!$bo5 5 K "ut*utD bad

5Q'i$ht(C2B A@ B A,=) -!$bo5 5 K "ut*utD @ B A va%Q\<0:<0:<0\ 5Q'i$ht(va%,=)

33

-!$bo5 5 K "ut*utD ;20<0 #*) Mid function 'eturn! a !*eci&ied nu-ber o& character! o& a $iven !trin$ ,5a-*%eD 6i- va%,5 va%QOHyderabadO 5QMid(3a%,=,@) -!$bo5 5 K "ut*utD rab va%QOHyderabadO 5QMid(3a%,=) -!$bo5 5 K "ut*utD rabad va%QOC2B A@ B AO 5QMid(va%,>,=) -!$bo5 5 K "ut*utD @ B A va%QOHC2yderabadO 5QMid(va%,<) -!$bo5 5 K "ut*utD HC2yderabad 5QMid(C2B A@ B A,=) -!$bo5 5 K "ut*utD A@ B A va%Q\<0:<0:<0\ 5QMid(va%,=) -!$bo5 5 K "ut*utD 0;20<0 #-) %tr/e(erse retun! rever!e va%ue o& a !trin$ ,5a-*%eD 6i- va%,5 va%QOHyderabadO 5Q4tr'ever!e(va%) -!$bo5 5 K"ut*ut dabaredyH

37

va%QO00<O 5Q4tr'ever!e(va%) -!$bo5 5 K"ut*utD <00 va%Q<002 5Q4tr'ever!e(va%) -!$bo5 5 K"ut*utD 200< va%Q\<0:<0:<0\ 5Q4tr'ever!e(va%) -!$bo5 5 K"ut*utD 0<02;0<;0< 5Q4tr'ever!e(OHyderabadO) -!$bo5 5 K"ut*utD dabaredyH 5Q4tr'ever!e(<00) -!$bo5 5 K"ut*utD 00< #.) %tr2om' 3unction It co-*are! t(o !trin$ (Binary and te5tua%) I& a) Both are e7ua%, return! 0(9ero) b) 4trin$ < $reater than !trin$ 2, return! <(one) b) 4trin$ 2 $reater than !trin$ <, return! :< ,5a-*%eD 6i- !tr<,!tr2,5 !tr<QOIndiaO !tr2QOIndiaO 5Q4tr1o-*(!tr<,!tr2,<) -!$bo5 5 K"ut*ut 0 !tr<QOindiaO

3+

!tr2QOIN6I0O 5Q4tr1o-*(!tr<,!tr2,<) -!$bo5 5 K"ut*ut 0 !tr<QOIndiaO !tr2QOIndianO 5Q4tr1o-*(!tr<,!tr2,<) -!$bo5 5 K"ut*ut :< !tr<QOIndianO !tr2QONdiaO 5Q4tr1o-*(!tr<,!tr2,<) -!$bo5 5 K"ut*ut :< !tr<QOIndianO !tr2QOIndiaO 5Q4tr1o-*(!tr<,!tr2,<) -!$bo5 5 K"ut*ut < !tr<Q<00 !tr2Q<00 5Q4tr1o-*(!tr<,!tr2,<) -!$bo5 5 K"ut*ut 0 !tr<Q<00 !tr2Q<0< 5Q4tr1o-*(!tr<,!tr2,<) -!$bo5 5 K"ut*ut :<

#0) Lcase function 1overt! /**er ca!e va%ue! into Lo(er ca!e 6i- va%,5 va%QOHF6,'0B06O 5QLca!e(va%) -!$bo5 5 K"ut*ut hyderabad

70

va%QOHyderabadO 5QLca!e(va%) -!$bo5 5 K"ut*ut hyderabad va%QOHederaba6O 5QLca!e(va%) -!$bo5 5 K"ut*ut hyderabad va%QOhyderabadO 5QLca!e(va%) -!$bo5 5 K"ut*ut hyderabad 5QLca!e(OHF6,'0B06O) -!$bo5 5 K"ut*ut hyderabad #1) 6case function 1overt! Lo(er ca!e va%ue! into /**er ca!e ,5a-*%eD 6i- va%,5 va%QOHF6,'0B06O 5Q/ca!e(va%) -!$bo5 5 K"ut*ut HF6,'0B06 va%QOHyderabadO 5Q/ca!e(va%) -!$bo5 5 K"ut*ut HF6,'0B06 va%QOHederaba6O 5Q/ca!e(va%) -!$bo5 5 K"ut*ut HF6,'0B06 va%QOhyderabadO 5Q/ca!e(va%) -!$bo5 5 K"ut*ut HF6,'0B06

71

5Q/ca!e(OHF6,'0B06O) -!$bo5 5 K"ut*ut HF6,'0B06 #A) /ound 3unction 'eturn! the round va%ue o& a $iven va%ue i& va%ue deci-a% *oint above .= it return!, ne5t neare!t va%ue, be%o( .= return! be&ore inte$er va%ue. ,5a-*%eD 6i- nu-,5 nu-Q<B.BC 5Q'ound(nu-) -!$bo5 5 K"ut*utD <B nu-Q<B.=C 5Q'ound(nu-) -!$bo5 5 K"ut*utD <= nu-QO<B.BCO 5Q'ound(nu-) -!$bo5 5 K"ut*utD <B nu-QOHydO 5Q'ound(nu-) -!$bo5 5 K"ut*utD ,rror #B) Trim 3unction 'eturn! a co*y o& !trin$ (ithout %eadin$ !*ace! 6i- va% va%QO -!$bo5 5 5QLen(5) -!$bo5 5 va%QO <00O 3B 4cri*tO 5QTri-(va%)

72

5QTri-(va%) -!$bo5 5 5QLen(5) -!$bo5 5 va%QO -!$bo5 5 5QLen(5) -!$bo5 5 va%QO -!$bo5 5 5QLen(5) -!$bo5 5 )E) Ltrim 3unction It re-ove! !*ace! &ro- %e&t !ide o& a !trin$ 6i- va% va%QO -!$bo5 5 5QLen(5) -!$bo5 5 va%QO<00 5QLTri-(va%) -!$bo5 5 5QLen(5) -!$bo5 5 va%QO -!$bo5 5 5QLen(5) 2\]_Z O O 3B 4cri*tO 5QLTri-(va%) 3B 4cri*t O 2\]_ZO

5QTri-(va%)

5QTri-(va%)

5QLTri-(va%)

73

-!$bo5 5 va%QO -!$bo5 5 5QLen(5) -!$bo5 5 va%Q -!$bo5 5 5QLen(5) -!$bo5 5 )#) /trim It re-ove! !*ace! &ro- ri$ht !ide o& a !trin$ 6i- va% va%QO3B 4cri*t 5Q'Tri-(va%) -!$bo5 5 5QLen(5) -!$bo5 5 va%QO -!$bo5 5 5QLen(5) -!$bo5 5 va%QO -!$bo5 5 5QLen(5) -!$bo5 5 va%QO 3B 4cri*t O 2\]_Z O <00 O O <00 3B 4cri*t O

5QLTri-(va%)

5QLTri-(va%)

5Q'Tri-(va%)

5Q'Tri-(va%)

7'

5Q'Tri-(va%) -!$bo5 5 5QLen(5) -!$bo5 5 va%Q -!$bo5 5 5QLen(5) -!$bo5 5 <00

5Q'Tri-(va%)

))) %'!it function 'eturn! a 9ero:ba!ed, one:di-en!iona% array containin$ a !*eci&ied nu-ber o& !ub!trin$! ,5a-*%eD 6i- a,b,5 bQO3B 4cri*t i! a Po(er&u% !cri*tin$ Lan$ua$eO aQ4*%it(b,O O) 5QI!0rray(b) -!$bo5 5 K"ut*utD 8a%!e 5QI!0rray(a) -!$bo5 5 K"ut*utD True -!$bo5 a(>) K"ut*utD Lan$ua$e bQO3B,4cri*t,i!,a,Po(er&u%,!cri*tin$,Lan$ua$eO aQ4*%it(b,O,O) -!$bo5 a(=) K"ut*utD 4cri*tin$ bQO3B 4cri*t i! a Po(er&u% !cri*tin$ Lan$ua$eO aQ4*%it(b) -!$bo5 a(=) K"ut*utD 4cri*tin$ bQO3B^4cri*t^i!^a^Po(er&u%^!cri*tin$^Lan$ua$eO aQ4*%it(b,O^O) -!$bo5 a(=) K"ut*utD 4cri*tin$ bQO3B4cri*ti!aPo(er&u%!cri*tin$Lan$ua$eO aQ4*%it(b) -!$bo5 a(=) K"ut*utD ,rror

70

#)) VB%cri't synta& ru!es and guide!ines


2<.< 1a!e:!en!itivityD By de&au%t, 3B4cri*t i! not ca!e !en!itive and doe! not di&&erentiate bet(een u**er: ca!e and %o(er:ca!e !*e%%in$ o& (ord!, &or e5a-*%e, in variab%e!, ob#ect and -ethod na-e!, or con!tant!. 8or e5a-*%e, the t(o !tate-ent! be%o( are identica% in 3B4cri*tD Bro(!er(OMercuryO).Pa$e(O8ind a 8%i$htDO).+ebLi!t(Oto6ayO).4e%ect O@<O bro(!er(O-ercuryO).*a$e(O&ind a &%i$htDO).(eb%i!t(OtodayO).!e%ect O@<O 2<.2 Te5t !trin$!D +hen (e enter a va%ue a! a te5t !trin$, (e -u!t add 7uotation -ark! be&ore and a&ter the !trin$. 8or e5a-*%e, in the above !e$-ent o& !cri*t, the na-e! o& the +eb !ite, +eb *a$e, and edit bo5 are a%% te5t !trin$! !urrounded by 7uotation -ark!. Note that the va%ue @< i! a%!o !urrounded by 7uotation -ark!, becau!e it i! a te5t !trin$ that re*re!ent! a nu-ber and not a nu-eric va%ue. In the &o%%o(in$ e5a-*%e, on%y the *ro*erty na-e (&ir!t ar$u-ent) i! a te5t !trin$ and i! in 7uotation -ark!. The !econd ar$u-ent (the va%ue o& the *ro*erty) i! a variab%e and there&ore doe! not have 7uotation -ark!. The third ar$u-ent (!*eci&yin$ the ti-eout) i! a nu-eric va%ue, (hich a%!o doe! not need 7uotation -ark!. Bro(!er(OMercuryO).Pa$e(O8ind a 8%i$htDO).+aitPro*erty(Oite-! countO, Tota%UIte-!, 2000) 2<.@ 3ariab%e!D +e can !*eci&y variab%e! to !tore !trin$!, inte$er!, array! and ob#ect!. /!in$ variab%e! he%*! to -ake our !cri*t -ore readab%e and &%e5ib%e 2<.B Parenthe!e!D To achieve the de!ired re!u%t and to avoid error!, it i! i-*ortant that (e u!e *arenthe!e! () correct%y in our !tate-ent!. 2<.= IndentationD +e can indent or outdent our !cri*t to re&%ect the %o$ica% !tructure and ne!tin$ o& the !tate-ent!. 2<.> 1o--ent!D +e can add co--ent! to our !tate-ent! u!in$ an a*o!tro*he (K), either at the be$innin$ o& a !e*arate %ine, or at the end o& a !tate-ent. It i! reco--ended that (e add co--ent! (herever *o!!ib%e, to -ake our !cri*t! ea!ier to under!tand and -aintain.

72

2<. 4*ace!D +e can add e5tra b%ank !*ace! to our !cri*t to i-*rove c%arity. The!e !*ace! are i$nored by 3B4cri*t.

#*)

rrors

+e have t(o ty*e! ,rror! in 3B 4cri*tE they are 3B4cri*t 'un:ti-e ,rror! and 3B4cri*t 4ynta5 ,rror!

#*7# VB%cri't /un-time

rrors

3B4cri*t run:ti-e error! are error! that re!u%t (hen our 3B4cri*t !cri*t atte-*t! to *er&or- an action that the !y!te- cannot e5ecute. 3B4cri*t run:ti-e error! occur (hi%e our !cri*t i! bein$ e5ecutedE (hen variab%e e5*re!!ion! are bein$ eva%uated, and -e-ory i! bein$ dyna-ic a%%ocated. #*7) VB%cri't %ynta& rrors

3B4cri*t !ynta5 error! are error! that re!u%t (hen the !tructure o& one o& our 3B4cri*t !tate-ent! vio%ate! one or -ore o& the $ra--atica% ru%e! o& the 3B4cri*t !cri*tin$ %an$ua$e. 3B4cri*t !ynta5 error! occur durin$ the *ro$ra- co-*i%ation !ta$e, be&ore the *ro$ra- ha! be$un to be e5ecuted.

3i!e %ystem 9'erations


3i!e %ystem 9,:ect Mode!$ The 8i%e 4y!te- "b#ect (84") -ode% *rovide! an ob#ect:ba!ed too% &or (orkin$ (ith &o%der! and &i%e!. It a%%o(! u! to u!e the &a-i%iar ob#ect. -ethod !ynta5 (ith a rich !et o& *ro*ertie!, -ethod!, and event! to *roce!! &o%der! and &i%e!. +e can a%!o e-*%oy the traditiona% 3i!ua% Ba!ic !tate-ent! and co--and!. The 84" -ode% $ive! our a**%ication the abi%ity to create, a%ter, -ove, and de%ete &o%der!, or to deter-ine i& and (here *articu%ar &o%der! e5i!t. It a%!o enab%e! u! to $et

73

in&or-ation about &o%der!, !uch a! their na-e! and the date they (ere created or %a!t -odi&ied. The 84" -ode% -ake! *roce!!in$ &i%e! -uch ea!ier a! (e%%. +hen *roce!!in$ &i%e!, our *ri-ary $oa% i! to !tore data in an e&&icient, ea!y:to:acce!! &or-at. +e need to be ab%e to create &i%e!, in!ert and chan$e the data, and out*ut (read) the data. 0%thou$h (e can !tore data in a databa!e, doin$ !o add! a !i$ni&icant a-ount o& overhead to our a**%ication. +e -ay not (ant to have !uch overhead, or our data acce!! re7uire-ent! -ay not ca%% &or the e5tra &unctiona%ity a!!ociated (ith a &u%%: &eatured databa!e. In thi! ca!e, !torin$ our data in a te5t &i%e or binary &i%e i! the -o!t e&&icient !o%ution. The 84" -ode%, contained in the 4cri*tin$ ty*e %ibrary (4crrun.d%%), !u**ort! the creation and -ani*u%ation o& te5t &i%e! throu$h the Te5t4trea- ob#ectE ho(ever, the 84" -ode% doe! not !u**ort binary &i%e!. To -ani*u%ate binary &i%e!, u!e the 8i%e"*en 8unction (ith the Binary key(ord. &am'!es #) 2reate a 3o!der "*tion ,5*%icit 6i- ob#84", ob#8o%der, !tr6irectory !tr6irectory Q O6DP.creddyO 4et ob#84" Q 1reate"b#ect(O4cri*tin$.8i%e4y!te-"b#ectO) 4et ob#8o%der Q ob#84".1reate8o%der(!tr6irectory) )) +e!ete a 3o!der 4et o84" Q 1reate"b#ect(O4cri*tin$.8i%e4y!te-"b#ectO) o84".6e%ete8o%der(O,DP.creddyO) *) 2o'ying 3o!ders 4et o84"Qcreateob#ect(O4cri*tin$.8i%e!y!te-ob#ectO) o84".1o*y8o%der O,DP$crO, O1DP#vrO, True -) 2hec?ing weather the fo!der a(ai!a,!e or notH if not creating the fo!der "*tion ,5*%icit 6i- ob#84", ob#8o%der, !tr6irectory !tr6irectory Q O6DP.creddyO 4et ob#84" Q 1reate"b#ect(O4cri*tin$.8i%e4y!te-"b#ectO) I& ob#84".8o%der,5i!t!(!tr6irectory) Then 4et ob#8o%der Q ob#84"..et8o%der(!tr6irectory) -!$bo5 !tr6irectory I O a%ready created O e%!e 4et ob#8o%der Q ob#84".1reate8o%der(!tr6irectory) end i& .) /eturning a co!!ection of +is? +ri(es

77

4et o84" Q 1reate"b#ect(O4cri*tin$.8i%e4y!te-"b#ectO) 4et co%6rive! Q o84".6rive! 8or ,ach o6rive in co%6rive! M!$Bo5 O6rive %etterD O I o6rive.6riveLetter Ne5t 0) 4etting a(ai!a,!e s'ace on a +is? +ri(e 4et o84" Q 1reate"b#ect(O4cri*tin$.8i%e4y!te-"b#ectO) 4et o6rive Q o84"..et6rive(O1DO) M!$Bo5 O0vai%ab%e !*aceD O I o6rive.0vai%ab%e4*ace 1) 2reating a 3!at 3i!e 4et ob#84" Q 1reate"b#ect(O4cri*tin$.8i%e4y!te-"b#ectO) 4et ob#8i%e Q ob#84".1reateTe5t8i%e(O,DP.creddy.t5tO) A) 2hec?ing weather the 3i!e is a(ai!a,!e or notH if not creating the 3i!e !tr6irectoryQO,DPO !tr8i%eQO.creddy.t5tO 4et ob#84" Q 1reate"b#ect(O4cri*tin$.8i%e4y!te-"b#ectO) I& ob#84".8i%e,5i!t!(!tr6irectory I !tr8i%e) Then 4et ob#8o%der Q ob#84"..et8o%der(!tr6irectory) ,%!e 4et ob#8i%e Q ob#84".1reateTe5t8i%e(O,DP.creddy.t5tO) ,nd i& B) /eading +ata character ,y character from a 3!at 3i!e 4et ob#84" Q 1reate"b#ect(O4cri*tin$.8i%e4y!te-"b#ectO) 4et ob#8i%e Q ob#84"."*enTe5t8i%e(O,DP.creddy.t5tO, <) 6o /nti% ob#8i%e.0t,nd"&4trea!tr1haracter! Q ob#8i%e.'ead(<) -!$bo5 !tr1haracter! Loo* #E) /eading +ata !ine ,y !ine from a 3!at 3i!e 4et ob#84" Q 1reate"b#ect(O4cri*tin$.8i%e4y!te-"b#ectO) 4et ob#8i%e Q ob#84"."*enTe5t8i%e(O,DP.creddy.t5tO, <) 6o /nti% ob#8i%e.0t,nd"&4trea!tr1haracter! Q ob#8i%e.'ead%ine -!$bo5 !tr1haracter! Loo* ##) /eading data from a f!at fi!e and using in data dri(en testing 6i- &!o,-y&i%e

7+

4et &!oQcreateob#ect(O!cri*tin$.&i%e!y!te-ob#ectO) 4et -y&i%eQ &!o.o*ente5t&i%e (O8DP.creddy.t5tO,<) -y&i%e.!ki*%ine +hi%e -y&i%e.atendo&%ine [G True 5Q-y&i%e.read%ine !Q!*%it (5, O,O) 4y!te-/ti%.'un O1DPPro$ra- 8i%e!PMercury InteractivePQuickTe!t Pro&e!!iona%P!a-*%e!P&%i$htPa**P&%i$htBa.e5eO,OO,O1DPPro$ra- 8i%e!PMercury InteractivePQuickTe!t Pro&e!!iona%P!a-*%e!P&%i$htPa**PO,Oo*enO 6ia%o$(OLo$inO).0ctivate 6ia%o$(OLo$inO).+in,dit(O0$ent Na-eDO).4et !(0) 6ia%o$(OLo$inO).+in,dit(OPa!!(ordDO).4et4ecure !(<) 6ia%o$(OLo$inO).+inButton(O")O).1%ick +indo((O8%i$ht 'e!ervationO).1%o!e +end #)) "riting data to a te&t fi!e 6i- 4tu&&, -y84", +rite4tu&&, date4ta-* date4ta-* Q 6ate() 4tu&& Q OI a- Pre*arin$ thi! !cri*tD O Idate4ta-* 4et -y84" Q 1reate"b#ect(O4cri*tin$.8i%e4y!te-"b#ectO) 4et +rite4tu&& Q -y84"."*enTe5t8i%e(OeDP.creddy.t5tO, A, True) +rite4tu&&.+riteLine(4tu&&) +rite4tu&&.1%o!e 4,T +rite4tu&& Q N"THIN. 4,T -y84" Q N"THIN. #*) +e!ete a te&t fi!e 4et ob#84"Qcreateob#ect(O4cri*tin$.&i%e!y!te-ob#ectO) 4et t5t8i%e*ath Q ob#84"..et8i%e(O,DP$cr.t5tO) t5t8i%e*ath.6e%ete() #-) 2hec?ing weather the 3i!e is a(ai!a,!e or notH if a(ai!a,!e de!ete the 3i!e !tr6irectoryQO,DPO !tr8i%eQO$cr.t5tO 4et ob#84" Q 1reate"b#ect(O4cri*tin$.8i%e4y!te-"b#ectO) I& ob#84".8i%e,5i!t!(!tr6irectory I !tr8i%e) Then 4et ob#8i%e Q ob#84"..et&i%e(!tr6irectory I !tr8i%e) ob#8i%e.de%ete () ,nd i& #.) 2om'aring two te&t fi!es 6i- &<, &2 &<QOeDP.creddy<.t5tO &2QOeDP.creddy2.t5tO Pub%ic 8unction 1o-*are8i%e! (8i%ePath<, 8i%ePath2) 6i- 84, 8i%e<, 8i%e2 4et 84 Q 1reate"b#ect(O4cri*tin$.8i%e4y!te-"b#ectO)

+0

I& 84..et8i%e(8i%ePath<).4i9e [G 84..et8i%e(8i%ePath2).4i9e Then 1o-*are8i%e! Q True ,5it 8unction ,nd I& 4et 8i%e< Q 84..et8i%e(8i%ePath<)."*en0!Te5t4trea-(<, 0) 4et 8i%e2 Q 84..et8i%e(8i%ePath2)."*en0!Te5t4trea-(<, 0) 1o-*are8i%e! Q 8a%!e 6o +hi%e 8i%e<.0t,nd"&4trea- Q 8a%!e 4tr< Q 8i%e<.'ead 4tr2 Q 8i%e2.'ead 1o-*are8i%e! Q 4tr1o-*(4tr<, 4tr2, 0) I& 1o-*are8i%e! [G 0 Then 1o-*are8i%e! Q True ,5it 6o ,nd I& Loo* 8i%e<.1%o!e() 8i%e2.1%o!e() ,nd 8unction 1a%% 1o-*are&i%e!(&<,&2) I& 1o-*are8i%e!(&<, &2) Q 8a%!e Then M!$Bo5 O8i%e! are identica%.O ,%!e M!$Bo5 O8i%e! are di&&erent.O ,nd I& #0) 2ounting the num,er of times a word a''ears in a fi!e !8i%eNa-eQO,DP$cr.t5tO !4trin$QO$creddyO 1on!t 8"'U',06IN. Q < 6i- o8!o, oT5t8i%e, !'eadT5t, o'e$,5, oMatche! 4et o8!o Q 1reate"b#ect(O4cri*tin$.8i%e4y!te-"b#ectO) 4et oT5t8i%e Q o8!o."*enTe5t8i%e(!8i%eNa-e, 8"'U',06IN.) !'eadT5t Q oT5t8i%e.'ead0%% 4et o'e$,5 Q Ne( 'e$,5* o'e$,5.Pattern Q !4trin$ o'e$,5.I$nore1a!e Q bI$nore1a!e o'e$,5..%oba% Q True 4et oMatche! Q o'e$,5.,5ecute(!'eadT5t) Matche!8ound Q oMatche!.1ount 4et oT5t8i%e Q Nothin$ D 4et o8!o Q Nothin$ D 4et o'e$,5 Q Nothin$ -!$bo5 Matche!8ound #1) /ead a 2%V 3i!e 6sing +ata,ase TechniCues "n ,rror 'e!u-e Ne5t 1on!t ad"*en4tatic Q @ 1on!t adLock"*ti-i!tic Q @ 1on!t ad1-dTe5t Q IH000< 4et ob#1onnection Q 1reate"b#ect(O06"6B.1onnectionO)

+1

4et ob#'ecord4et Q 1reate"b#ect(O06"6B.'ecord!etO) !trPathtoTe5t8i%e Q O1DP6ataba!e!PO ob#1onnection."*en OProviderQMicro!o&t.2et."L,6B.B.0EO I U O6ata 4ourceQO I !trPathtoTe5t8i%e I OEO I U O,5tended Pro*ertie!QOOte5tEH6'QF,4E8MTQ6e%i-itedOOO ob#'ecord!et."*en O4,L,1T V 8'"M PhoneLi!t.c!vO, U ob#1onnection, ad"*en4tatic, adLock"*ti-i!tic, ad1-dTe5t 6o /nti% ob#'ecord!et.,"8 +!cri*t.,cho ONa-eD O I ob#'ecord!et.8ie%d!.Ite-(ONa-eO) +!cri*t.,cho O6e*art-entD O I U ob#'ecord!et.8ie%d!.Ite-(O6e*art-entO) +!cri*t.,cho O,5ten!ionD O I ob#'ecord!et.8ie%d!.Ite-(O,5ten!ionO) ob#'ecord!et.MoveNe5t Loo* #A) /ead a Te&t 3i!e into an Array 1on!t 8or'eadin$ Q < 4et ob#84" Q 1reate"b#ect(O4cri*tin$.8i%e4y!te-"b#ectO) 4et ob#Te5t8i%e Q ob#84"."*enTe5t8i%e U (OeDP$creddy.t5tO, 8or'eadin$) 6o /nti% ob#Te5t8i%e.0t,nd"&4trea!trNe5tLine Q ob#Te5t8i%e.'ead%ine arr4erviceLi!t Q 4*%it(!trNe5tLine , O,O) +!cri*t.,cho O4erver na-eD O I arr4erviceLi!t(0) 8or i Q < to /bound(arr4erviceLi!t) +!cri*t.,cho O4erviceD O I arr4erviceLi!t(i) Ne5t Loo*

&ce! 3i!e 9'erations


#) 2reate an scri'tingM <) 2) @) B) =) >) &ce! fi!eH enter some data and sa(e the fi!e through VB 6i- ob#e5ce% 4et ob#,5ce% Q createob#ect(O,5ce%.a**%icationO) ob#e5ce%.3i!ib%e Q True ob#e5ce%.+orkbook!.add ob#e5ce%.1e%%!(<, <).3a%ue Q OTe!tin$O ob#e5ce%.0ctive+orkbook.4ave0!(O&DPe5ce%te!t.5%!O)

+2

) ob#e5ce%.Quit )) +ata +ri(en Testing through an &terna! &ce! %heet

<) 4et -y,5ce%Q1reateob#ect(O,5ce%.0**%icationO) 2) 4et -y8i%eQ-y,5ce%.(orkbook!.o*en (O1DP6ocu-ent! and 4ettin$!Pad-inPMy 6ocu-ent!P$creddy.5%!O) @) 4et -y4heetQ-y8i%e.(ork!heet!(O4heet<O) B) 'o(!U1ountQ-y4heet.u!edran$e.ro(!.count =) 8or iQ < to 'o(!U1ount >) 0$entQ-y4heet.ce%%!(i,O0O) ) *(dQ-y4heet.1e%%!(i,OBO) A) 4y!te-/ti%.'un O1DPPro$ra- 8i%e!PMercury InteractivePQuickTe!t Pro&e!!iona%P!a-*%e!P&%i$htPa**P&%i$htBa.e5eO,OO,O1DPPro$ra- 8i%e!PMercury InteractivePQuickTe!t Pro&e!!iona%P!a-*%e!P&%i$htPa**PO,Oo*enO C) 6ia%o$(OLo$inO).0ctivate <0) 6ia%o$(OLo$inO).+in,dit(O0$ent Na-eDO).4et 0$ent <<) 6ia%o$(OLo$inO).+in,dit(OPa!!(ordDO).4et4ecure *(d <2) 6ia%o$(OLo$inO).+in,dit(OPa!!(ordDO).Ty*e -ic'eturn <@) +indo((O8%i$ht 'e!ervationO).1%o!e <B) Ne5t *) 2om'are two e&ce! fi!es 4et ob#,5ce% Q 1reate"b#ect(O,5ce%.0**%icationO) ob#,5ce%.3i!ib%e Q True 4et ob#+orkbook<Q ob#,5ce%.+orkbook!."*en(O,DP$creddy<.5%!O) 4et ob#+orkbook2Q ob#,5ce%.+orkbook!."*en(O,DP$creddy2.5%!O) 4et ob#+ork!heet<Q ob#+orkbook<.+ork!heet!(<) 4et ob#+ork!heet2Q ob#+orkbook2.+ork!heet!(<) 8or ,ach ce%% In ob#+ork!heet<./!ed'an$e I& ce%%.3a%ue [G ob#+ork!heet2.'an$e(ce%%.0ddre!!).3a%ue Then -!$bo5 Ova%ue i! di&&erentO ,%!e -!$bo5 Ova%ue i! !a-eO ,nd I& Ne5t ob#+orkbook<.c%o!e ob#+orkbook2.c%o!e ob#,5ce%.7uit !et ob#,5ce%Qnothin$ -) +ata +ri(en Testing using +ata Ta,!e methods 6atatab%e.0dd4heet O$creddyO 6atatab%e.I-*ort4heet O1DP6ocu-ent! and 4ettin$!P0d-ini!tratorP6e!kto*P$creddy.5%!O,<,@ nQdatatab%e..et4heet (@)..et'o(1ount 8or iQ < to n 6atatab%e.4et1urrent'o((i)

+3

Invokea**%ication O1DPPro$ra- 8i%e!PHPPQuickTe!t Pro&e!!iona%P!a-*%e!P&%i$htPa**P&%i$htBa.e5eO 6ia%o$(OLo$inO).0ctivate 6ia%o$(OLo$inO).+in,dit(O0$ent Na-eDO).4et datatab%e(Oa$entO,@) 6ia%o$(OLo$inO).+in,dit(OPa!!(ordDO).4et datatab%e(O*(dO,@) 6ia%o$(OLo$inO).+inButton(O")O).1%ick +indo((O8%i$ht 'e!ervationO).1%o!e Ne5t &am'!e ))$ 6atatab%e.0dd4heet O$creddyO 6atatab%e.I-*ort4heet O1DP6ocu-ent! and 4ettin$!P0d-ini!tratorP6e!kto*P$creddy.5%!O,<,@ nQdatatab%e..et4heet (@)..et'o(1ount 8or iQ < to n 6atatab%e.4et1urrent'o((i) 3b+indo((O8or-<O).0ctivate 3b+indo((O8or-<O).3b,dit(Ova%<O).4et datatab%e(O3<O,@) 3b+indo((O8or-<O).3b,dit(Ova%2O).4et datatab%e(O32O,@) 3b+indo((O8or-<O).3bButton(O066O).1%ick ere!Q 6atatab%e.3a%ue (Ore!O,@) are!Q3b+indo((O8or-<O).3b,dit(Ore!O)..et'"Pro*erty (Ote5tO) I& ere!Qare! Then datatab%e(Ore!O,@)Q*a!! e%!e datatab%e(Ore!O,@)Q&ai% ,nd I& Ne5t .) 9'en an &ce! %'readsheet

4et ob#,5ce% Q 1reate"b#ect(O,5ce%.0**%icationO) 4et ob#+orkbook Q ob#,5ce%.+orkbook!."*en(O1DP4cri*t!P$creddy.5%!O) 0) /ead an &ce! %'readsheet

4et ob#,5ce% Q 1reate"b#ect(O,5ce%.0**%icationO) 4et ob#+orkbook Q ob#,5ce%.+orkbook!."*en U (O1DP4cri*t!PNe(Uu!er!.5%!O) int'o( Q 2 6o /nti% ob#,5ce%.1e%%!(int'o(,<).3a%ue Q OO +!cri*t.,cho O1ND O I ob#,5ce%.1e%%!(int'o(, <).3a%ue +!cri*t.,cho O!0M0ccountNa-eD O I ob#,5ce%.1e%%!(int'o(, 2).3a%ue +!cri*t.,cho O.ivenNa-eD O I ob#,5ce%.1e%%!(int'o(, @).3a%ue +!cri*t.,cho OLa!tNa-eD O I ob#,5ce%.1e%%!(int'o(, B).3a%ue int'o( Q int'o( L < Loo*

+'

ob#,5ce%.Quit 1) Add 3ormatted +ata to a %'readsheet 4et ob#,5ce% Q 1reate"b#ect(O,5ce%.0**%icationO) ob#,5ce%.3i!ib%e Q True ob#,5ce%.+orkbook!.0dd ob#,5ce%.1e%%!(<, <).3a%ue Q OTe!t va%ueO ob#,5ce%.1e%%!(<, <).8ont.Bo%d Q T'/, ob#,5ce%.1e%%!(<, <).8ont.4i9e Q 2B ob#,5ce%.1e%%!(<, <).8ont.1o%orInde5 Q @ A) %ort an &ce! %'readsheet on Three +ifferent 2o!umns

1on!t 5%0!cendin$ Q < 1on!t 5%6e!cendin$ Q 2 1on!t 5%Fe! Q < 4et ob#,5ce% Q 1reate"b#ect(O,5ce%.0**%icationO) ob#,5ce%.3i!ib%e Q True 4et ob#,5ce% Q 1reate"b#ect(O,5ce%.0**%icationO) ob#,5ce%.3i!ib%e Q True 4et ob#+orkbook Q U ob#,5ce%.+orkbook!."*en(O1DP4cri*t!P4ortUte!t.5%!O) 4et ob#+ork!heet Q ob#+orkbook.+ork!heet!(<) 4et ob#'an$e Q ob#+ork!heet./!ed'an$e 4et ob#'an$e2 Q ob#,5ce%.'an$e(O0<O) 4et ob#'an$e@ Q ob#,5ce%.'an$e(OB<O) 4et ob#'an$eB Q ob#,5ce%.'an$e(O1<O) ob#'an$e.4ort ob#'an$e2,5%0!cendin$,ob#'an$e@,,5%6e!cendin$, U ob#'an$eB,5%6e!cendin$,5%Fe!

+ata,ase 9'erations
A+9 @0ctive 6ata "b#ect!), thi! techno%o$y a%%o(! u!er! to acce!! data ea!i%y &ro-any e5i!tin$ databa!e! (!uch a! 0cce!! or Parado5) or &ro- "6B1 co-*%iant databa!e! %ike "rac%e or M4 4QL 4erver. /!in$ 06" i! 7uite !i-*%e and a%%o(! *ro$ra--er! to *rovide &%e5ib%e databa!e &ront end! to u!er! that are re%iab%e and inc%ude -any &eature!. 8o%%o(in$ are !o-e o& the key ob#ect! &ound in the 06" ob#ect -ode% and !o-e o& their key -ethod! and *ro*ertie!.

+0

2onnection 9,:ect Thi! ob#ect re*re!ent! an o*en connection to the data !ource. Thi! connection can be a %oca% connection (!ay 0**.Path) or can be acro!! a net(ork in a c%ient !erver a**%ication. 4o-e o& the -ethod! and *ro*ertie! o& thi! ob#ect are not avai%ab%e de*endin$ on the ty*e o& data !ource connected to. 2ommand 9,:ect 0 co--and ob#ect !*eci&ie! a !*eci&ic -ethod (e intend to e5ecute on or a$ain!t the data !ource acce!!ed by an o*en connection. /ecord%et 9,:ect The 'ecord4et ob#ect re*re!ent! a co-*%ete !et o& record! &ro- an e5ecuted co--and or &ro- an under%yin$ ba!e tab%e in the databa!e. 0 key thin$ to note i! that a 'ecord4et ob#ect re&erence! on%y one record at a ti-e a! the current record. &am'!es #) 4et Test +ata from a +ata,ase and use in +ata +ri(en Testing @through %cri'ting) <) 6i- con,r! 2) 4et conQcreateob#ect(O0dodb.connectionO) @) 4et r!Qcreateob#ect(O0dodb.record!etO) B) con.*roviderQ(O-icro!o&t.#et.o%edb.B.0O) =) con.o*en O1DP6ocu-ent! and 4ettin$!P0d-ini!tratorPMy 6ocu-ent!P.creddy.-dbO >) r!.o*en O4e%ect V 8ro- Lo$inO,con ) +hi%e r!.eo& [GTrue A) 4y!te-/ti%.'un O1DPPro$ra- 8i%e!PMercury InteractivePQuickTe!t Pro&e!!iona%P!a-*%e!P&%i$htPa**P&%i$htBa.e5eO C) 6ia%o$(OLo$inO).0ctivate <0) 6ia%o$(OLo$inO).+in,dit(O0$ent Na-eDO).4et r!.&ie%d! (O0$entO) <<) 6ia%o$(OLo$inO).+in,dit(OPa!!(ordDO).4et r!.&ie%d! (OPa!!(ordO) <2) 6ia%o$(OLo$inO).+inButton(O")O).1%ick <@) +indo((O8%i$ht 'e!ervationO).1%o!e <B) r!.-ovene5t <=) +end )) <) 2) @) B) =) >) ) &'orting +ata from a +ata,ase to an &ce! %heet

6i- con,r! 4et conQcreateob#ect(Oadodb.connectionO) 4et r!Qcreateob#ect(Oadodb.record!etO) con.*roviderQO-icro!o&t.#et.o%edb.B.0O con.o*enO1DP6ocu-ent! and 4ettin$!Pad-inPMy 6ocu-ent!P.creddy.-dbO r!.o*enO!e%ectV&ro- Lo$inO,con 4et e5Qcreateob#ect(O,5ce%.0**%icationO)

+2

A) 4et aQe5.(orkbook!.o*en(O1DP6ocu-ent! and 4ettin$!Pad-inPMy 6ocu-ent!P.creddy.5%!O) C) 4et bQa.(ork!heet!(O!heet<O) <0) iQ< <<) 6o +hi%e Not r!.,"8 <2) b.ce%%! (i,<).va%ueQr!.&ie%d!(Oa$entO) <@) b.ce%%!(i,2).va%ueQr!.&ie%d!(O*a!!(ordO) <B) r!.-ovene5t <=) iQiL< <>) Loo* < ) a.!ave <A) a.c%o!e *) &'orting +ata from a +ata,ase to a Te&t fi!e 6i- ob#1on,ob#'!,"b#8!o,-y8i%e,-y6ata,rc,r 4et ob#1onQcreateob#ect(O0dodb.connectionO) 4et ob#'!Qcreateob#ect(O0dodb.'ecord!etO) !et ob#8!oQcreateob#ect(O4cri*tin$.8i%e!y!te-ob#ectO) 4et -y8i%eQob#8!o."*enTe5t8i%e(O1DP6ocu-ent! and 4ettin$!P$crPMy 6ocu-ent!P$creddy.t5tO,A) ob#con.*roviderQ(OMicro!o&t.#et.o%edb.B.0O) ob#con.o*enO1DP6ocu-ent! and 4ettin$!P$crPMy 6ocu-ent!P$creddy.-dbO ob#r!.o*en O!e%ect V &ro- %o$inO,ob#1on rQ< 6o unti% ob#'!.,"8 aQob#'!.8ie%d! (O0$entO) bQob#'!.8ie%d! (OP(dO) -y8i%e.+rite%ine a IO,OI b rQrL< ob#'!.MoveNe5t Loo* -y8i%e.1%o!e ob#1on.1%o!e -) 2onnecting to a %QL %e(er data,ase 1on!t ad"*en4tatic Q @ 1on!t adLock"*ti-i!tic Q @ 4et ob#1onnection Q 1reate"b#ect(O06"6B.1onnectionO) 4et ob#'ecord4et Q 1reate"b#ect(O06"6B.'ecord!etO) ob#1onnection."*en U OProviderQ4QL"L,6BE6ata 4ourceQat%:!7%:0<EO I U OTru!tedU1onnectionQFe!EInitia% 1ata%o$QNorth(indEO I U O/!er I6Q&abrika-Pken-yerEPa!!(ordQ@B6,>tB.TEO ob#'ecord4et."*en O4,L,1T V 8'"M 1u!to-er!O, U ob#1onnection, ad"*en4tatic, adLock"*ti-i!tic ob#'ecord4et.Move8ir!t +!cri*t.,cho ob#'ecord4et.'ecord1ount

+3

.) 9'en a +ata,ase 6sing a +%8 1on!t ad"*en4tatic Q @ 1on!t adLock"*ti-i!tic Q @ 4et ob#1onnection Q 1reate"b#ect(O06"6B.1onnectionO) 4et ob#'ecord4et Q 1reate"b#ect(O06"6B.'ecord!etO) ob#1onnection."*en U ONorth(indE&abrika-Pken-yerE@B$h&nIT#O ob#'ecord4et."*en O4,L,1T V 8'"M 1u!to-er!O, U ob#1onnection, ad"*en4tatic, adLock"*ti-i!tic ob#'ecord4et.Move8ir!t +!cri*t.,cho ob#'ecord4et.'ecord1ount 0) 9'en Two /ecord sets 1on!t ad"*en4tatic Q @ 1on!t adLock"*ti-i!tic Q @ 4et ob#1onnection Q 1reate"b#ect(O06"6B.1onnectionO) 4et ob#'ecord4et Q 1reate"b#ect(O06"6B.'ecord!etO) 4et ob#'ecord4et2 Q 1reate"b#ect(O06"6B.'ecord!etO) ob#1onnection."*en U OProviderQ Micro!o&t.2et."L,6B.B.0E O I U O6ata 4ourceQinventory.-dbO ob#'ecord4et."*en O4,L,1T V 8'"M .enera%Pro*ertie! +here 1o-*uterNa-e Q K1o-*uter<KO, U ob#1onnection, ad"*en4tatic, adLock"*ti-i!tic ob#'ecord4et.Move8ir!t ob#'ecord4et2."*en O4,L,1T V 8'"M 4tora$e +here 1o-*uterNa-e Q K1o-*uter<KO, U ob#1onnection, ad"*en4tatic, adLock"*ti-i!tic ob#'ecord4et2.Move8ir!t 6o /nti% ob#'ecord!et.,"8 +!cri*t.,cho ob#'ecord!et.8ie%d!.Ite-(O1o-*uterNa-eO) +!cri*t.,cho ob#'ecord!et.8ie%d!.Ite-(O"4Na-eO) ob#'ecord4et.MoveNe5t Loo* 6o /nti% ob#'ecord!et2.,"8 +!cri*t.,cho ob#'ecord!et2.8ie%d!.Ite-(O6riveNa-eO), U

+7

ob#'ecord!et2.8ie%d!.Ite-(O6rive6e!cri*tionO) ob#'ecord4et2.MoveNe5t Loo* ob#'ecord4et.1%o!e ob#'ecord4et2.1%o!e ob#1onnection.1%o!e 1) %earching a +ata,ase 6sing %tring 2riteria 1on!t ad"*en4tatic Q @ 1on!t adLock"*ti-i!tic Q @ 4et ob#1onnection Q 1reate"b#ect(O06"6B.1onnectionO) 4et ob#'ecord4et Q 1reate"b#ect(O06"6B.'ecord!etO) ob#1onnection."*en U OProvider Q Micro!o&t.2et."L,6B.B.0E O I U O6ata 4ource Q event%o$!.-dbO ob#'ecord4et."*en O4,L,1T V 8'"M ,ventTab%e O I U O+H,', Ty*e Q K,rrorKO, ob#1onnection, ad"*en4tatic, U adLock"*ti-i!tic ob#'ecord4et.Move8ir!t +!cri*t.,cho ONu-ber o& record!D O I ob#'ecord!et.'ecord1ount ob#'ecord4et.1%o!e ob#1onnection.1%o!e A) Insert +ata into a data,ase ta,!e using +ata,ase 2ommand 9,:ect 6i- ob#1on,ob#1o4et ob#1onQ1reateob#ect(O06"6B.connectionO) ob#1on.o*enOProviderQMicro!o&t.2et."L,6B.B.0E6ata 4ourceQ1DP$creddy.-dbEO 4et ob#1o-Q1reateob#ect(O06"6B.1o--andO) ob#1o-.0ctive1onnectionQob#1on ob#1o-.1o--andTe5tQOin!ert into ,-* va%ue!(K. 1 'eddyK,AA2@@,@0000)O ob#1o-.,5ecute ob#1on.1%o!e 4et ob#1o-QNothin$ 4et ob#1onQNothin$ B) Insert mu!ti'!e sets of +ata @using using +ata,ase 2ommand 9,:ect &ce! sheet) into a data,ase ta,!e

6i- ob#1on,ob#1o-,!tr,-*Na-e,int,-*No,int,-*4a%,int'o(count,i

++

4et ob#1onQ1reateob#ect(O06"6B.connectionO) ob#1on.o*enOProviderQMicro!o&t.2et."L,6B.B.0E6ata 4ourceQ1DP$creddy.-dbEO 4et ob#1o-Q1reateob#ect(O06"6B.1o--andO) ob#1o-.0ctive1onnectionQob#1on 6atatab%e.0dd4heet(Oin*utO) 6atatab%e.I-*ort4heet O1DP$creddy.5%!O,<,Oin*utO int'o(countQ6atatab%e..et4heet(Oin*utO)..et'o(1ount M!$bo5 int'o(count 8or iQ< to int'o(count !te* < 6ataTab%e.4et1urrent'o((i) !tr,-*Na-eQ 6ataTab%e.3a%ue(<,Oin*utO) int,-*NoQ 6ataTab%e.3a%ue(2,Oin*utO) int,-*4a%Q 6ataTab%e.3a%ue(@,Oin*utO) ob#1o-.1o--andTe5tQOin!ert into ,-* va%ue!( KOI!tr,-*Na-eIO K,OIint,-*NoIO,OIint,-*4a%IO)O ob#1o-.,5ecute Ne5t ob#1on.1%o!e 4et ob#1o-QNothin$ 4et ob#1onQNothin$

9,:ect Identification 2onfiguration


9(er(iew$ .enera%%y &or every ob#ect 20:2= *ro*ertie! in&or-ation avai%ab%e, 7t* reco$ni9e! ob#ect u!in$ 2 0r @ i-*ortant *ro*ertie!. Qt* ha! de&au%t ob#ect identi&ication con&i$uration &or every environ-ent, i& (e &ee% that con&i$uration i! not !u&&icient &or reco$ni9in$ ob#ect! in our a**%ication, (e can

100

con&i$ure !o-e -ore 9,:ect Identification Ty'es a) <) 2) b) <) 2) c) 8orma! identification Mandatory *ro*ertie! 0!!i!tive *ro*ertie! %mart identification ba!e &i%ter *ro*ertie! o*tiona% &i%ter *ro*ertie! 9rdina! identifier

<) 2) @)

%ocation inde5 creation ti-e(on%y &or (eb)

QTP !earns information in the fo!!owing in case of norma! identification$ 8ir!t o& a%% the 7t* %earn! a%% the -andatory *ro*ertie! at a ti-e and think! (hether the!e *ro*ertie! !u&&icient to identi&y the ob#ect uni7ue%y. i& it &ee%! !u&&icient then it !to*! %earnin$ other(i!e, It %earn! &ir!t a!!i!tive *ro*erty and once a$ain !to*! and think!, %ike thi! 7t* %earn! one by one. 0t the end o& a!!i!tive *ro*ertie! %i!t a%!o i& it &ee%! not !ati!&ied and it &ina%%y $oe! to "rdina% Identi&ier. QTP !earns information in the fo!!owing in case of %mart Identification$ 4-art identi&ication i! an o*tiona% &eature, i& (e &ee% nor-a% identi&ication i! not !u&&icient &or any ob#ect, and then (e con&i$ure 4-art Identi&ication &or that ob#ect, in order to avoid "rdina% Identi&ier. 0&ter nor-a% identi&ication i& 7t* &ee%! not !ati!&ied then it $oe! to !-art identi&ication. in !-art identi&ication 2 ty*e! o& *ro*ertie! avai%ab%e, &ir!t 7t* %earn! a%% ba!e &i%ter *ro*ertie! at a ti-e and think! (hether the!e *ro*ertie! are !u&&icient &or identi&yin$ the ob#ect uni7ue%y. I& it &ee%! !u&&icient, then it !to*! %earnin$ other(i!e it $oe! "*tiona% 8i%ter Pro*ertie! and %earn! one by one. 4ti%% it &ee%! not !ati!&ied &ina%%y it $oe! to "rdina% Identi&ier. 9rdina! identifiers$ There are @ ty*e! o& ordina% identi&ier! avai%ab%e

<) LocationD i! ba!ed on ob#ect %ocation in the 0/T ,%ocation !tart! &ro- 9ero.

101

2) inde5D it i! ba!ed on !e7uence o& the *ro$ra-!, inde5 !tart! &ro- 9ero

@) 1reation ti-eD it i! ba!ed on %oadin$ ti-e o& the (eb ob#ect!. 7t* $enerate! 0,<,2 %ike nu-ber!. Too! %ettings 4!o,a!i5ation$ 0! QTP i! a I:tier(4tand:a%one) a**%ication,-akin$ Too% !ettin$! $%oba%%y i! not *o!!ib%e. 8or -akin$ too% !ettin$! $%oba%, QTP i! *rovidin$ a !*ecia% &eature ca%%ed O.enerate 4cri*tO. %T P%$ <) 4ettin$! avai%ab%e in @ area!. a) 8i%e:G4ettin$! b) Too%!:G"*tion! c) Too%!:G"b#ect Identi&ication 2) Per&or- re7uired !ettin$! and $enerate 4cri*t! @) 4hare 4cri*t &i%e! to tea- -e-ber! and a!k the- to e5ecute tho!e !cri*t!. N"T,D 0&ter e5ecutin$ the!e !cri*t! a%% tea- -e-ber! can $et !a-e !ettin$!.

/egu!ar
"hat is /egu!ar &'ressionM

&'ressions in QTP

It i! a (ay o& re*re!entin$ data u!in$ !y-bo%!. They are o&ten u!ed (ithin -atchin$, !earchin$ or re*%acin$ a%$orith-!. /egu!ar &'ressions in QTP$

102

'e$u%ar e5*re!!ion! can be u!ed in QTP &or identi&yin$ ob#ect! and te5t !trin$! (ith varyin$ va%ue!. "here we use$ o 6e&inin$ the *ro*erty va%ue! o& an ob#ect in 6e!cri*tive *ro$ra--in$ &or hand%in$ dyna-ic ob#ect! o 8or *ara-eteri9in$ a !te* o creatin$ check*oint! (ith varyin$ va%ue! 6sing /egu!ar &'ressions in QTP$

+e can de&ine a re$u%ar e5*re!!ion &or a con!tant va%ue, a 6ata Tab%e *ara-eter va%ue, an ,nviron-ent *ara-eter va%ue, or a *ro*erty va%ue in 6e!cri*tive *ro$ra--in$. +e can de&ine a re$u%ar e5*re!!ion in !tandard check*oint to veri&y the *ro*erty va%ue! o& an ob#ectE (e can !et the e5*ected va%ue o& an ob#ectK! *ro*erty a! a re$u%ar e5*re!!ion !o that an ob#ect (ith a varyin$ va%ue can be veri&ied. +e can de&ine the te5t !trin$ a! a re$u%ar e5*re!!ion, (hen creatin$ a te5t check*oint to check that a varyin$ te5t !trin$ i! di!*%ayed on our a**%ication, 8or NML check*oint! (e can !et attribute or e%e-ent va%ue! a! re$u%ar e5*re!!ion!. "ays of /egu!ar &'ressions$

a) Bac?s!ash 2haracter$ 0 back!%a!h (P) can !erve t(o *ur*o!e!. It can be u!ed in con#unction (ith a !*ecia% character to indicate that the ne5t character be treated a! a %itera% character. 0%ternative%y, i& the back!%a!h (P) i! u!ed in con#unction (ith !o-e character! that (ou%d other(i!e be treated a! %itera% character!, !uch a! the %etter! n, t, (, or d, the co-bination indicate! a !*ecia% character. ,) Matching Any %ing!e 2haracter$ 0 *eriod (.) in!truct! QTP to !earch &or any !in$%e character (e5ce*t &or Pn). ,5D (e%co-e. Matche! (e%co-e!, (e%co-ed, or (e%co-e &o%%o(ed by a !*ace or any other !in$%e character. c) Matching Any %ing!e 2haracter in a List$ 47uare bracket! in!truct QTP to !earch &or any !in$%e character (ithin a %i!t o& character!. ,5D To !earch &or the date <A> , <A>A, or <A>C, enterD

103

<A>` ACa d) Matching Any %ing!e 2haracter 8ot in a List$

+hen a caret (Z) i! the &ir!t character in!ide !7uare bracket!, it in!truct! QTP to -atch any character in the %i!t e5ce*t &or the one! !*eci&ied in the !trin$. ,5a-*%eD `Zaba Matche! any character e5ce*t a or b. e) Matching Any %ing!e 2haracter within a /ange$

To -atch a !in$%e character (ithin a ran$e, (e can u!e !7uare bracket! (` a) (ith the hy*hen (:) character. ,5a-*%eD 8or -atchin$ any year in the 20<0!, enterD 20<`0:Ca f) Matching Rero or More %'ecific 2haracters$

0n a!teri!k (V) in!truct! QTP to -atch 9ero or -ore occurrence! o& the *recedin$ character. 8or e5a-*%eD caVr Matche! car, caaaaaar, and cr g) Matching 9ne or More %'ecific 2haracters$

0 *%u! !i$n (L) in!truct! QTP to -atch one or -ore occurrence! o& the *recedin$ character. 8or e5a-*%eD caLr Matche! car and caaaaaar, but not cr.

h) Matching Rero or 9ne %'ecific 2haracter$

0 7ue!tion -ark (J) in!truct! QTP to -atch 9ero or one occurrence! o& the *recedin$ character. 8or e5a-*%eD

10'

caJr Matche! car and cr, but nothin$ e%!e. i) 4rou'ing /egu!ar &'ressions$

Parenthe!e! (()) in!truct QTP to treat the contained !e7uence a! a unit, #u!t a! in -athe-atic! and *ro$ra--in$ %an$ua$e!. /!in$ $rou*! i! e!*ecia%%y u!e&u% &or de%i-itin$ the ar$u-ent(!) to an a%ternation o*erator ( b ) or a re*etition o*erator ( V , L , J , c d ). :) Matching 9ne of %e(era! /egu!ar &'ressions$

0 vertica% %ine (b) in!truct! QTP to -atch one o& a choice o& e5*re!!ion!. ?) Matching the Beginning of a Line$

0 caret (Z) in!truct! QTP to -atch the e5*re!!ion on%y at the !tart o& a %ine, or a&ter a ne(%ine character. %) Matchin$ the ,nd o& a LineD 0 do%%ar !i$n (]) in!truct! QTP to -atch the e5*re!!ion on%y at the end o& a %ine, or be&ore a ne(%ine character. m) Matching Any A!'ha8umeric 2haracter Inc!uding the 6nderscore$

P( in!truct! QTP to -atch any a%*hanu-eric character and the under!core (0:e, a: 9, 0:C, U). n) Matching Any 8on-A!'ha8umeric 2haracter$

P+ in!truct! QTP to -atch any character other than a%*hanu-eric character! and under!core!. o) 2om,ining /egu!ar &'ression 9'erators$

+e can co-bine re$u%ar e5*re!!ion o*erator! in a !in$%e e5*re!!ion to achieve the e5act !earch criteria (e need. 8or e5a-*%e, !tart.V Matche! !tart, !tarted, !tartin$, !tarter, and !o &orth. (e can u!e a co-bination o& bracket! and an a!teri!k to %i-it the !earch to a co-bination o& non:nu-eric character!. 8or e5a-*%eD `a:90:eaV

100

To -atch any nu-ber bet(een 0 and <200, (e need to -atch nu-ber! (ith < di$it, 2 di$it!, @ di$it!, or B di$it! bet(een <000:<200. The re$u%ar e5*re!!ion be%o( -atche! any nu-ber bet(een 0 and <200. (`0:CaJ`0:CaJ`0:Cab<`0<a`0:Ca`0:Cab<200) /eg &' o,:ect

3B 4cri*t i! *rovidin$ 'e$,5* ob#ect &or de&inin$ 'e$u%ar e5*re!!ion!, It *rovide! !i-*%e !u**ort &or de&inin$ re$u%ar e5*re!!ion!. 'e$u%ar ,5*re!!ion "b#ect Pro*ertie! and Method!D

Pro'erties$

a) .%oba% Pro*erty

b) I$nore1a!e Pro*erty

c) Pattern Pro*erty

Methods$

a) ,5ecute Method

b) 'e*%ace Method

c) Te!t Method /egu!ar &'ressions &am'!es$

102

#) Match 3i!e 8ames in a +irectory against /egu!ar 4et ob#84 Q 1reate"b#ect(O4cri*tin$.8i%e4y!te-"b#ectO) 4et ob#4he%% Q 1reate"b#ect(O+4cri*t.4he%%O) !tr1urrent6irectory Q ob#4he%%.1urrent6irectory 4et ob#8o%der Q ob#84..et8o%der(!tr1urrent6irectory) 4et co%8i%e! Q ob#8o%der.8i%e! 4et ob#', Q Ne( 'e$,5* ob#',..%oba% Q True ob#',.I$nore1a!e Q 8a%!e ob#',.Pattern Q +4cri*t.0r$u-ent!(0) 8or ,ach ob#8i%e In co%8i%e! bMatch Q ob#',.Te!t(ob#8i%e.Na-e) I& bMatch Then +4cri*t.,cho ob#8i%e.Na-e ,nd I& Ne5t

&'ression

)) Match 2ontent in a 3i!e against a /egu!ar &'ression !tr8i%eNa-e Q O,DP$creddy.t5tO 4et ob#84 Q 1reate"b#ect(O4cri*tin$.8i%e4y!te-"b#ectO) 4et ob#T4 Q ob#84."*enTe5t8i%e(!tr8i%eNa-e) !tr8i%e1ontent! Q ob#T4.'ead0%% +4cri*t.,cho O4earchin$ +ithinD O +4cri*t.,cho !tr8i%e1ontent! ob#T4.1%o!e 4et ob#', Q Ne( 'e$,5* ob#',..%oba% Q True ob#',.I$nore1a!e Q 8a%!e ob#',.Pattern Q +4cri*t.0r$u-ent!(0) 4et co%Matche! Q ob#',.,5ecute(!tr8i%e1ontent!) +4cri*t.,cho vbNe(Line I O'e!u%tin$ Matche!DO 8or ,ach ob#Match In co%Matche! +4cri*t.,cho O0t *o!ition O I ob#Match.8ir!tInde5 I O -atched O I ob#Match.3a%ue ::::::::::::::::::::::::::::::::::::::::::::::::::

Batch Testing
,5ecutin$ a $rou* o& te!t!;!erie! o& te!t! at a ti-e i! kno(n a! Batch Te!tin$ or Batch ,5ecution. 8or *er&or-in$ Batch Te!tin$, QTP ha! *rovided a !e*arate Too% ca%%ed FTest Batch /unnerF.

103

%te's for Batch Testing$ <). 1reate Individua% Te!t! and 'un once. 2). "*en FTest ,atch /unnerF Too% and 8or- Batche!. @) Provide *er-i!!ion to FTest ,atch /unnerF to run te!t! B). 'un or ,5ecute Te!t Batche! &ro- Te!t Batch 'unner. =) 3ie( Te!t (i!e 'e!u%t in KTest /esu!t ViewerK 3orming a Test Batch$ Launch Te!t Batch 'unner. Navi$ationD 4tartG*ro$ra-G7uickte!t *ro&e!!iona%GToo%!GTe!t Batch 'unnerG8i%eGne(GbatchGaddGbro(!e *ath o& the te!t (%ike thi! add nu-ber o& te!t!)G!ave (ith MTB e5ten!ion (Modu%e te!t batche)Gc%o!e te!t batch runner. /unning or &ecuting a Test Batch

"*en Te!t Batch 'unner Too% Navi$ationD 8i%eGo*enGbro(!e *ath o& the te!t batchGbatchGrun NoteD Te!t Batch 'unner %aunche! QTP Too%, QTP run! Te!t! one by one. NoteD 0%%o(in$ other *roduct! to 'un Te!t!. Navi$ationD Too%!G"*tion!G'unGcheck a%%o( other -ercury *roduct!Ga**%y I "k &ecuting 'artia! Test Batch "*en Te!t Batch 'unner Go*en Te!t BatchG4e%ect or de!e%ect te!t!Grun te!t batch.

VB %cri't 9ther 9,:ects


#) +ictionary 9,:ect

107

6ictionary "b#ect that !tore! data key, ite- *air!. 0 6ictionary ob#ect i! the e7uiva%ent o& a P,'L a!!ociative array;Ha!h 3ariab%e. Ite-! can be any &or- o& data, and are !tored in the array. ,ach ite- i! a!!ociated (ith a uni7ue key. The key i! u!ed to retrieve an individua% ite- and i! u!ua%%y an inte$er or a !trin$, but can be anythin$ e5ce*t an array. 2reating a +ictionary 9,:ect$ 4et ob#6ictionary Q 1reate"b#ect(O4cri*tin$.6ictionaryO) +ictionary 9,:ects Methods$

Add Method 0dd! a key and ite- *air to a 6ictionary ob#ect &ists Method 'eturn! true i& a !*eci&ied key e5i!t! in the 6ictionary ob#ect, &a%!e i& it doe! not. Items Method 'eturn! an array containin$ a%% the ite-! in a 6ictionary ob#ect. Keys Method 'eturn! an array containin$ a%% e5i!tin$ key! in a 6ictionary ob#ect. /emo(e Method 'e-ove! a key, ite- *air &ro- a 6ictionary ob#ect. /emo(eA!! Method The 'e-ove0%% -ethod re-ove! a%% key, ite- *air! &ro- a 6ictionary ob#ect. &am'!e$ 6i- citie! 4et citie! Q 1reate"b#ect(O4cri*tin$.6ictionaryO) citie!.0dd OhO, OHyderabadO citie!.0dd ObO, OBan$a%oreO citie!.0dd OcO, O1hennaiO +ictionary 9,:ects Pro'erties$ 2ount Pro'erty 'eturn! the nu-ber o& ite-! in a co%%ection or 6ictionary ob#ect. 'ead:on%y.

10+

2om'areMode Pro'erty 4et! and return! the co-*ari!on -ode &or co-*arin$ !trin$ key! in a 6ictionary ob#ect. Key Pro'erty 4et! a key in a 6ictionary ob#ect. Item Pro'erty 4et! or return! an ite- &or a !*eci&ied key in a 6ictionary ob#ect. 8or co%%ection!, return! an ite- ba!ed on the !*eci&ied key. 'ead;(rite. &am'!es$ #) Add !ements toa+ictionary

4etob#6ictionaryQ1reate"b#ect(O4cri*tin$.6ictionaryO) ob#6ictionary.0ddOPrinter<O,OPrintin$O ob#6ictionary.0ddOPrinter2O,O"&&%ineO ob#6ictionary.0ddOPrinter@O,OPrintin$O

)) +e!ete A!!

!ements from +ictionary

4etob#6ictionaryQ1reate"b#ect(O4cri*tin$.6ictionaryO) ob#6ictionary.0ddOPrinter<O,OPrintin$O ob#6ictionary.0ddOPrinter2O,O"&&%ineO ob#6ictionary.0ddOPrinter@O,OPrintin$O co%)ey!Qob#6ictionary.)ey! +!cri*t.,choO8ir!trunDO 8or,ach!tr)eyinco%)ey! +!cri*t.,cho!tr)ey Ne5t ob#6ictionary.'e-ove0%% co%)ey!Qob#6ictionary.)ey! +!cri*t.,cho3b1rL&IO4econdrunDO 8or,ach!tr)eyinco%)ey! +!cri*t.,cho!tr)ey Ne5t *) +e!ete 9ne !ement from a +ictionary

110

4et ob#6ictionary Q 1reate"b#ect(O4cri*tin$.6ictionaryO)

ob#6ictionary.0dd OPrinter <O, OPrintin$O ob#6ictionary.0dd OPrinter 2O, O"&&%ineO ob#6ictionary.0dd OPrinter @O, OPrintin$O

co%)ey! Q ob#6ictionary.)ey!

+!cri*t.,cho O8ir!t runD O 8or ,ach !tr)ey in co%)ey! +!cri*t.,cho !tr)ey Ne5t

ob#6ictionary.'e-ove(OPrinter 2O) co%)ey! Q ob#6ictionary.)ey!

+!cri*t.,cho 3b1rL& I O4econd runD O 8or ,ach !tr)ey in co%)ey! +!cri*t.,cho !tr)ey Ne5t

-) List the 8um,er of Items in a +ictionary 4etob#6ictionaryQ1reate"b#ect(O4cri*tin$.6ictionaryO) ob#6ictionary.0ddOPrinter<O,OPrintin$O ob#6ictionary.0ddOPrinter2O,O"&&%ineO

111

ob#6ictionary.0ddOPrinter@O,OPrintin$O +!cri*t.,choob#6ictionary.1ount .) Verify the &istence of a +ictionary Key

4et ob#6ictionary Q 1reate"b#ect(O4cri*tin$.6ictionaryO) ob#6ictionary.0dd OPrinter <O, OPrintin$O ob#6ictionary.0dd OPrinter 2O, O"&&%ineO ob#6ictionary.0dd OPrinter @O, OPrintin$O I& ob#6ictionary.,5i!t!(OPrinter BO) Then +!cri*t.,cho OPrinter B i! in the 6ictionary.O ,%!e +!cri*t.,cho OPrinter B i! not in the 6ictionary.O ,nd I& )) /eg &' o,:ect

3B 4cri*t i! *rovidin$ 'e$,5* ob#ect &or de&inin$ 'e$u%ar e5*re!!ion!, It *rovide! !i-*%e !u**ort &or de&inin$ re$u%ar e5*re!!ion!. 'e$u%ar ,5*re!!ion "b#ect Pro*ertie! and Method!D Pro'erties$ a) .%oba% Pro*erty b) I$nore1a!e Pro*erty c) Pattern Pro*erty Methods$ a) ,5ecute Method b) 'e*%ace Method c) Te!t Method

112

<) Match 8i%e Na-e! in a 6irectory a$ain!t 'e$u%ar ,5*re!!ion

4et ob#84 Q 1reate"b#ect(O4cri*tin$.8i%e4y!te-"b#ectO) 4et ob#4he%% Q 1reate"b#ect(O+4cri*t.4he%%O) !tr1urrent6irectory Q ob#4he%%.1urrent6irectory

4et ob#8o%der Q ob#84..et8o%der(!tr1urrent6irectory) 4et co%8i%e! Q ob#8o%der.8i%e!

4et ob#', Q Ne( 'e$,5* ob#',..%oba% Q True

ob#',.I$nore1a!e Q 8a%!e ob#',.Pattern Q +4cri*t.0r$u-ent!(0)

8or ,ach ob#8i%e In co%8i%e! bMatch Q ob#',.Te!t(ob#8i%e.Na-e) I& bMatch Then +4cri*t.,cho ob#8i%e.Na-e ,nd I& Ne5t

2) Match 1ontent in a 8i%e a$ain!t a 'e$u%ar ,5*re!!ion !tr8i%eNa-e Q O,DP$creddy.t5tO 4et ob#84 Q 1reate"b#ect(O4cri*tin$.8i%e4y!te-"b#ectO)

113

4et ob#T4 Q ob#84."*enTe5t8i%e(!tr8i%eNa-e) !tr8i%e1ontent! Q ob#T4.'ead0%% +4cri*t.,cho O4earchin$ +ithinD O +4cri*t.,cho !tr8i%e1ontent! ob#T4.1%o!e

4et ob#', Q Ne( 'e$,5* ob#',..%oba% Q True

ob#',.I$nore1a!e Q 8a%!e ob#',.Pattern Q +4cri*t.0r$u-ent!(0)

4et co%Matche! Q ob#',.,5ecute(!tr8i%e1ontent!) +4cri*t.,cho vbNe(Line I O'e!u%tin$ Matche!DO 8or ,ach ob#Match In co%Matche! +4cri*t.,cho O0t *o!ition O I ob#Match.8ir!tInde5 I O -atched O I ob#Match.3a%ue Ne5t *) +ata,ase 2ommand 9,:ect #) Insert +ata into a data,ase ta,!e using +ata,ase 2ommand 9,:ect 6i- ob#1on,ob#1o4et ob#1onQ1reateob#ect(O06"6B.connectionO) ob#1on.o*enOProviderQMicro!o&t.2et."L,6B.B.0E6ata 4ourceQ1DP$creddy.-dbEO 4et ob#1o-Q1reateob#ect(O06"6B.1o--andO) ob#1o-.0ctive1onnectionQob#1on ob#1o-.1o--andTe5tQOin!ert into ,-* va%ue!(K. 1 'eddyK,AA2@@,@0000)O ob#1o-.,5ecute ob#1on.1%o!e 4et ob#1o-QNothin$ 4et ob#1onQNothin$

11'

)) Insert mu!ti'!e sets of +ata @using using +ata,ase 2ommand 9,:ect

&ce! sheet) into a data,ase ta,!e

6i- ob#1on,ob#1o-,!tr,-*Na-e,int,-*No,int,-*4a%,int'o(count,i 4et ob#1onQ1reateob#ect(O06"6B.connectionO) ob#1on.o*enOProviderQMicro!o&t.2et."L,6B.B.0E6ata 4ourceQ1DP$creddy.-dbEO 4et ob#1o-Q1reateob#ect(O06"6B.1o--andO) ob#1o-.0ctive1onnectionQob#1on 6atatab%e.0dd4heet(Oin*utO) 6atatab%e.I-*ort4heet O1DP$creddy.5%!O,<,Oin*utO int'o(countQ6atatab%e..et4heet(Oin*utO)..et'o(1ount M!$bo5 int'o(count 8or iQ< to int'o(count !te* < 6ataTab%e.4et1urrent'o((i) !tr,-*Na-eQ 6ataTab%e.3a%ue(<,Oin*utO) int,-*NoQ 6ataTab%e.3a%ue(2,Oin*utO) int,-*4a%Q 6ataTab%e.3a%ue(@,Oin*utO) ob#1o-.1o--andTe5tQOin!ert into ,-* va%ue!( KOI!tr,-*Na-eIO K,OIint,-*NoIO,OIint,-*4a%IO)O ob#1o-.,5ecute Ne5t ob#1on.1%o!e 4et ob#1o-QNothin$ 4et ob#1onQNothin$ -) "ord 9,:ect #) 2reate a word document and write some data di- -( !et -(Q1reate"b#ect(O+ord.0**%icationO) -(.6ocu-ent!.0dd -(.!e%ection.ty*ete5t Ohe%%oO -(.0ctive6ocu-ent.4ave0! OeDP$creddy.docO -(.7uit !et -(Qnothin$

)) 2reate %cri't to get the !ist of !in?s in 4oog!e and do s'e!! chec? 6i- d !et -(Q1reate"b#ect(O+ord.0**%icationO) !et dQ6e!cri*tion.1reate

110

d(O-icc%a!!O).va%ueQOLinkO !et aQBro(!er(O.oo$%eO).*a$e(O.oo$%eO).chi%dob#ect!(d) &or iQ0 to a.count:< -(.+ordBa!ic.&i%ene( !Qa(i).$et'"Pro*erty(Oinnerte5tO) -(.+ordBa!ic.in!ert ! i& -(.0ctive6ocu-ent.4*e%%in$error!.countG0 then 'e*orter.'e*ort,vent <,O4*e%%in$O,O!*e%%in$ error DOI! end i& -(.0ctive6ocu-ent.1%o!e(8a%!e) ne5t -(.7uit !et -(Qnothin$ *) %cri't to dis'!ay a!! the doc fi!es in a!! the dri(es in the system

6i- -( 4et -(Q1reate"b#ect(O+ord.0**%icationO) 4et &!Qcreateob#ect(O4cri*tin$.8i%e4y!te-"b#ectO) 4et dQ&!.6rive! -(.8i%e4earch.8i%eNa-eQOV.docO 8or each dr in d -!$bo5 dr -(.8i%e4earch.LookInQdr -(.8i%e4earch.4earch4ub8o%der!QTrue -(.8i%e4earch.,5ecute 8or each i in -(.8i%e4earch.8ound8i%e! *rint i 4et &Q&!..et8i%e(i) *rint &.Na-eIO OI&.4i9eIO OI&.6ate1reated *rint O:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::O Ne5t Ne5t -(.Quit .) I 9,:ect

112

#) 9'en Internet 6i- ie

&'!orer and na(igate to yahoo mai!

4et ieQ1reate"b#ect(OInternet,5*%orer.0**%icationO) ie.3i!ib%eQTrue ie.Navi$ate O(((.yahoo-ai%.co-O 5QBro(!er(O1reationTi-eDQ0O)..et'"Pro*erty(Otit%eO) -!$bo5 5

Automation 3ramewor?
Automation$ 0cce!!in$ one 4o&t(are "b#ect! &ro- another 4o&t(are i! ca%%ed 0uto-ation. (0/T i! one !;( and Te!tin$ Too% i! another !;(.)

113

Automation 3ramewor?$ It i! a !et o& $uide%ine!, a!!u-*tion! and *roce!! deve%o*ed by e5*ert! in order to *er&or- a ta!k(!) in an e&&ective, e&&icient and o*ti-i9ed (ay. "r 0 !y!te-atic a**roach to auto-ate !o&t(are Te!t *roce!! "hy Automation 3ramewor?$ In one *ro#ect te!t auto-ation (e u!e variou! &i%e!, (e *er&or- variou! ta!k!, in order to or$ani9e and -ana$e the- a%%, a !y!te-atic a**roach (0uto-ation 8ra-e(ork) re7uired. 3i!es to ,e used$ a) 8%at &i%e! (.t5t), b) ,5ce% &i%e! (.5%!) c) "b#ect re*o!itory &i%e! (.t!r) d) NML &i%e! (.5-%) e) Library &i%e! (.vb!;.7&%) &) Te!t 4cri*t! (.-t!) $) Te!t Batch 8i%e! (.-tb) h) 'ecovery !cenario &i%e! (.7r!) i) Te!t 'e!u%t &i%e (.NML) Tas?s to ,e 'erformed$ a) 0na%y9in$ the a**%ication b) 4e%ectin$ 0rea!;Te!t 1a!e! &or 0uto-ation c) P%annin$ (,&&ort e!ti-ation, 4chedu%e, +ork a%%ocation and 0uto-ation 8ra-e(ork i-*%e-entation) d) 1reatin$ .eneric and *ro#ect !*eci&ic &unction!. e) 1reatin$ re7uired 0uto-ation re!ource! (8unction!, "b#ect re*o!itory 8i%e!, ,nviron-ent variab%e &i%e!:::etc) &) 1reatin$ Te!t! (/!in$ "b#ect 'e*o!itory or 6e!cri*tive Pro$ra--in$) ,tc...

117

$) ,nhancin$ Te!t!(In!ertin$ 1heck*oint!, "ut*ut 3a%ue!, Tran!action *oint!, 8%o( 1ontro% 4tate-ent!, 4ynchroni9ation, Para-eteri9ation:::etc ) h) 6ebu$$in$ and runnin$ te!t!(Individua% te!t e5ecution, Te!t Batch e5ecution ::etc) i) 6e&inin$ and e5*ortin$ te!t re!u%t! #) 0na%y9in$ re!u%t! k) Te!t re*ortin$ %) 6e&ect 'e*ortin$ u!in$ co-*anie! de&ect -ana$e-ent !y!te-. -) Modi&yin$ te!t! n) Per&or-in$ re and re$re!!ion te!tin$ :::etc Ty'es 9f Automation 3ramewor?$ 0uto-ation 8ra-e(ork i! not a 7t* &eature, itH! a @rd *arty conce*t. 0nd thi! i! *ure%y %oca% conce*t.(&ra-e(ork -ay vary &ro- one co-*any to another) <. /ecord;P!ay,ac? or Linear 8ra-e(ork (<!t $eneration &ra-e(ork). In thi! 8ra-e(ork (e create te!t! u!in$ recordin$,%o( re!ource! -aintenance, 8orbatche! and e5ecutin$ te!t!. 6ra(back!D Modi&ication! and -aintenance are di&&icu%t,%e!! co--and on !cri*t!,%o( *er&or-ance :::etc 2. Modu!ar 3ramewor?7 In thi! 8ra-e(ork,reu!ab%e co-*onent! can be reco$ni9ed,&ir!t (e concentrate on creatin$ reu!ab%e co-*onent!, then creatin$ te!t! u!in$ tho!e co-*onent!. Ad(antages$ It reduce! te!t 0uto-ation ti-e Per&or-ance i! hi$h than recordin$ and *%ayback +raw,ac?s$ Le!! u!a$e o& key(ord!, no concentration on 6ata driven te!tin$ and %o( *er&or-ance than %ate!t 8ra-e(ork! %ike )ey(ord 6riven 8ra-e(ork. @. +ata +ri(en 3ramewor? In thi! 8ra-e(ork,(e concentrate -ore on 6ata 6riven te!tin$.+e reco$ni9e *o!itive and ne$ative !cenario!,then co%%ectin$ te!t data and *ara-eteri9in$. Ad(antages$

11+

+e can check re%iabi%ity o& the !y!te-,*o!itive and ne$ative te!tin$. +raw,ac?s$ Le!! concentration on co-*%e5 8unctiona%ity Te!tin$ and %o( key(ord! u!a$e. B. )ey(ord 6riven &ra-e(ork =. Hy,rid 3ramewor? In the above &ra-e(ork! )ey(ord 6riven &ra-e(ork i! very &a-ou! in the indu!try. It i! a -i5in$ o& -ore than one a**roach. In thi! a**roach,(e -i5 6ata driven and Modu%ar a**roache! "' 6ata 6riven and )ey(ord 6riven a**roache!:::etc Ad(antages$ 4co*e i! very hi$h a! (e -i5 di&&erent a**roache!,8%e5ib%e &or *er&or-in$ any ta!k!. +raw,ac?s$ "r$ani9in$ and -ana$in$ re!ource! are di&&icu%t,co-*%e5 architecture,%o( in *er&or-ance. 89T $ No( a day! Mi5 o& 6ata driven and )ey(ord driven a**roache! i! a &a-ou! Hybrid 8ra-e(ork in the indu!try. Keyword +ri(en 3ramewor? Keyword$ <. 0ny (ord u!ed a! the key to a code 2 0 re!erved (ord u!ed to identi&y a !*eci&ic co--and, &unction etc. (in our te!t auto-ation e5a-*%e key(ord! are D Keywords to ,e used in Test Automation$ a) Te!t "b#ect! (,ND Bro(!er,*a$e,(eb,dit,+inButton:::etc) b) 8unction! (Bui%t:In and /!er de&ined) c) Method! (,5D4et,4e%ect,0ctivate,Navi$ate:::etc) d) 4tate-ent! (,ND6i-,I&,8or:::etc) e) "*erator! (,ND L,;,V,and,or,not:::etc) Keyword +ri(en A''roach$ In thi! a**roach (e u!e key(ord! &or *re*arin$ te!t!. 8ir!t (e create te!t! and -ake the- a! &unction!, throu$h &ra-e(ork (e e5ecute the- and $enerate re!u%t!.

120

Key e!ements of Automation 3ramewor?$ <. 2. @. B. =. +e%% de&ined &o%der !tructure Initia%i9ation !cri*t 6river !cri*t in*ut data !*read!heet *roce!! $uide%ine! docu-ent

"hy fo!der structureM In order to create, !tore, or$ani9e and -ana$e &i%e! a (e%% de&ined &o%der !tructure re7uired. 8o%der !tructure i! a -andatory e%e-ent o& any &ra-e(ork, but &o%der na-e! -ay vary &ro- one &ra-e(ork to another and co-*any to another . 3o!der %tructure$ <. "b#ect 'e*o!itory 2. ,nviron-ent @. Library a) 1o-*any b) Pro#ect 4*eci&ic B. Te!t data =. Te!t %o$ >. 'ecovery !cenario! . Mi!ce%%aneou! 0nd <. Initia%i9ation !cri*t (.vb! &i%e) 2. 6river !cri*t (QTP 4cri*t &i%e) <) 9,:ect /e'ository$ In thi! &o%der (e !tore ob#ect re*o!itory &i%e!(.t!r), a%% tea-e-ber! can u!e thi! re*o!itorie!. 2) n(ironment$ In thi! &o%der (e !tore environ-ent variab%e! &i%e!(.5-%), a%% tea-e-ber! can u!e thi! variab%e!. @) 3unction Li,rary$thi! &o%der contain! t(o !ub &o%der! one i! &or !torin$ co--on &unction! o& our co-*any, another &o%der &or !torin$ our *ro#ect !*eci&ic &unction!(.vb!). B) Test +ata$ in thi! &o%der (e !tore te!t data re7uired &or data driven te!tin$, &or that (e u!e either .5%! &i%e! or .t5t &i%e! or .-db &i%e!.

121

=) Test Log$ In thi! &o%der (e !tore te!t re!u%t(e5ce% !heet). >) /eco(ery scenarios$ In thi! &o%der (e !tore 7t* recovery !cenario! &i%e!(.7r!). ) Misce!!aneous$ in thi! &o%der (e !tore the &i%e! other than above &i%e!(e5:*roce!! $uide%ine doc and -e!!a$e! a-on$ tea- -e-ber! and in!truction! by tea- %ead etc). And <) Initia!i5ation scri't (.vb! &i%e)D It %aunche! 7t* too% and ca%%! driver !cri*t, at end it c%o!e! 7t* too%. 2) +ri(er scri't (QTP 4cri*t &i%e)D It i! on%y the 7t* !cri*t, (e can a!!ociate a%% re!ource! to thi! !cri*t

122

You might also like