Sunteți pe pagina 1din 222

QTP Complete Reference QTP Guide

Step by Step QTP Guide for beginners as well as advanced learners. It explains QTP Tool fundamentals and features in detailed manner. It covers QTP tool window keyelements, QTP test process, ecording and unning tests,!n"ancing tests, #ebugging Tests, $naly%ing Test esults and eporting #efects. It describes QTP important features like Step Generator, Syc"roni%ation, Parameteri%ation, ecovery scenarios and &b'ect Identification (onfiguration.

An overview on Test Automation QTP Basic features Add-in Manager Key elements of QTP Test Pane QTP Commands QTP Test Process Recording Tests

Keyword

riven Met!odology

Test "#$ect Model

"#$ect Repository "#$ect %dentification Configuration QTP Test Met!ods #ata Table )et"ods escriptive Programming &n!ancing Tests %nserting C!ec'points %nserting "utput values Parameteri(ation )ync!roni(ation %nserting Transaction Points )tep Generator Adding Comments %nserting *low Control )tatements e#ugging Tests Running+&,ecuting Tests Analy(ing Test Results - Reporting

Reporting Actions

efects

*unctions &nvironment .aria#les Regular &,pressions .irtual "#$ect Configuration Batc!ing Testing Recovery )cenarios *ile )ystem "perations ata#ase connections Automation "#$ect Model ynamic /andling of "#$ect Repositories QTP Performance Tips
****************************************

QTP )cripting
QTP Tests in +, Script orientation provides a real-time approac" on Scripting. It explains .lat file scripts, !xcel Scripts, G/I Scripts, 0eb scripts, #atabase scripts and xml scripts wit" syntax and examples.

****************************************

*ile )ystem )cripts *lat *ile )cripts ata#ase )cripts-% ata#ase )cripts-%% &,cel )cripts G0% )cripts 1e# )cripts 1e# )cripts -%% QTP Real-time )cript &,amples 2etwor' Administration )ystem Administration Power point )cripts 1ord )cripts 3M4 )cripts

QTP )'ills &rror /andling in QTP 5555555555555555555555555555

.B )cript for QTP


It explains +, Script in QTP orientation, It covers all most all +, Script .undamentals and .eatures. It describes, +ariables, constants declarations, usage of operators, +, Script flow control statements, Procedures, (oding conventions, egular !xpressions, .ile system &perations, #atabase &perations etc.. ****************************************

)cripting 4anguages .s Programming 4anguages .B )cript *undamentals - *eatures Comments .B )cript .aria#les .B )cript ata Types

.B )cript "perators %nput+"utput "perations .B )cript Constants .B )cript Conditional )tatements

4oop t!roug! Code .B )cript )tatements .B )cript Procedures .B )cript &rrors .B )cript Built-%n *unctions 0ser efined *unctions

Regular &,pressions .B )cript Met!ods .B )cript "#$ects .B )cript Coding Conventions .B )cript Classes .B )cript Keywords .B )cript synta, rules and guidelines .B )cript General &,amples .B )cript General &,amples-%% .B )cript Glossary
******************************************

QTP *ramewor'
T"is section provides concepts on 1ow to implement $utomation .ramework. It explains about $utomation Infrastructure development, esources creation, #river script creation, Initiali%ation script creation etc. It describes data driven framework, keyword driven framework and 1ybrid framework in detailed manner. It also provides Test estimations, $pprovals, eporting, &rgani%ing and maintaining frameworks. **********************************************

QTP %nterview Questions QTP Model Resumes


T"is

section provides, esume preparation guidelines for fres"er as well as experienced. It provides some model QTP esumes for reference.

QTP 6o# 2ews


T"is section Provides QTP 2ob news weekly. Information can be collected by !mployers, (onsultants and employees. QTP Professionals can use t"is information and t"eir resumes directly to !mployer3s and consultants mail ids.

QTP Certification
T"is section provides 1P QTP (ertification guidelines and model Questions, It useful for QTP test professionals for preparing (ertification exam.

QTP Training Programs


T"is section provides information on variou QTP Training programs like QTP ,asics program for beginners, $dvanced program for working people, QTP .ramework, and +, Script for QTP t"at conducted by gcreddy.com

Manual Testing

ocuments

T"is section Provides link to our anot"er website gcreddy7net, t"ere you can get )anual Testing Information like, Software Testing Guide, )anual Testing Interview 4uestion and answers, Test management guidelines, Test planning, Test design and ot"er documents. *******************************************

Quality Center

T"is Section Provides Quality (enter .undamentals and features5 Site $dministration, (reating #omains, Pro'ects, and /sers. (reating e4uirements, #esigning )anual 6 $utomated Tests, !xecuting )anual and $utomated Tests and !ntering defects. Sending #efects directly from QTP esult window. **********************************************************

4oadRunner
T"is section provides 7oad unner tool .undamentals and .eatures5 +user generator, (ontroller, 7oad Generator, $nalysis and 7oad unner Interview Questions. *********************************************************

QTP "t!er Topics


T"is section provides QTP elated articles and ot"er information like, c"allenges in Test $utomation using QTP, )igrating Test scripts from old version to 8ew version, QTP trends, en"ancements, 8ew release information, ,rowser compatibility issues etc..

QTP )oftware

ownload 4in' ocuments

)Q4 )erver Guide )oftware Testing


QTP Basic Features
#ocuments on /nit Testing, 0eb Testing, Software Testing $rtifacts, Software Test Process !tc..
9 QTP was 7aunc"ed in :;;: <8ov=. ,y )ercury Interactive. 7ater taken over by 1P, in :;;>. 9 QTP is an "#$ect Based Testing Tool.

(Object based means; QTP Follows Test Object Model for Performing Testing operations. Based on either Test Objects or A tomation Objects or !tilit" Objects onl"# we can a tomate test operations$ (%oad& nner is a Protocol based Test Tool$ 9 QTP is for .unctional and egression Testing. (Basicall" QTP is a F nctional and &egression Test tool b t we can se it for little bit 'ompatibilit" Testing and Performance Testing$

It follows Keyword

riven $pproac".

((e"word )ri*en Approach means; (e"words# e+ample, 'ommands# f nctions# methods# statements etc.. are sed for creating Test scripts$ 9 It supports 0indows &perating !nvironment only. (QTP basicall" depends on !ser -nterface to a tomate test operations and it is not depends on ser*er side interactions# where as %oad& nner depends on ser*er side Operations# so .P de*eloped %oad& nner for /indows as well as !0-1 *ersions$ 9 It supports G/I based <Grap"ical user interface= and 0eb based $pplications $utomation, does not support (/I <(ommand user interface= $pplications. 9 It "as multilingual support. <It supports !nglis", ("inese, 2apanese, ?orean, etc languages wit" respect to license.= 9 It "as adapted )icrosoft +isual ,asic Scripting edition for programming and !xcel like spread s"eet for #ata driven testing. Tools support for QTP8 -----------------------------9 +, Script for Scripting <for implementing programming logic= 9 +, Script engine integrated in QTP, so apart from scripting features we can use .ile system, !xcel, word, $dodb etc. &b'ect models from QTP. 9 SQ7 <Structured 4uery language= engine integrated in QTP, so we can use SQ7 Statements in QTP to perform #atabase &perations 9 !xcel like spread s"eet integrated in QTP for performing #ata driven Testing 9 0e can install )S Script #ebugger wit" QTP for #ebugging Test scripts. 9 QTP uses @)7 format for Test results, !nvironment variables and for exporting ob'ect repositories. ------------------------------------------------------9 QTP can be integrated wit" ot"er Tools like 0in unner and Quality (enter. 9 QTP can be used for user interface </I= test case automation and some limited <8on /I= Test case automation like .ile system operations

and #ata base operations. 9 It was derived from $stra QuickTest <mot"er tool of QTP=.

9 It supports I! <Internet !xplorer= only for recording tests, for execution it supports ot"er browsers like )o%illa and $&7, opera !tc apart from I!. 9 9 QTP is a #esktop $pplication <I-TierAStand alone=. QTP developed in .8!T Tec"nology.

9 Since it is Stand-alone $pplication, It doesn3t "ave #atabase, It stores resources as files <Internal and !xternal=. 0e can3t s"are 4tp services from one mac"ine to anot"er, but we can s"are resources<!xB &b'ect epository files, .unction 7ibraries, !nvironment variable files, ecovery scenario files etc...= QTP !as two types of 4icense9 9 9 )eat or 8ode locked 7icense, Concurrent or float license.

9 0e "ave to use Seat license from fixed systemAmac"ine and (oncurrent 7icense, we can use from any system but one user at a time. If we want multiple concurrent licenses t"at we can purc"ase. 9 QTP "as /8I code support.

.ersion /istory of Quic'Test Professional 9 $stra QuickTest <)ot"er tool of QTP= C.; to D.; * QTP derived from $stra QuickTest and influenced by 0in unner. Quick Test Professional 9 D.E F 8ov :;;: 9 E.D F :;;G

9 H.; F :;;I 9 H.:, H.G F:;;D 9 J.;,J.C-:;;E

9 J.:- :;;> )ercury Interactive 9 J.D F:;;H 1.P 9 C;.;; F:;;J 2anuary 9 ::7;; <=;:;** <It is 7atest +ersion= &verview ---------------------------------------------------------------a= #isadvantages of )anual Testing C= 1uge $mount of 1uman esources as well as !nvironment <Test lab= := Time taking process G= 7ess $ccuracy I= Tideness

b= $dvantages of Test $utomation C= .ast := eliable G= $ccurated I= eusable D= epeatable E= (ompre"ensive

c= #raback of Test $utomation C= !xpensive := Tec"nical expertise G= C;;K $utomation not Posible

d= Types of Test Tool ,usiness cla Tec"nical cla -------------------------------------+endor Tools .unctional 6 egression Test tools &pensource PerformanceA7oadAstress Test tools

In-1ouse Test )anagement Tools #efect )anagement Tools Security /nit Test tools !tc... -----------------------------------------------------------------------I= ,asic .eatures of QTP ------------------------------------------------------------------------a= QTP Supporting !nvironments C= /I <G/IA0indows and 0eb= := &nly 0indows <(lien side and Server side= b= +ersion 1istory QTP derived from $stra QuickTest<C.;....D.;= D.E :;;: <8ov= E.D :;;G H.; :;;I H.: :;;D J.;, J.C :;;E J.: :;;> J.D :;;H--------1P C;.; :;;J <2an=

c= QTP 7icense<SeatA8ode 7ocked and (oncurentA.loat= c= QTP I#! C= QTP .eatures !xB ecording, ("eckpoints, &b'ect epository etc... := Integrated Tools <1P= !xB Password !ncoder, Test ,atc" unner, Test esult #letion Tool etc.. G= Integrated Tools <&t"ers= !xB Spread s"eet, +, Script !ngine, SQ7 !ngine, )S Script #ebugger d= ?ey elements of QTP C= Test Pane := $ctive Screen G= #ata Table I= #ebug +iewer D= Information Pane E= )issing esources >= QTP (ommands

--------------------------------------------------------------------------II= QTP Test Process --------------------------------------------------------------------------)anual Test Process <ST7(= +s QTP Test Process ----------------------------------------------------------------I= Planning I= Planning a= $naly%ing e4uirements a= $naly%ing t"e $/T b= Test Strategy Implentation b= selectingA(reating Test case for $utomation c= Test estimations c= Test !stimations 6 $pprovals d= team formation d= $utomation framework Implementation e= isk $nalysys e= QTP Tool Settings (onfiguration f= (onfiguration management g= #efining Test !nvironment "= Test Plan #ocumentation -------------------------------------------------------------------------------II= Test #esign II$= (reating t"e ,asic Tests a= /nderstanding 6 $naly%ing b= Generating Test Scenarios c= Test case #ocumentation e4s a= epository based Test creation C= ecording <7ocal epository= := ?eyword driven met"odology <S"ared epository= b= #escriptive Programming C= Static Programming := #escriptive Programming

II,= !n"ancing Tests a= $dding (omments b= Inserting ("eckpoints c= Inserting &utput values d= Inserting Transaction points e= Generating steps t"ru Step Generator f= Inserting .low (ontrol Statements g= Sync"roni%ation "= Parameteri%ation i= (alling .unctions A $ctions '= /sing egular expressions k= /sing !nvironment +ariables l= /sing $utomation &b'ects <using &b'ect )odels=

---------------------------------------------------------------------------------III= Test !xecution III$= #ebugging Tests <&ptional= ---------------------------------------------------------------------------------a= .orming Test ,atc"esAsuites a= Step by step execution b= Test !nvironment setup b= 0atc"ing +ariables c= Test !xecution c= 7ocating 6 Isolating !rrors d= $naly%ing Test esults d= #efect eporting e= #efect Tracking III ,= unning Tests f= e 6 egression Testing a= Single Test un g= Test status eporing b= ,atc" Testing "= Test 7ogs c= !xecuting Tests t"ru .ramework i= .inal egression d= Sc"eduled execution e= $naly%ing esults f= esult eporing g= #efect eporing "= egression Testing -----------------------------------------------------------------------------------------I+= Test (losure I+= Test (losure ----------------a= evaluating !xit (riteria a= Sending Test scripts 6 esources to (ustomer b= (ollecting all facts from Test $ctivities b= )aintaning Tests 6 esouce files c= sending Test #elivarables to (ustomer c= Improvement Suggessions d= Improvement Suggessions for Q$ Process -------------------------------------------------------------------------------------------III= (reating Tests A Test Scripts ----------------------------------------------------------------------------------------C= epository based Test #esign a= ecording <7ocal repository= b= ?eyword #riven met"odology <S"ared repository=

:= #escriptive Programming a= Static Programming

b= #ynamic programming

ecording Tests ---------------a= ecording Process b= ecording )odes i= 8ormal ecording ii= $nalog ecording iii= 7ow 7evel ecording c= unning Process &b'ect epositoryB -----------------a= &b'ect and Types of &b'ect i= un-time &b'ects ii= Test &b'ect )odel iii= /tility &b'ects iv= $utomation &b'ects

b= Types of &b'ect epository i= 7ocal epository ii= S"ared epository c= &perations on &b'ect epository

i= $dding &b'ects ii= enaming &b'ects iii= #eleting &b'ects iv= !xporting 7ocal &b'ects v= )erging epositories vi= $ssociating epositories to an $ction vii= +iew &ptions viii= !xporting &b'ects to @)7AImporting &b'ects from @)7 i@= #efining 8ew Test &b'ects @= Spying &b'ects

d= &b'ect Identification (onfiguration

i= 8ormal identification C= )andatory properties := $ssistive properties ii= Smart Identification <&ptional= C= ,ase .ilter properties := &ptional .ilter properties iii= &rdinal Identifier C= 7ocation := Index G= (reation Time <&nly for web $pplication= ?eyword driven met"odolyB ------------------------a= (reating S"ared &b'ect epositories b= $ssociating epositories to an $ction c= (reating tests manually i= T"ru !xpert +iew ii= ?eyword +iew iii= generate steps t"ru Step Generator

#escriptive programmingB -----------------------a= Static programming i= identifying /ni4ue Properties for &b'ects ii= (reating (onstants iii=(reating 7ibrary file for constants iv= associating 7ibrary files A loading 7ibrary files during run-time v= /sing (onstants, generating Tests b= #ynamic Programming i= (reating (ollection &b'ects ii= !ntering Properties Information into (ollection &b'ects iii= /sing (ollection &b'ects, generating tests c= 1andling #ynamic &b'ects using egular expressions

d= 1andling #uplicateASimilar &b'ects using Index property ------------------------------------------------------------------------------------------------------

Key &lements of QTP Tool 1indow


:> Test Pane8 It is programming interface of QTP, used for creating, editing, viewing and deleting test scripts. Test8 It is a set of statements or set of one or more actions. <It is a local concept= Action8 It is a set of Statements. <It is a local concept= )tatement8 $ minimal executable unit. Statements may "ave keywords. <?eyword suc" as function, met"od, statement etc=. It is a global concept.

Test pane !as = views7 !xpert view- Test in +, script format. ?ey word view- Test in Icon based G/I format.

2ote:8 1ere in test pane Test is same but views are different, if you perform anymodifications in one view t"ose automatically reflects in anot"er view. 2ote =8 Tec"nical users use expert view and business user use key word view. 2ote ?8 /ser can customi%e Test pane view options. 8avigationB Tools )enuL view optionsL we can use font si%e and colors etc. => Active )creen It "as an optional element of QTP, it takes snap s"ots of every statement t"at user performed action or operation on $/T. It can be used for understanding and editing t"e test easily. 2avigation8 +iew menuLactive screen <for launc"ing and closing=

Configuring Active )creen8 viewLoptionsLactive screen tabLincrease A#ecrease capture level, apply and okay. 8ote CB Generally novice testers use t"is feature but it occupies lot of memory space on QTP. ?> ata Ta#le

It "as an integrated spread s"eet <!xcel like=, used for #ata driven testing. 8avigationB +iew menuL#ata table <for launc"ing and closing=

#ata driven TestingB Testing t"e same task<S= or same operation wit" multiple sets of test data. It can be used in two ways. C. !nter test data directly into #ata Table and use. :. Importing data from external files <.lat files, excel s"eets, etc= and #ata bases <)S access, S4l Server, oracle, etc.= It "as two types of s"eets. C=. Global S"eet- for entire Test Aused for all actions in t"e Test. :=. $ction S"eets- for specific $ction only. #ata table available in : waysB C=. #esign time data table. <$ttac"ed wit" every test= :=. un time data table. <$vailable in result window= un time is a carbon copy of design time data table. QTP "as #ata table met"ods for performing operations on data table.

@> e#ug .iewer It is used for locating and rectifying or fixing errors. It can be used for debugging t"e tests by step-by-step execution. 0e use Step into, Step over and Step out commands for debugging. <debug commands= 8avigationB +iew menuLdebug viewer <for launc"ing and closing=

T"roug" #ebug viewer user can watc" variables and c"ange values of variables temporarily. A> Missing Resources It can be used for s"owing missing resources t"at attac"ed to current test suc" as < ecovery Scenarios, 7ibrary files etc=. 8avigationB +iew menu Lmissing resources <for launc"ing and closing= B> %nformation T"is pane s"ows syntax errors automatically during saving t"e test. 8avigationB view menuL information

C> QTP Commands QTP (ommands are available in G ways. C=. )enu options :=. Tool ,ar options G=. S"ort cut keys <for Some important operations only=

QTP Tool 1indow Menus

.ile menuB T"roug" file menu user can create, save tests, open existing tests, export tests in %ip format.

!dit )enuB It provides editing options and renaming, deleting and splitting actions. +iew menuB T"roug" t"is menu we can launc" and close, active screen, #ata Table, #ebug viewer, information, missing resources etc. Insert )enuB T"roug" t"is menu user can inserting c"eck points, out put values,sync"roni%ing points. In t"is menu step generator available, using t"is user can generate recordable and non-recordable scripts. T"roug" insert menu user can insert +, Script conditional and loop statements and transaction points <Start and !nd=. T"roug" insert menu user can create new actions, call existing actions and copy existing actions. $utomation )enuB T"is menu provides setting options ecord, un options and un

T"roug" t"is menu we can start normal recording, analog recording and 7ow level recording. T"roug" t"is menu we can stop recoding, running and also we run tests. esources )enuB T"is menu provides ob'ect repository and recovery scenarios options. T"roug" t"is menu we can create AmodifyAdelete ob'ects information and we can associate repositories. T"roug" t"is menu we can create, modify and delete recovery scenarios. #ebug )enuB T"is menu provides debug commands for step by step execution. T"roug" t"is menu we can insertAremoveAbreak points.

Tools )enuB T"is menu provides Tools settings option, view options and ob'ect identification configuration. T"roug" t"is menu we can set tool options as well as test pane view options. In t"is menu ob'ect spy option available, t"roug" t"is we can get ob'ectMs information.<Properties and values= In t"is menu +irtual ob'ect option available5 t"roug" t"is option we can create virtual ob'ects. 0indow )enuB T"is menu provides QTP tool window style settings. 1elp )enuB T"is menu provides QTP "elp as well as +, Script "elp. T"roug" t"is menu we can contact tec"nical support people and we can send feedback. T"roug" t"is menu we can c"eck for updates and download or install directly.

QTP Commands
QTP Commands are availa#le in ? ways7 C.)enu options :.Tool ,ar options G.S"ort cut keys <for Some important operations only= *ile menu8 T"roug" file menu user can create, save tests, open existing tests, export tests in %ip format.

Command New > Test New > Business Component New > Scripted Component New > Application Area Creates a new test.

Function

Creates a new business component. Creates a new scripted component. Creates a new application area.

New > Function Library Open > Test Open > Business/Scripted Component Open > Application Area Open > Function Library Close Close All Function Libraries

Creates a new function library. Opens an existing test. Opens an existing business or scripted component. Opens an existing application area. Opens an existing function library. Closes the active function library. Closes all open function libraries.

Quality Center Connection Opens the Quality Center Connection dialog box, enabling you to connect to a Quality Centerproject. Quality Center Version Control Provides a sub-menu of options for managing versions of Quic !est assets in Quality Center. !he sub-menu is available only when you are connected to versioncontrol enabledQuality Center project. "aves the active document. Opens the relevant "ave dialog box so you can save the open document. "aves a standalone copy of the current test together with its resource files. "aves all open documents. #a es read-only function libraries editable. Creates a $ip file of the active document.

Sa e Sa e As Sa e Test wit! "esources Sa e All #nable #ditin$ #%port Test to &ip File

'mport Test (rom &ip File %mports a document from a $ip file. Con ert to Scripted Component )rint )rint )re iew Converts a business component to a scripted component. Prints the active document. &isplays the 'eyword (iew as it will loo

when printed and enables you to modify the page setup. Settin$s Opens the "ettings dialog box, enabling you todefine settings for the open document. )*ot relevant for function libraries+ Opens the Process ,uidance #anagement dialog box, enabling you to manage the list of processes that are available in Quic !est. -ssociates the active function library with the open document. )-vailable only from function libraries+ .ists the recently viewed files. Closes the Quic !est session.

)rocess *uidance +ana$ement Associate Library ,-Function Library Name>, wit! ,-.ocument Name>, "ecent Files #%it

&dit Menu8 It provides editing options and renaming, deleting and splitting actions.

Command /ndo "edo Cut Copy )aste .elete Copy .ocumentation to Clipboard Action > Split Action

Function /everses the last command or deletes the last entry you typed. /everses the most recent operation of the 0ndo command. /emoves the selection from your document. Copies the selection from your document. Pastes the selection to your document. &eletes the selection from your document. Copies the content of the .ocumentation column of the 'eyword (iew, enabling you to paste it in an external application. "eparates an action into two sibling actions or into parent-child nested actions.

Action > "ename Action Action > .elete Action

Changes the name of an action. 1nables you to remove the selected call to the action, or delete the action and its calls from the active test.

Action > Action )roperties 1nables you to specify options, parameters, and associated object repositories for a stored action. Action > Action Call )roperties 1nables you to specify the number of run iterations according to the number of rows in the &ata !able, and to define the values of input parameters and the storage location of output parameters. Opens the Comment Properties dialog box for a comment step. -vailable only when the selected step is a comment. Opens the Object Properties dialog box for a selectedobject. -vailable only when the selected step contains a test object. Opens the relevant Chec point Properties dialog box for a selected object. -vailable only when the selected step is a chec point step. Opens the relevant Output (alue Properties dialog box for a selected object. -vailable only when the selected step is an output value step. &isplays the /eport Properties dialog box for a report step. -vailable only when the selected step is a"eporter2"eport# ent step. "earches for a specified string. "earches and replaces a specified string. #oves the cursor to a particular line in the test. Creates boo mar s in your script for easy navigation. Comments out the current row, or selected rows. /emoves the comment formatting from the current or selected rows.

Step )roperties > Comment )roperties Step )roperties > Ob0ect)roperties Step )roperties > C!ec1point )roperties Step )roperties > Output Value )roperties Step )roperties > "eport )roperties Find "eplace *o To Boo1mar1s Ad anced > Comment Bloc1 Ad anced > /ncomment Bloc1

Ad anced > 'ndent Ad anced > Outdent

%ndents the step according to the tab spacing defined inthe 1ditor Options dialog box. Outdents the step )reduces the indentation+ according to the tab spacing defined in the 1ditor Options dialog box. *avigates to the definition of the selected function. Completes the word when you type the beginning of a (2"cript method or object. &isplays the syntax of a method.

Ad anced > *o to Function .e(inition Ad anced > Complete 3ord Ad anced > Ar$ument 'n(o

Ad anced > Apply 43it!4 ,enerates 3it! statements for the action displayed to Script in the 1xpert (iew, and enables %ntelli"ense within 3it!statements. Ad anced > "emo e 43it!4 Statements Optional Step Converts any 3it! statements in the action displayed in the 1xpert (iew to regular )single-line+ (2"cript statements. %nserts an optional step )a step that is not re3uired to successfully complete a run session+.

.iew menu8 T"roug" t"is menu we can launc" and close, active screen, #ata Table, #ebug viewer, information, missing resources etc. %nsert Menu8 T"roug" t"is menu user can inserting c"eck points, out put values, sync"roni%ing points. In t"is menu step generator available, using t"is user can generate recordable and non-recordable scripts. T"roug" insert menu user can insert +, Script conditional and loop statements and transaction points <Start and !nd=. T"roug" insert menu user can create new actions, call existing actions and copy existing actions. Automation Menu8 T"is menu provides ecord,

un options and

un setting options

T"roug" t"is menu we can start normal recording, analog recording and 7ow levelrecording. T"roug" t"is menu we can stop recoding, running and also we run tests.

Command "ecord "un Stop "un Current Action "un (rom Step

Function "tarts a recording session. "tarts a run session from the beginning or from the line at which the session was paused. "tops the recording or run session. /uns only the active action. "tarts a run session from the selected step.

+aintenance "un +ode "tarts a run session during which the #aintenance /un #ode wi$ard opens for steps that failed because an object was not found in the application)if applicable+. /pdate "un +ode "tarts a run session to update test objectdescriptions and other options )if applicable+. "tarts recording in Analo$ "ecordin$ mode. "tarts recording in Low Le el "ecordin$ mode.

Analo$ "ecordin$ Low Le el "ecordin$

"ecord and "un Settin$s Opens the /ecord and /un "ettings dialog box, enabling you to define browser preferences for recording and running your test. )rocess *uidance List .ists the processes that are available for the current document type and for the currently loaded Quic !est add-ins, enabling you to open them. 1nables you to view results for a test run session.

"esults

Resources Menu8 T"is menu provides ob'ect repository and recovery scenarios options.

T"roug" t"is menu we can create AmodifyAdelete ob'ects information and we can associate repositories. T"roug" t"is menu we can create, modify and delete recovery scenarios.

Command Ob0ect "epository

Function Opens the Object /epository window, which displays a tree containing all objects in the current test or component. Opens the Object /epository #anager dialog box, enabling you to open and modify multiple sharedobject repositories. Opens the -ssociate /epositories dialog box, enabling you to manage the object repository associations for the test. Opens the #ap /epository Parameters dialog box, enabling you to map repository parameters, as needed. Opens the /ecovery "cenario #anager dialog box.

Ob0ect "epository +ana$er

Associate "epositories

+ap "epository )arameters

"eco ery Scenario +ana$er

Associated Function Libraries .ists the function libraries associated with the active document, enabling you to open them.
e#ug Menu8 T"is menu provides debug commands for step by step execution. T"roug" t"is menu we can insertAremoveAbreak points. Tools Menu8 T"is menu provides Tools settings option, view options and ob'ect identification configuration. T"roug" t"is menu we can set tool options as well as test pane view options. In t"is menu ob'ect spy option available, t"roug" t"is we can get ob'ectMs information.<Properties and values= In t"is menu +irtual ob'ect option available5 t"roug" t"is option we can create virtual ob'ects.

Command Options

Function Opens the Options dialog box, enabling you to modify global

testing options. View Options Opens the 1ditor Options dialog box, enabling you to customi$e how tests and function libraries are displayed in the 1xpert (iew and 4unction .ibrary windows. Chec s the syntax of the active document. Opens the Object %dentification dialog box, enabling you to specify how Quic !est identifies a particular test object. Opens the Object "py dialog box, enabling you to view the native properties and operations of any object in an open application, as well as the test object hierarchy, identification properties, and operations of the test object that Quic !est uses to represent that object. Opens the 5eb 1vent /ecording Configuration dialog box, enabling you to specify a recording configuration level. )/elevant for tests only+ Opens the &ata &river dialog box, which displays the default Constants list for the action. )/elevant for tests only+ /eplaces the previously recorded -ctive "creen with the selected -ctive "creen. )/elevant for tests only+ Opens the (irtual Object 5i$ard, enabling you to teach Quic !est to recogni$e an area of your application as a standard test object.

C!ec1 Synta% Ob0ect 'denti(ication Ob0ect Spy

3eb # ent "ecordin$ Con(i$uration .ata .ri er C!an$e Acti e Screen Virtual Ob0ects > New Virtual Ob0ect

Virtual Ob0ects > Virtual Opens the (irtual object #anager, enabling you to manage all Ob0ect +ana$er of the virtual object collections defined on your computer. Customi5e Opens the Customi$e dialog box, which enables you to customi$e toolbars and menus, and create new menus.

1indow Menu8 T"is menu provides QTP tool window style settings. /elp Menu8 T"is menu provides QTP "elp as well as +, Script "elp. T"roug" t"is menu we can contact tec"nical support people and we can send feedback. T"roug" t"is menu we can c"eck for updates and download or install directly.

QTP Test Process


:> Planning o o o o o o

C )tages of QTP Testing Process

$naly%ing t"e $/T $utomation Test Plan Generation $utomation .ramework Implementation GeneratingASelecting Test cases for $utomation (ollecting Test #ata QTP Tool Settings (onfiguration

=> Generating Tests o ecording o ?eyword driven met"odology o #escriptive Programming ?> &n!ancing Tests o o o o o o o o o o Inserting ("eckpoints Inserting &utput values $dding (omments Sync"roni%ation Parameteri%ation Inserting .low (ontrol Statements (alling /ser defined functions andAor eusable $ctions Generating Steps t"oug" Step Generator Inserting Transaction Points egular !xpressions e#ugging Tests

@> o o o o

#ebug (ommands 6 ,reak Points Step by step execution 0atc"ing +ariables ("anging values of variables

A> Running Tests o o o o o 8ormal !xecution ,atc" !xecution T"roug" $&) Scripting Tests unning t"roug" framework Sc"eduled !xecution

B> Analy(ing Results o o o o QTP esult window #efining our own esults !xporting esults #eleting esults efects

C> Reporting

o )anual #efect eporting o Tool based #efect eporting o 0orking wit" Quality (enter ----------------------------------------------------------Types of )tatements in QTP Test + Test )cript i> eclarations <+ariables and constants=

#im x, y, % (onst (ity, Price ii> "#$ect calls !xCB #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set NgcreddyN !x:B ,rowser<NGoogleN=.Page<NGoogleN=.7ink<NGmailN=.(lick iii> Comments iv> *low Control )tatements <(onditional 6 7oop= !xB= If TotalOTickets*Price T"en )sgbox NTest PassedN !lse )sgbox NTest .ailedN !nd If v> *unction + Action calls !xB (all 7ogin<NgcreddyN,NmercuryN= vi= /tility Statements !xCB System/til. un N(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN **It launc"e t"e $pplication !x:B System/til. un N(BPProgram .ilesPInternet !xplorerPI!@P7& !.!@!N,N"ttpBAAwww.icicibank.comAN

vii> .B script ot!er statements !xamplesB &ption !xplicit 0ait <CI=

Recording Tests

Recording and Running


a> Test Recording Process It is a Process of ecording user operations on $/T <$pplication /nder Test=. #uring ecording QTP (reates steps in ?eyword view, and generates t"em in a script in t"e !xpert view. Simultaneously it adds &b'ects information into &b'ect epository. #> Running +&,ecution Process #uring unning QTP reads statements one by one and gets &b'ect Information from t"e &b'ect epository, based on t"at Information performs operations on $/T. c> Recording Modes QTP "as G ecording )odes to generate Tests A Test Scripts i> 2ormal Recording It records /ser )ouse and ?eyboard operations on $/T wit" respect to ob'ects, but unable to record continuous mouse operations like #igital Signatures, grap"s, paints etc. #uring recording QTP generates +bScript statements in Test Pane, Simultaneously it stores ob'ects information into ob'ect repository. 2avigation8 $utomationL ecord &r Select ecord option on automation toolbar &r /se s"ort cut key <.G= )teps for preparing a Test <t"roug" C.Put $/T in base state :.Select ecord &ption ecording=B

G.It s"ows ecord and un Settings, Select type of !nvironment <0indows or 0eb= I.Select ecord &ption <It s"ows two &ptions B C. ecord and un Test on any open window based applications :. ecord and un only on= If we select first option it records on any opened application on #esktop. If we select Second option, it asks for t"e pat" of t"e $/T, $fter Providing t"e pat" it records only on t"at particular application.= D.(lick &? E.Perform actions on $/T >.Stop recording. H.Save t"e Test ii> Analog Recording8 It records t"e exact mouse and keyboard operations. 0e can use t"is mode for recording continuous mouse operations. It is not useful for recording normaloperations w"y because it does not generate steps for eac" operation, generates total user actions in a Track .ile. T"e Track file is not editable. 2avigation8 C.?eep tool under recording mode :.$utomation L$nalog ecording & /se S"ort cut ?ey <S"ift Q $7TQ.G= )teps for preparing a Test <t"roug" $nalog ecording=B

C.7aunc" $/T <or we can launc" $/T t"roug" QTP= :.Select ecord option G.$utomationL$nalog ecording I.$nalog ecording Settings #ialog box opens <In t"is #ialog box two options available. C. ecord relative to t"e screen :. ecord relative to t"e following window= <If we select first option QTP records /ser operations wit" respect to #esktop co-ordinates.

If we select Second option, we "ave to s"ow t"e window <$/T=, after s"owing t"e 0indow it records wit" respect to t"at window co-ordinates.= D.Select any one option in t"e dialog box and click Start $nalog record. E.It records /ser actions >.Stop ecording iii> 4ow 4evel Recording It records some operations on 8on-supported environments apart from 8ormaloperations. T"is mode records at t"e ob'ect level and records all run time ob'ects as window or winob'ect Test ob'ects. /se 7ow 7evel by QTP. ecording for recording in an environment not recogni%ed

2avigation8 C.?eep tool under recording mode :.$utomation L7ow 7evel ecording )teps for preparing a Test <t"roug" 7ow 7evel ecording=B

C=7aunc" $/T <or we can launc" $/T t"roug" QTP= :=Select ecord option G=$utomationL 7ow 7evel ecording I=Perform options on $/T D=Stop ecording E=Save t"e Test d> isadvantages of Recording

9 It occupies a lot of memory space<due to duplicate ob'ects=, So QTP performance will be reduced 9 8o (entrali%ed )aintenance mec"anism , So )odifications are very difficult 9 /ser may not "ave command on t"e is difficult 9 ecorded script, So locating errors

ecorded scripts are QTP internal files, t"ey may corrupt.

e> Advantages of Recording+ 1!ere Applica#le

9 It is used for $naly%ing t"e $/T in t"e initial stage to find out weat"er t"e QTP tool is ecogni%ing all of our $pplication &b'ects or not 9 It is easy to create Tests A Test Scripts 9It is used for fre4uently c"anging /I </ser Interface= 9 It takes less time to create Tests

Keyword Driven Methodology

Keyword- riven Met!odology


,y creating our tests wit" a keyword-driven met"odology in mind, our tests become more modular, focusing on t"e operations to test using bot" QuickTest built-in keywords and your own user-defined keywords. $dditionally, because it is possible to add ob'ects to t"e ob'ect repository before t"ey exist in an application, it is possible to begin preparing our automated keyword-driven tests even before a software build containing t"e new ob'ects is available. )etting up "#$ect Repositories In t"is step, we build one or more ob'ect repositories and ensure t"at all ob'ects "ave clear names t"at follow any predetermined naming conventions defined by ourorgani%ation. 0e can create ob'ect repositories using QuickTest functionality to recogni%e and learn t"e ob'ects in your application, or we can manually define ob'ects. ,y creating and populating s"ared ob'ect repositories t"at can be associated wit" multiple actions, we can use t"e same ob'ect repository in multiple tests. Add Dlearn> o#$ects from our application7 0e instruct QuickTest to learn t"e ob'ects in our application according to filters t"at we define. !nsure t"at ob'ects in t"e ob'ect repository "ave names t"at are easy for applicationtesters to recogni%e and t"at follow any establis"ed ob'ect naming guidelines.

T"is "elps make bot" test creation and maintenance easier over time. Configuring Quic'Test According to our Testing 2eeds $fter we set up t"e test automation infrastructure, we need to configure QuickTest to use t"is infrastructureB #efine your global testing preferences. 0e need to specify configuration settings t"at affect "ow we create and run tests in generalRt"ese settings are not test-specific. Building our Tests 0e can create tests t"at are as simple or complex as needed. In general, it is best to create tests and actions t"at c"eck 'ust one or a few simple functions or complete atransaction rat"er t"an creating long tests and actions t"at perform several complex tasks or t"at perform many tasks. 0e may perform t"e following tasks w"en creating tests and test stepsB (reate new tests, if needed. To do so, select .ile L 8ew L Test. (reate t"e re4uired actions. $ssociate our ob'ect repositories wit" t"e relevant actions T"is enables us to insert steps t"at perform operations on t"ose ob'ects. $ssociate our function libraries wit" t"e relevant tests. T"is enables us to use our special keywords in any of t"e associated tests.

Ob ect Re!ository

"#$ect Repository8 It is a storage place of QTP w"ere ob'ects information can be stored and it also acts as interface between t"e Test script and t"e $/T in order to identify t"e ob'ects during execution. "#$ect8 &b'ect is somet"ing, w"ic" "as structure and properties. )oftware o#$ects8

0e call 0indows, 0eb Pages, ,uttons, !dit boxes, ("eck boxes etc.. as software ob'ects. Types of "#$ect in QTP8 T"ere are four types of ob'ect available in QTP. C. un time ob'ects :. Test ob'ects G. /tility ob'ects I. $utomation ob'ectsA/ser defined ob'ects. Run time o#$ects8 T"e ob'ects present in t"e $/T. !xB ,uttons, 7inks, etcS Test "#$ects8 eferences of 0eb,utton, 7ink, etcS un time ob'ects. !xB 0in!dit, 0in,utton,

2ote8 Test ob'ects names vary from one environment to anot"er. 0tility o#$ects T"ey are QTP reserved ob'ects used for Testing and !xB C. System/til for launc"ingAclosing t"e application. :. eporter for defining results. G. Services for inserting transaction points I. !nvironment for using environment variables Automation o#$ects+0ser defined o#$ects /ser can create ob'ects5 t"ose can be used for performing specific operations. !xB (reating ob'ects in filesystemob'ect class, adodb.connection class, dictionaryob'ect class, !xcel. $pplication class etc. T!ere are two types of repository availa#le in QTP7 C. 7ocal repository <.)T extension= :. S"ared repository<.TS extension= 4ocal Repository8 QTP creates a 7ocal epository for every $ction automatically during ecording. T"at cannot be s"ared among tests. esult reporting.

/ser can add some more ob'ects to 7ocal repository /ser can perform rename, delete operations on local repository. $s it is QTP internal file user no need to save modifications.

)!ared Repository8 /ser <Test !ngineer= creates t"e S"ared epository by adding ob'ects. T"at can be s"ared among number of tests. /sing t"is met"od user can perform modifications on ob'ects easily.

"perations on "#$ect Repository


Adding o#$ects a. 7ocal epositoryB 8avigationB open 7ocal epository < esource )enu L &b'ect epository=

ob'ectsL$dd ob'ects to 7ocalL S"ow t"e &b'ectL(lick &k <8o need to save separately, it saves automatically= B7 )!ared Repository8 8avigationB esource menuLob'ect repository managerLob'ectL$dd ob'ectsLs"ow t"e windowAob'ectLclick ok o o o o Selected ob'ect only #efault ob'ect types $ll ob'ects types Selected ob'ect types

<If we select first option it stores Selected ob'ects only, if we select second option it stores all default ob'ects, if we select t"ird option it stores $ll ob'ects including static ob'ects, if we select fourt" option, we "ave to select ob'ectclasses t"en it stores t"at class ob'ects, we can select more t"an one class also.= Renaming "#$ects a. 7ocal epositoryB

esources L ob'ect repository Lselect ob'ect and rig"t click Lc"oose rename option Lmodify t"e nameLrelease t"e mouse.Lclose repository b. S"ared epositoryB

esources Lob'ect repository managerLfileLopenLbrowse pat" of t"e repository file LfileLenable editingLselect ob'ect 6 ig"t clickLc"oose rename optionLmodify t"e name L release mouseLsave t"e file 6 close repository manager. eleting "#$ects a. 7ocal epositoryB

esources L ob'ect repository Lselect ob'ect and rig"t click Lc"oose delete option Lconfirm deletionL. Lclose repository b. S"ared epositoryB

esources Lob'ect repository managerLfileLopenLbrowse pat" of t"e repository file LfileLenable editingLselect ob'ect 6 ig"t clickLc"oose delete optionLconfirm t"e deletion Lsave t"e file 6 close repository manager. Associating "#$ect Repositories to an Action+Test esourcesL$ssociate repositoriesLclick add icon <Q=Lbrowse pat" of t"e repositoryL$ssociate wit" an actionLclick ok Merging Repositories esources L ob'ect repository managerLtoolsLob'ect repository merge tool Lbrowse pat" of t"e first repositoryL browse pat" of t"e second repositoryLclick okLclick closeLsave t"e merged repositoryLclose t"e repository manager.

2ote8 $fter merging also, source repository files will be available, if we do not want source files we can delete. efining 2ew Test "#$ects 8avigationB &b'ectL#efine new test ob'ect LSelect !nvironmentLSelect (lass oft"e ob'ectL!nter name of t"e ob'ectL(lick $ddLclick closeLSelect ob'ectLselect property nameLenter value <like t"is select one by one properties and enter values=Lsave 2ote8 T"is feature can be used for preparing tests before t"e $/T is ready. )pying "#$ects .or getting ob'ects information, <Test ob'ects names, property 6 +alues= QTP isproviding a feature called &b'ect Spy, using t"is we can get ob'ects information. 8avigationLToolsLob'ect spyLtake "and icon 6 S"ow t"e ob'ectLget information <&b'ect Spy s"ows t"e specific ob'ects all available properties wit" t"eir values= 2ote8 $s &b'ect spy is an important feature, it can be available in G $reas.<C. In tools )enu :. In local repository G. In epository manager= .iew "ptions 7ocate in epository

T"is feature can be used for identifying ob'ects from application to repository. 8avigationB +iewL7ocate in repository Ls"ow t"e ob'ectLclick &kLit locates specified ob'ect in t"e repository. 1ig"lig"t in $pplication T"is feature can be used for identifying ob'ects from repository to application. 8avigationB Select ob'ect in t"e repository LviewL"ig"lig"t in applicationLit "ig"lig"ts specified ob'ects in t"e application. &,porting Repository to an 3M4 file

0e can export our repository file to an xml file. 8avigationB .ile Lexport Test ob'ects to @)7 !nter t"e file name and Save wit" xml extension. %mporting Repository from 3M4 file7 0e can import @)7 file to our repository. 8avigationB .ileLimport from @)7 Lbrowse pat" of t"e @)7 file Lit loads ob'ects. 8oteB T"e purpose of t"is feature is !diting ob'ects information outside of t"e QTP 8avigationB esource menuLob'ect repository <S"ort cut key (trlQ =

Ob ect "denti#ication $on#iguration


"verview8

"#$ect %dentification Configuration

Generally for every ob'ect :;-:D properties information available, 4tp recogni%es ob'ect using : ;r G important properties. Qtp "as default ob'ect identification configuration for every environment, if we feel t"at config is not sufficient for recogni%ing ob'ects in our application, we can configure some more "#$ect %dentification Types a= C= := b= C= := c= C= := 2ormal identification )andatory properties $ssistive properties )mart identification base filter properties optional filter properties "rdinal identifier location index

G=

creation time<only for web=

QTP learns information in t!e following in case of normal identification8 .irst of all t"e 4tp learns all t"e mandatory properties at a time and t"inks w"et"er t"eseproperties sufficient to identify t"e ob'ect uni4uely. if it feels sufficient t"en it stops learning ot"erwise, It learns first assistive property and once again stops and t"inks, like t"is 4tp learns one by one. $t t"e end of assistive properties list also if it feels not satisfied and it finally goes to &rdinal Identifier. QTP learns information in t!e following in case of )mart %dentification8 Smart identification is an optional feature, if we feel normal identification is not sufficient for any ob'ect, and t"en we configure Smart Identification for t"at ob'ect, in order to avoid &rdinal Identifier. $fter normal identification if 4tp feels not satisfied t"en it goes to smart identification. in smart identification : types of properties available, first 4tp learns all base filter propertiesat a time and t"inks w"et"er t"ese properties are sufficient for identifying t"e ob'ect uni4uely. If it feels sufficient, t"en it stops learning ot"erwise it goes &ptional .ilterProperties and learns one by one. Still it feels not satisfied finally it goes to &rdinal Identifier. "rdinal identifiers8 T"ere are G types of ordinal identifiers available C= 7ocationB is based on ob'ect location in t"e $/T ,location starts from %ero. := indexB it is based on se4uence of t"e programs, index starts from %ero G= (reation timeB it is based on loading time of t"e web ob'ects. 4tp generates ;,C,: like numbers. Tool )ettings Glo#ali(ation8

$s QTP is a I-tier<Stand-alone= application,making Tool settings globally is not possible. .or making tool settings global, QTP is providing a special feature called NGenerate ScriptN. )T&P)8 C= Settings available in G areas. a= .ile-LSettings b= Tools-L&ptions c= Tools-L&b'ect Identification := Perform re4uired settings and generate Scripts G= S"are Script files to team members and ask t"em to execute t"ose scripts. 8&T!B $fter executing t"ese scripts all team members can get same settings.

QTP Methods

QTP Met!ods + "perations


:> Activate Met!od It activates dialog boxesA0indows SyntaxB &b'ect "ierarc"y. $ctivate !xB #ialog<T7oginU=.$ctivate 0indow<T.lig"t eservationU=.$ctivate => Clic' )et"od It clicks on an ob'ect <,uttons= SyntaxB &b'ect "ierarc"y. (lick !xB #ialog<T7oginU=.0inbutton<TokU=.click ?> Close )et"od It closes t"e window,#ialog box, ,rowser window etc. SyntaxB &b'ect "ierarc"y. (lose !xB 0indow<T.lig"t eservationU=.(lose

,rowser<T,rowserU=.(lose @> #lclic' It #ouble clicks t"e ob'ect. A> )et )et"od It can be used in t"ree ways. a. .or setting t"e value of an edit box SyntaxB &b'ect 1ierarc"y. S!T T+alueU !xB #ialog <T7oginU=.0in!dit<T$gent 8ameU=.Set TasdfU b. Selecting a adio ,utton SyntaxB &b'ect 1ierarc"y. Set !xB 0indow<N.lig"t eservationN=.0in adio,utton<N,usinessN=.Set c. SelectingA#eselecting c"eck boxes SyntaxBob'ect 1ierarc"y.Set T&8AoffU !xB 0indow <N.lig"t eservationN=. #ialog<N&pen &rderN=.0in("eck,ox<N&rder 8o.N=.Set N&8N B> )elect )et"odB It is used for selecting an item from a combo box or list box. SyntaxB &b'ect "ierarc"y.select TitemU !xB 0indow<N.lig"t eservationN=.0in(ombo,ox<N.ly .romBN=.Select N7ondonN 0indow<N.lig"t eservationN=.#ialog<N.lig"ts TableN=.0in7ist<N.romN=.Select NC:D>: C> Get.isi#lete,t8 It returns Text from t"e specified area. SyntaxB +ariable Oob'ect "ierarc"y.getvisibletext !xB xO0indow<N.lig"t eservationN=.0in(ombo,ox<N.ly .romBN=.Get+isibleText msgbox x E> GetRoproperty8 It returns current ob'ect property value. It can be used for getting any ob'ectMs, any property value. SyntaxB +ariable O ob'ect "ierarc"y.getroproperty <Tproperty nameU= !xB xO0indow<N.lig"t eservationN=.0in!dit<NTicketsBN=.Get &Property <Nwidt"N= msgbox x F> 2avigate )et"odB It opens a specified / 7 in t"e ,rowser. SyntaxB ob'ect "ierarc"y.navigate T/ 7U

!xB ,rowser<NVa"ooWN=.8avigate "ttpBAAwww.google.co.inA :;> Getitemscount8 It returns number of items in a combobox. SyntaxB +ariableOob'ect "ierarc"y.getitemscount !xB xO0indow<N.lig"t eservationN=.0in(ombo,ox<N.ly .romBN=.GetItems(ount msgbox x ::> Getcontent8 It returns all items from a combobox. SyntaxB variableOob'ect "ierarc"y.Get(ontent !xB xO0indow<N.lig"t eservationN=.0in(ombo,ox<N.ly .romBN=.Get(ontent msgbox x :=> &,ist propertyB It c"ecks w"et"er t"e ob'ect is available or not. SyntaxB &b'ect "ierarc"y.exist<time in seconds= !xB 0indow<N.lig"t eservationN=.!xist<D=

Data Table Methods

QTP

ata Ta#le Met!ods

<C= Add )!eet8 0e can use t"is met"od to TaddU one new s"eet to t"e run time data table. SyntaxB #ataTable.$ddS"eet Ns"eet nameN !xB #ataTable.$ddS"eet NgcreddyN <:= elete )!eet8 un

0e can use t"is met"od to TdeleteU one specified s"eet from t"e Time #ata table. SyntaxB datatable.#eleteS"eet <S"eetXI#= !xB datatable.#eleteS"eet <G= <G= Get)!eetCount

0e can use t"is met"od to count number of s"eets in t"e run time data table. SyntaxB datatable.GetS"eet(ount

msgbox datatable.GetS"eet(ount <I= GetRowCount 0e can use t"is met"od to count number of rows in t"e Cst s"eet <longest column= of t"e un time data table. SyntaxB datatable.Get ow(ount !xB msgbox datatable.Get ow(ount <D= Get)!eet 0e can use t"is met"od to return a specified s"eet from t"e Time data table. SyntaxB datatable.GetS"eet<S"eetI#= !xB msgbox datatable. GetS"eet<C=.Get ow(ount <E= .alue 0e can use t"is met"od to set or get value of cell in t"e specified parameter and t"e current row of t"e um time data table. To set data SyntaxB datatable.+alue<ParameterX8ame, S"eetX8ame= O +alue A variable &r datatable<ParameterX8ame, S"eetX8ame= O +alue A variable To get data SyntaxB +ariable O datatable.+alue<ParameterX8ame, S"eetX8ame= &r +ariable O datatable<ParameterX8ame, S"eetX8ame= un

!xB &ption explicit #im a, b, c aOdatatable.+alue <C,C= bOdatatable.+alue <:,C= cOcint<a=Qcint<b= datatable.+alue <G,C= O c 8oteB #efault property of #atatable is value <>= )etCurrentRow 0e can use t"is met"od to take a specified row as current row in t"e Time #atatable <,y default it is Cst ow of Cst S"eet= SyntaxB datatable.Set(urrent ow< owX8umber= gONgcreddyN datatable.Set(urrent ow <G= datatable.+alue <C,C= O g <H= )et2e,tRow 0e can use t"is met"od to take t"e row after t"e current (urrent ow in t"e un time data table. SyntaxB datatable.Set8ext ow !xB gONgcreddyN datatable.Set(urrent ow <G= datatable.Set8ext ow datatable.+alue <C,C= Og <J= )etPrevRow 0e can use t"is met"od to take t"e row before t"e current (urrent ow in t"e un time data table. SyntaxB datatable.SetPrev ow ow as 8ew ow as 8ew un

!xB gONgcreddyN datatable.Set(urrent ow <G= datatable.SetPrev ow datatable.+alue <C,C= Os <C;= %mport 0e can use t"is met"od to import )icrosoft !xcel .ile to t"e untime #ata Table<Including all s"eets= SyntaxB datatable.Import TPat" of .ileU !xB datatable.Import T.BPInputdata.xlsU CC= %mport)!eet 0e can use t"is met"od to import a specified s"eet of )icrosoft !xcel S"eet to t"e untime #ata table. SyntaxB datatable.ImportS"eet TPat" of .ileU, TSource S"eetU, T#estinationS"eetU !xB datatable.ImportS"eet T!BPgcreddy.xlsU,G,C <C:= &,port 0e can use t"is met"od to export a copy of anot"er location <Including all s"eets= SyntaxB datatable.!xport TPat" of .ileU !xB datatable.!xport T.BPgcreddy.xlsU CG= &,port)!eet 0e can use t"is met"od to export a copy specified s"eet of un Time #ata tableto t"e existing or new !xcel .ile. un Time #ata table to

SyntaxB datatable.!xportS"eet TPat" of .ileU, TS"eet 8ame A Source S"eetU !xB datatable.!xportS"eet T.BPgcreddy.xlsU, : ********************** ata riven Testing for 4ogin "peration using ata Ta#le met!ods

#atatable.$ddS"eet N7oginN #atatable.ImportS"eet N(BP#ocuments andSettingsPgcrP#esktopPgcreddy.xlsN,C,G owsXcountO#atatable.GetS"eet<G=.Get ow(ount .or iO C to owsXcount #atatable.Set(urrent ow<i= System/til. un N(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN,NN,N(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPN,NopenN #ialog<N7oginN=.$ctivate #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set #atatable<N$gentN,G= #ialog<N7oginN=.0in!dit<NPasswordBN=.Set #atatable<NPwdN,G= #ialog<N7oginN=.0in,utton<N&?N=.(lick If window<N.lig"t eservationN=.exist<C;= T"en 7oginON7ogin &peration SuccessfulN #atatable<N esultN,G=O7ogin eporter. eport!vent micPass,NresN,NPassedN else eporter. eport!vent mic.ail,NresN,N.ailedN 7oginON7ogin &peration .ailedN #atatable<N esultN,G=O7ogin #ialog<N7oginN=.#ialog<N.lig"t eservationsN=.0in,utton<N&?N=.(lick #ialog<N7oginN=.0in,utton<N(ancelN=.(lick !nd If If 0indow<N.lig"t eservationN=.!xist<G=T"en 0indow<N.lig"t eservationN=.(lose !nd if 8ext

Descri!tive Progra%%ing

escriptive Programming

!ntering A Providing ob'ects information directly into t"e test script is called #escriptive Programming. In t"is met"od of script creation, we no need to "ave &b'ect epositories. Advantages8 a= #escriptive Programming based Test scripts are faster in execution t"an epository based Test scripts. b= Scripts are portable <we can run t"ese scripts from any mac"ine easily= c= )aintenance is easy <less amount of resources= d= 0e can start Test !xecution process even t"oug" $pplication is not ready. escriptive programming is #asically = types7 C. Static Programming :. #ynamic Programming

)tatic Programming
In t"is style of script generation, we provide ob'ects information directly into t"e script. &,ample8 C= Invokeapplication N(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN := dialog<NtextBO7oginN=.$ctivate G= dialog<NtextBO7oginN=.0inedit<Nattac"ed textBO$gent 8ameBN=.Set NgcreddyN I= dialog<NtextBO7oginN=.0inedit<Nattac"ed textBOPasswordBN=.Set NmercuryN D= dialog<NtextBO7oginN=.0inbutton<NtextBO&?N,Nwidt"BOE;N=.(lick 2ote8 C. #ialog, 0in!dit and 0in,utton F Test &b'ects :. text, attac"ed text - Property names G. 7ogin, $gent 8ameB, PasswordB, &? - Property values or 7ogical 8ames of t"e &b'ect I. $ctivate, Set, Setsecure, (lick - )et"ods

2ote=8 If we feel one property information is not sufficient for recogni%ing t"e ob'ect uni4uely, t"en we can provide more properties information by separating wit" commas. 2ote ?8 If we want to get ob'ects information <Test ob'ects, properties and values=, we can use ob'ect spy feature. T"is feature is available in Tools )enu, in local repository and in repository manager. &,ample =8 System/til. un N(BPProgram .ilesPInternet !xplorerPI!@P7& !.!@!N,NN,N(BPProgram .ilesPInternet !xplorerN,NopenN ,rowser<NtitleBOGoogleN=.Page<NtitleBOGoogleN=.Sync ,rowser<NtitleBOGoogleN=.8avigate N"ttpBAAwww.icicibank.comAN

------------------------------------------------------------------If we want maintain Y&b'ects informationM in centrali%ed location t"en we can use (onstants. StepsB (reating (onstantsB (onst 7oginONtextBO7oginN, $gentONattac"ed textBO$gent 8ameBN (onst Pwd ONattac"ed textBOPasswordBN, &kONtextBO&?N 8oteB we can declare no of (onstants in a line by separating wit" (amas <,=, if we take ot"er line t"en we "ave to use (onst Statement again. (reating a 7ibrary file Place (onstants in 8otepad and save as .vbs file $ssociate t"e 7ibrary file to QTP <.ile-LSettings-L esources-L (lick add <Q= icon-L ,rowse pat" of t"e 7ibrary file-L(lick $pply and click &k buttons &t"erwise, we can load t"e library file during run-time SyntaxB

!xecute.ile TPat" of t"e 7ibrary file<.vbs=U $fter t"at create t"e Test Script using (onstants (reating t"e Test Script using (onstantsB Invokeapplication N(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN #ialog<7ogin=.$ctivate #ialog<7ogin=.0inedit<$gent=.Set NasdfN #ialog<7ogin=.0inedit<PwdN=.Set NmercuryN #ialog<7ogin=.0inbutton<&k=.(lick $dvantagesB If we maintain &b'ect Information in t"e centrali%ed location, t"en we can "andle modifications easily. -------------------------------------------------------------------

ynamic Programming
In t"is style of script generation, first we create description ob'ects, provide properties information and use description ob'ects in t"e test script. Creating Properties Collection "#$ects Set Set Set Set o7oginOdescription.(reate o$gentOdescription.(reate oPasswordOdescription.(reate o&kOdescription.(reate

&ntering Properties %nformation into "#$ects o7ogin<NtextN=.valueON7oginN o7ogin<Nwidt"N=.valueOG:; o7ogin<N"eig"tN=.valueO:;I o$gent<Nattac"ed textN=.valueON$gent 8ameBN oPassword<Nattac"ed textN=.valueONPasswordBN o&k<NtextN=.valueON&?N Generating Tests using Properties collection "#$ects Invokeapplication N(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN

#ialog<o7ogin=.$ctivate #ialog<o7ogin=.0inedit<o$gent=.Set NgcreddyN #ialog<o7ogin=.0inedit<oPassword=.Set NmercuryN #ialog<o7ogin=.0inbutton<o&?=.(lick 2ote:8 (reate #escription ob'ects and put into one library file, by associating t"at library file, we can generate tests. 2ote=8 #ynamic programming is some difficult in preparation t"an static programming but maintenance is very easy. ------------------------------------------------------

&,amples8
/andling similar+ uplicate "#$ects using %nde, Property System/til. un N(BPProgram .ilesPInternet !xplorerPI!@P7& !.!@!N ,rowser<NnameBOGoogleN=.Page<NtitleBOGoogleN=.Sync ,rowser<NnameBOGoogleN=.8avigate "ttpBAAwww.''perfumes.comA ,rowser<NnameBO22 Perfumes-#iscount perfume c"eap brand name perfumes,fragrance 6 cologne onlineN=.page<NtitleBO22 Perfumes-#iscount perfume c"eap brand name perfumes, fragrance 6 cologne onlineN=.7ink<NinnertextBO egisterN,NindexBO;N=.(lick

"nserting $hec&!oints

%nserting C!ec'points
("eck point is a verification point, it takes expected result from t"e user and compares wit" actual results during execution and provides test results.

T!ere are :: C!ec'points availa#le in QTP8


:7 =7 ?7 @7 A7 B7 C7 E7 F7 Standard c"eck point Text c"eck point Text area c"eck point ,it map c"eck point #ata base c"eck point $ccessibility c"eck point @)7 ("eck point <from $pplication= @)7 ("eck point <from esource= Page c"eck point

:;. Image c"eckpoint ::. Table c"eckpoint 8ote CB .rom E to CC c"eckpoints are only for 0eb. 8ote :B .rom J to CC c"eckpoints are "idden c"eckpoints, we can insert t"esec"eckpoints t"roug" standard c"eckpoint.

:7 )tandard C!ec'point8
It c"ecks ob'ect property values. 0e can use t"is c"eckpoint for c"ecking anyproperty value. 2avigation for %nserting standard c!ec'point ?eep tool under recording mode L place cursor in desired location L Insert L c"eck point L Standard c"eckpoint L S"ow t"e ob'ect L click okay L select property and enter expected results 6 click &k and stop ecording. 2avigation for &diting standard c!ec'point Select ("eckpoint statement and rig"t click L c"oose c"eckpoint properties option L modify t"e value L click &k. 2avigation for eleting standard c!ec'point8

Select ("eckpoint statements and rig"t click L c"oose delete option. %nserting )tandard c!ec' points t!roug! active screen8 +iew L $ctive Screen Lplace cursor in desired location LPlace mouse pointer on active screen 6 rig"t clickL c"oose insert standard c"eckpoint option L click ok L enter expected result L click ok 8oteB Inserting Standard c"eck points t"roug" keyword view same as in expert view. 2ote8 0e can insert standard c"eckpoints in G ways.

a7 T"roug" expert view, #7 T"roug" keyword view, c7 T"roug" $ctive screen. => Te,t C!ec'point8
It ("ecks ob'ectMs text property value in different ways. 2avigation8

?eep tool under ecording mode LInsert menu L c"eckpoint L Text c"eckpoint L S"ow t"e ob'ect L click ok L Select options (Match case; ignore spaces# e+act match# te+t not displa"ed.$ 0e can select one or more options L click ok 6 stop ecording.

?> Te,t Area C!ec'point8


It c"ecks t"e text area present in t"e application. 8avigationB ?eep tool under ecording mode L Insert menuL ("eckpoint L Text area c"eckpoint L )ark t"e area of text L select one or more options (Match case# ignore spaces# e+act match# te+t not displa"ed.$ (lick ok and stop recording.

@7 Bitmap c!ec'point8
It compares bitmaps5 we can compare complete bitmaps as well as part of t"e bitmaps. 2avigationB ?eep tool under ecording mode L Insert menu L ("eckpoint L ,itmap c"eckpoint L s"ow t"e ,itmap Lclick ok Lselect Tc"eck only selected areaU option if we want to compare part of t"e bitmap L click ok Lstop recording.

A7

ata#ase c!ec'point8
It c"ecks (ontent of t"e back end #atabase. 2avigation8 Insert L c"eckpoint L #atabase c"eckpoint Lc"oose Tspecify SQ7 statement manuallyU option Lclick next L click create L select mac"ine data source L Select #S8 <QTXflig"tG:= L click ok L enter SQ7 statement <select * from orders= L finis" L click ok. 2ote8 "ere we do not need to put tool under $/T since data is from backend. ecording mode and we do not need

B7 Accessi#ility c!ec' point8


It c"ecks w"et"er t"e webpage in our web application is developed according to 0G( <0orld 0ide 0eb consortium= ules and egulations or not. It is a configurable c"eckpoint, according to our re4uirements, we can customi%e.

Configuring accessi#ility c!ec'point8 Tools menuL options Lweb L advanced L c"eckAunc"eck items L click apply L click ok %nvigilation8 ?eep tool under recording mode wit" web environment LinsertLc"eckpointLaccessibility c"eckpointLs"ow t"e webpageLclick okLclick okLstop recording. esult (riteriaB a= If item is available but not according to 0G( rules t"en fail. b= If an item is available, according to 0G( rules t"en Pass. c= If an item is not available t"en result would be pass

C7 3M4 C!ec' point Dfrom Application>


It c"ecks content of t"e @)7 file. 8avigationB ?eep tool under ecording mode in web environment L insert menu L c"eckpoint <fromapplication=L s"ow t"e xml pages Lclick ok L stop ecording.

E7 3M4 C!ec' point Dfrom Resource>


It c"ecks content of t"e @)7 file. 8avigationB Insert menu L c"eckpoint Lxml c"eckpoint <from resource= L browse pat" of t"e @)7 .ile L click ok L click ok. 8oteB C. If @)7 file is an individual and pat" available, and t"en we can go for inserting xml c"eckpoint from resource. 8oteB :. If @)7 file is part of web application, separate pat" is not available t"en we can c"oose inserting @)7 c"eckpoints from application.

F7 Page c!ec'point8
It c"ecks number of 7inks, Images and 7oading time in a web page. It is a "idden c"eckpoint5 we can insert t"is t"roug" standard c"eckpoint. 2avigation8 ?eep tool under ecording mode wit" web environment L Insert menu L c"eckpoint L Standard c"eckpoint Ls"ow t"e web page L click ok L click ok L stop recording.

:;7 %mage c!ec'point8

It c"ecks Image property values. 2avigation8 ?eep tool under ecording mode wit" web environment L Insert menu L c"eckpoint Lstandard c"eckpoint L s"ow t"e image L select image L click ok L click ok Lstop recording.

::7 Ta#le c!ec'point8


It c"ecks content of t"e web tables. 8avigationB ?eep tool under ecording mode under web environment L Insert menu L c"eckpoint L standard c"eckpoint Ls"ow t"e web table L click ok Lstop recording.

%nserting "utput .alues


It is a step in w"ic" one or more values are captured during test execution. T"e values can later be used as input at a different point in t"e run session or we can use as input for anot"er test. It is stored in run time data table5 it is located in QTP result window and can be retrieved later.

Types of "utput .alues8


:7 =7 ?7 @7 A7 B7 Standard output value Text output value Text area output value #atabase output value @)7 output value <.rom $pplication= @)7 output value <.rom esource=

:> )tandard output value8


0e can use standard output values to output t"e properties values of most ob'ects. 2avigation8

?eep tool under ecording mode L Insert menu Loutput valueL standard output value L s"ow t"e ob'ect L click ok L select property L modify t"e column name <if re4uired= L click ok Lclick ok Lstop recording.

=> Te,t output value8


0e can use Text output values to output text strings displayed in an application. 0"en creating a text output value we can output a part of t"e ob'ects text and we can also specify text before and after options. 2avigation8 ?eep tool under recording modeL Insert menuL output value L text output value L s"ow t"e text Lselect one of t"e option<output textAtext beforeAtext after= L click modify if you want to c"ange t"e column name L click ok L click ok.L c"eck in runtime table after running it.

?> Te,t Area output value8


0e can use text area output values to output text strings displayed wit"in a definedarea of t"e screen. 2avigation8 ?eep tool under recording mode L insert menu Loutput value L text area output value L)ark t"e text area Lclick modify t"e column name if necessary L click ok L again click ok L c"eck in run time table after running it..

@>

ata#ase output value8

0e can use #atabase output values to output t"e value of t"e contents of database cells. 2avigation8 Insert menuL output value L #atabase output valueL c"oose specify SQ7 statementsmanually Lclick next Lclick create LSelect )ac"ine #ata source L Select #river<QTXflig"tG:= L click ok L enter SQ7 statement <select *from orders= L click finis" L select data cells L click ok L un and it will capture and see t"e results in run time table.

A> 3M4 output value Dfrom application>8

we can use @)7 output values to output t"e values of @)7 elements in @)7documents. 8avigationB ?eep tool under recording mode wit" web environment L Insert menu L output value L @)7 output value from application L S"ow t"e @)7 document L select elements L click ok Lstop recording.

B> 3M4 output .alue D*rom Resource>8


0e can use @)7 output values to output t"e values of @)7documents. 2avigation8 Insert menu Loutput valueL @)7 output value from resource L browse pat" of t"e @)7 file L click ok L select elements Lclick ok. @)7 elements in

Para%eteri'ation

Passing parameters, t"roug" t"is we can pass multiple values. 0e use parameteri%ation in #ata #riven Testing. ata riven TestingB Testing t"e Same operation wit" multiple sets of test data. Types of Parameteri(ationB 0e can parameteri%e tests in several ways in QTP C. T"roug" 7oop Statements :. #ynamic Test #ata Submission G. T"roug" #ata Table I. .etc"ing Test #ata directly from !xternal files <.lat files 6 Spreads"eets= D. .etc"ing Test #ata directly from #atabases <)S$cess, &racle etc=. E. Getting Test #ata from front end ob'ects. :7 T!roug! 4oop )tatementsB 0e can use loop statements for passing se4uential numbers 6 7ogical 8umbers. 8oteB 0e canMt generate Strings. .or ordernoOC to C; step C 3 for one increment step keyword is not mandatory 0indow<N.lig"t eservationN=.$ctivate 0indow<N.lig"t eservationN=.0in,utton<N,uttonN=.(lick

0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N&rder 8o.N=.Set N&8N 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in!dit<N!ditN=.Set orderno 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in,utton<N&?N=.(lick 8ext =7 ynamic Test ata )u#missionB T"roug" 7oop Statements we can give strings also but every time user "as to enter data. .or xOC to G $gent Oinputbox<Nenter an $gent 8ameN= PasswordOinputbox<Nenter a passwordN= invokeapplication N(BPProgram .ilesP)ercury InteractivePQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN #ialog<N7oginN=.$ctivate #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set $gent #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Type micTab #ialog<N7oginN=.0in!dit<NPasswordBN=.SetSecure password #ialog<N7oginN=.0in,utton<N&?N=.(lick 0indow<N.lig"t eservationN=.(lose 8ext ?7 T!roug! ata Ta#le8 QTP adds one data table <Spreads"eet= for every test, we can use #ata Table for #ata #riven Testing. It "as G types of usage . a. !ntering test data directly into data table and use b. Importing test data from external .lat files c. Importing test data from external Spread s"eets d. Importing test data from #ata bases. a7 &ntering test data directly into data ta#le and use7 )teps8 i= Generate t"e basic testLopen data table<+iewL#ata Table=

ii= (lick on column "eaderLenter t"e name of t"e field <like t"is we can create number of columns= L !nter #ataLconnect t"e data to test <variableOdatatable<Tcolumn nameU, S"eet id= !xampleB agentOdatatable<TagentU,C= Pass parameters.= iii= un t"e test.

&,ample8 $gent O #atatable<N$gentN,C= pwdO#atatable <NPasswordN,C= Invokeapplication N(BPProgram .ilesP)ercury InteractivePQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN #ialog<N7oginN=.$ctivate #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set $gent #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Type micTab #ialog<N7oginN=.0in!dit<NPasswordBN=.SetSecure pwd #ialog<N7oginN=.0in,utton<N&?N=.(lick 0indow<N.lig"t eservationN=.(lose

#7 %mporting test data from e,ternal files8 &pen #ata Table <viewL#ata table=Lplace mouse pointer on data table and rig"t clickLfileLimport from fileL(lick okL,rowsw pat" of t"e file<it imports data from t"e flat file= (onnecting Test #ata to QTP Test as above and run t"e test. c7 %mporting test data from e,ternal )pread s!eets8 &pen #ata Table <viewL#ata table=Lplace mouse pointer on data table and rig"t clickLfileLimport from fileL(lick okL,rowse pat" of t"e excel s"eet <it imports data from t"e excel s"eet=

(onnecting Test #ata to QTP Test as above and run t"e test. d7 %mporting test data from ata #ases8

T"roug" #ata table we can import Test #ata from #ata bases, but first we "ave to create Aget t"e #S8<#ata source 8ame=6 we "ave to use SQ7 (ommands. i=. (reating a Test #atabaseB open )S $ccess <or we can use any ot"er database=. ii= Start programsL)S &fficeL)S $ccessLfile LnewLSelect blank #atabaseLenter name of t"e databaseLSave wit" mdb extension. iii= (reating TablesB Select (reate table in design viewL!nter field name<$gent=and Select data type<text= 7ike t"is we can create number of fieldsLsave6enter table name. iv= !ntering #ata into TablesB Select tableLenter t"e data. v= (reating #S8 6 importing data 2avigation8 viewLdata tableLPlace mouse pointer on #ata tableLs"eetLimportLfrom database<#atabase 4uery wi%ard opens=Lc"oose Yspecify SQ7 statements manuallyLclick next Lclick createLclick newLselect driver typeLclick next Lbrowse pat" to storeL enter #S8 8ameL(lick SaveLclick nextLclick finis"LselectLbrowse t"e database6 selectLclick okLclick okLselect #S8Lclick okLenter SQ7 statement <select *from login=Lclick finis". 2ote8 #S8 (reation is one time activity, by using t"e #S8 we can get data for number of tests. @7 *etc!ing Test ata directly from *lat files

#im fso, myfile Set fsoOcreateob'ect<Nscripting.filesystemob'ectN= Set myfileOfso.opentextfile<NdBPtrigun.txtN,C= myfile.skipline 0"ile myfile.atendofline ZL true

xOmyfile.readline SOsplit<x,N[N= System/til. un N(BPProgram .ilesP)ercury InteractivePQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN,NN,N(BPProgram .ilesP)ercury InteractivePQuickTest ProfessionalPsamplesPflig"tPappPN,NopenN #ialog<N7oginN=.$ctivate #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set s<;= #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Type micTab #ialog<N7oginN=.0in!dit<NPasswordBN=.SetSecure S<C= #ialog<N7oginN=.0in!dit<NPasswordBN=.Type mic eturn 0indow<N.lig"t eservationN=.(lose 0end *etc!ing Test *etc!ing Test ata directly from &,cel )!eets ata directly from ata#ases

&ption explicit #im con,rs Set conOcreateob'ect<Nadodb.connectionN= Set rsOcreateob'ect<Nadodb.recordsetN= con.providerO<Nmicrosoft.'et.oledb.I.;N= con.open N(BP#ocuments and SettingsPpoo'aP)y #ocumentsPtrigun.mdbN rs.open Nselect * from loginN,con do until rs.eofOtrue System/til. un N(BPProgram .ilesP)ercury InteractivePQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN,NN,N(BPProgram .ilesP)ercury InteractivePQuickTest ProfessionalPsamplesPflig"tPappPN,NopenN #ialog<N7oginN=.$ctivate #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set rs.fields <NagentN= #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Type micTab #ialog<N7oginN=.0in!dit<NPasswordBN=.SetSecure rs.fields<NpasswordN= #ialog<N7oginN=.0in!dit<NPasswordBN=.Type mic eturn 0indow<N.lig"t eservationN=.(lose rs.movenext loop -------------------------------------0sing ictionary "#$ect for Parameteri(ation

Set inputdataO(reate&b'ect<NScripting.#ictionaryN= inputdata.$dd N$gentN,NgcreddyN inputdata.$dd NPasswordN,NmercuryN System/til. un N(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN #ialog<N7oginN=.$ctivate #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set inputdata<N$gentN= #ialog<N7oginN=.0in!dit<NPasswordBN=.Set inputdata<NPasswordN= #ialog<N7oginN=.0in,utton<N&?N=.(lick

(ynchroni'ation

It is a process of matc"ing t"e speeds of bot" QTP and $/T in order to get proper execution and results. 1!ere )ync!roni(ation is reGuired8 #uring test execution QTP gives instructions one by one wit" same speed, but $/T takes less time for some operations execution and more time for some operations execution, t"at time we may not get proper execution and results. In order to get proper results inbetween QTP 6 $/T sync"roni%ation is re4uired. T"ere are several met"ods available in QTP for sync"roni%ation. C. :. G. I. D. Inserting 0ait statements. Inserting Sync"roni%ation points. Increasing Tool default sync"roni%ation time. Sync )et"od <&nly for 0!,= !xist Property

%nserting 1ait )tatements8 0e can insert wait statements in our test in order to make QTP to wait until $/T completes current operation. SyntaxB 0ait<time in seconds= 2ote8 If we insert wait statements QTP waits up to maximum time even t"oug" operation is completed. %nserting )ync!roni(ation points8

Place cursor in desired locationLkeep tool under recording modeLInsert menuLSync"roni%ation point Ls"ow t"e ob'ect Lclick okLselect property name 6 +alue<True=Lenter time in )illi secondsLclick okLStop recording. 2ote8 if we insert Sync"roni%ation points, it does not wait up to maximum time, after completion of t"e current operations, it goes to next step immediately. SyntaxB ob'ect "ierarc"y.waitproperty Tproperty nameU,value,time in milli seconds. %ncreasing Tool default sync!roni(ation time8 8avigationB .ileLsettingsLrun tabLincrease ob'ect sync"roni%ation time outLapplyLok 8oteB If we increase QTP tool default time t"at can be applied for all statements in t"e test, but QTP does not wait up to maximum time unnecessarily, $fter completion of one statement execution it goes to next statement immediately. )ync Met!od8 <only for 0!,= 0aits for t"e browser to complete current navigation. SyntaxB &b'ect 1irearc"y.Sync !xB ,rowser<NVa"ooW ToolbarN=.Page<NVa"ooW ToolbarN=.Sync )electing an appropriate Met!od8 C. Suppose in our test one or more statements only are taking more time for execution t"en selecting TInserting sync"roni%ation met"odU is better. :. Suppose in our test more statements are taking more time for execution t"en selecting Tincreasing tool time outU . G. $bove two are local features but wait statement is +bscript feature, even t"oug" some drawbacks are t"ere in using wait statement, it is better to use wait statement in functions.
Advantages of 1ait )tatement8 C= It is a +,Script statement, we can use t"is globally

:= It is recommended, w"enever we want to observe t"e Test !xecution process G= 8o ob'ect reference re4uired to insert wait statements I= It is useful to make QTP capture values and screen s"ots during test execution

%nserting Transaction Points


QTP is providing a /tility ob'ect called )ervices for measuring transaction time Suppose, we want to measure "ow muc" time t"at one test or part of t"e test is taking for executionArunning, we can measure using t"ese transaction point <Start and !nd= )ynta,8 Services.StartTransaction TTransaction 8ameU Statements -----------Services.!ndTransaction TTransaction 8ameU 8oteB t"ese options <Start and !nd Transactions= available in QTP tool Insert menu &,ample8 services.StartTransaction N7oginN System/til. un N(BPProgram .ilesP)ercury InteractivePQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN,NN,N(BPProgram .ilesP)ercury InteractivePQuickTest ProfessionalPsamplesPflig"tPappPN,NopenN #ialog<N7oginN=.$ctivate #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set NnagaN #ialog<N7oginN=.0in!dit<NPasswordBN=.SetSecure NIbafD;fCHb;ae;dDfDI:Dfe>E;EDGeJEdaD;bde>N #ialog<N7oginN=.0in,utton<N&?N=.(lick 0indow<N.lig"t eservationN=.$ctivate services.!ndTransaction N7oginN 8oteB 0e can insert number of transaction points in a test

0sing Timer *unction )Ti%er* is a +B (cri!t Built-in #unction, that can be used #or %easuring transaction ti%e.
STOTimerM It returns elapsed time since C:B;; $) )id nig"t in seconds &,ample8 System/til. un N(BPProgram .ilesP)ercury InteractivePQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN,NN,N(BPProgram .ilesP)ercury

InteractivePQuickTest ProfessionalPsamplesPflig"tPappPN,NopenN #ialog<N7oginN=.$ctivate #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set NnagaN #ialog<N7oginN=.0in!dit<NPasswordBN=.SetSecure NIbafD;fCHb;ae;dDfDI:Dfe>E;EDGeJEdaD;bde>N #ialog<N7oginN=.0in,utton<N&?N=.(lick 0indow<N.lig"t eservationN=.$ctivate !TOTimer TTO!T-ST msgbox TT

2ote8 "ere ST, !T and TT are variables, you can take any variable, I usedB ST for Start Transaction !T for !nd transaction TT for Transaction Time

)tep Generator D*C>


)tep Generator is a feature of QTP, 7ibrary of .unctions, used for generating t"e ecordable and 8on- ecordable steps. 8avigationB Insert menu-LStep Generator &r /se S"ortcut key .> T"e Step Generator enables us to add steps by selecting from a range of context-sensitive options and entering t"e re4uired values. In t"e Step Generatordialog box we can define steps t"at useB Test ob'ect operations <tests only= /tility ob'ect operations (alls to library functions <tests only=, +,Script functions, and internal script functions .or example, we can add a step t"at c"ecks t"at an ob'ect exists, or t"at stores t"e returned value of a met"od as an output value or as part of a conditionalstatement. 0e can parameteri%e any of t"e values in our step. 8oteB we can use t"e Step Generator to insert steps in tests and function libraries. 1over, in function libraries, we cannot use t"e Step Generator to access test ob'ect names or collections, or to access t"e list of library functions.

,efore we open t"e Step Generator to define a new step, we first select w"ere inour test t"e new step s"ould be inserted. $fter we open t"e Step Generator, we first select t"e category for t"e step operation <test ob'ect, /tility ob'ect or function= and t"e re4uired ob'ect or t"e function library. 0e can t"en select t"e appropriate operation <met"od, property, or function= and define t"e arguments and return values, parameteri%ing t"em if re4uired. T"e Step Generator t"en inserts a step wit" t"e correct syntax into y test. 0e can continue to add furt"er steps at t"e same location wit"out closing t"e StepGenerator. 0e can open t"e Step Generator from t"e ?eyword +iew, !xpert +iew, or $ctive Screen.

e#ugging Tests
#ebugging is a process of executing t"e script or a program in a /ser designed fas"ion wit" some temporary break points in order to identify t"e errors. .or debugging, QTP is providing debug commands and breakpoints. #ebug (ommandsB

:> )tep %nto Ds!ort cut 'ey *::>8


a. b. It starts execution It executes one statement at a time.

c. If it is function call, it opens t"e function, after t"at it executes one statement at a time.

=> )tep "ver D)!ort cut 'ey *:;>8

a= It executes one statement at a time after execution starts b= It executes all functions statements at a time 2ote8 $fter opening t"e function, if we use step over it executes one statement at a time only.

?> )tep "ut Ds!ift H*::>8


It executes all remaining statements in a function at a time. !xB #im a,b,c aOC;; bO:;; cOaQb msgbox c msgbox N"elloN (all "yderabad msgbox Nbye byeN 2ote8 (reate a script and work on it

Brea' Point8
T"is feature is used for breaking t"e execution temporarily. 2avigation8 Place cursor in desired location L#ebug menuLInsertA emove break point &r /se s"ort cut key D*F> &r Place mouse pointer before t"e statement and click. 8oteB If we want to execute Some part of t"e Test Script at a time and some ot"er part of t"e test script step by step, t"ere we can use breakpoints.

e#ug viewer Pane8


It is used for viewing, modifying or setting t"e value of t"e variables during t"e execution break wit" t"e "elp of G Tabs. C. :. 0atc" +ariables

G.

(ommand

8oteB T"roug" #ebug +iewer Pane, 0e can watc" variables w"et"er t"e variables aretaking correct values or not at a specific point of time. 0e can c"ange +alues of +ariables temporarily. !x B #im x,y,% xOC; yO:; %OxQy msgbox % msgbox N1elloN xOGD yOE> %Ox*y msgbox % msgbox Nbye byeN 8avigationB +iew menu L #ebug +iewer L /se step into feature.

-naly'ing Test Results . Re!orting


$naly%ing t"e Test esult is not a responsibility of QTP. $fter unning Tests, /ser <Test !ngineer= "as to analy%e t"e test result. and send defect reports. QTP Result 1indow8 $fter unningA!xecuting a test, t"en QTP Provide result window. we export test result from result window in #ocument <.#oc=, 1T)7, @)7 and P#. formats. 8oteB QTP doen3t provide batc" wise test result, if we execute test batc"es. It provides test wise result only. )tatus of t!e Result8 QTP "as I types of result status a= Pass b= .ail

c= #one d= 0arning efining our own Result8 Generally QTP provides, test results, if we use 4tp tool features like c"eckpoints. suppose if we use flow control statements <conditional and 7oop statements=, t"en we "ave to define our own result. .or defining our own results, QTP is providing an utility ob'ect called NReporterN by using reporter, we can define our own results. SyntaxB eporter. eport!vent status of t"e !xampleN eporter. eport!vent micPass,N esN,N7ogin operation SuccessfulN exaplanationB eporter- /tility ob'ect eport!vent-)et"od micPass-Status of t"e esult. es- esult step N7ogin operation SuccessfulN- )essage )tatus of t!e Result8 C= Pass -micPass or ; := .ail -micPass or C G= #one- mic#one or : I= 0arning- mic#one or G esult,N esult StepN,NmessageN

Re!orting De#ects

QTP is an &b'ect based Test tool. 0e can create and execute tests using QTP. QTP Provides, various met"ods for crating and en"ancing Tests. $fter unning Tests, QTP provides result in esult window and also provides a facility to define our own esults. esult !xporting facility also available in QTP esult window.

$ny "ow $naly%ing running tests.

esults is t"e

esponsibility of Test !ngineer after

$fter analy%ing results, we can report defects in various met"ods. If we are using QTP for .unctional Test $utomation and #efect managementmanual, t"en entering defect details in company prescribed format and sending. If we are using ,ug%illa or \era or P -Tracker like ,ug Tracking tool, t"en after analy%ing results, if we find any mismatc"es sending defects t"roug" t"e ,ug tracking tool <!very ,ug Tracking tool "as its own defect report template= If we are using Quality center for Test management, t"en we can send defects directly from QTP result window. In between QTP and Quality (enter back to back integration is available.

-ctions
Action: (et o# (tate%ents #or !er#o%ing a Tas&/s0 1e divide our test into actions to strea%line the !rocess o# testing. Pur!ose o# -ctions2 For understandability For reusing co%!onents Types of Actions: 30 4on Re usable actions 50 Re usable actions 60 78ternal actions Operations on Actions: 9 $reating -ctions 9 (!litting -ctions 9 Rena%ing -ctions 9 Deleting -ctions 9 $alling an -ction

9 $o!ying an -ction 9 Ma&ing an -ction Reusable:4on Reusable Creating an Action: "nsert;call to new action;enter na%e o# the action;clic& o& (te!s2 3. $reate re<uired actions/e8 login, insert,delte0 5. Pre!are (cri!ts #or those actions. Splitting an action: 4avigation2 Place cursor in desired location;7dit %enu;action;s!lit action;7nter -ction 3 na%e . action 5 na%e. (te!s2 3. =enerate total test in the de#ault action 5. (!lit into %eaning#ul actions. 4ote2 -t a ti%e we can s!lit one actions into 5 actions. Renaming actions: (elect desired action in action dro! down bo8; edit %enu;action;rena%e action;%odi#y the na%e;clic& o&. Deleting Actions: (elect desired action in action dro! down bo8;edit %enu;action;delete action;con#ir% deletion. Calling an action: "nsert;call to e8isting action;browse !ath o# the test;select desired action;clic& o&. 4ote2 > can*t edit Copying an action2 "nsert;call to co!y o# action;browse !ath o# the test;select desired action;clic& o&. 4ote2 we can edit this action. Making an action reusable: (elect 4on Reusable action ;edit ;action;action !ro!erties;chec& reusable action chec& bo8 ;clic& o&.

+B (cri!t (tring Functions

)tring *unctions

:> 4eft *unction eturns a specified number of c"arectors of a given string from left side SyntaxB variableO7eft<string,7eng"= !xampleB #im val,x valON1yderabadN xO7eft<val,G= msgbox x 3 &utputB 1yd valONJ:I>HG>I>HN xO7eft<val,C= msgbox x 3 &utputB J valON1J:yderabadN xO7eft<val,G= msgbox x 3 &utputB 1J: xO7eft<J:I>HG>I>H,D= msgbox x 3 &utputB J:I>H valO]C;-C;-C;] xO7eft<val,G= msgbox x 3 &utputB C;A => Rig!t *unction eturns a specified number of c"arectors of a given string from side !xampleB #im val,x valON1yderabadN xO ig"t<val,G= ig"t

msgbox x 3 &utputB bad valONJ:I>HG>I>HN xO ig"t<val,C= msgbox x 3 &utputB H valON1J:yderabadN xO ig"t<val,G= msgbox x 3 &utputB bad xO ig"t<J:I>HG>I>H,D= msgbox x 3 &utputB G>I>H valO]C;-C;-C;] xO ig"t<val,D= msgbox x 3 &utputB A:;C; ?> Mid function eturns a specified number of c"arectors of a given string !xampleB #im val,x valON1yderabadN xO)id<+al,D,G= msgbox x 3 &utputB rab valON1yderabadN xO)id<+al,D= msgbox x 3 &utputB rabad valONJ:I>HG>I>HN xO)id<val,E,D= msgbox x 3 &utputB G>I>H valON1J:yderabadN xO)id<val,C= msgbox x 3 &utputB 1J:yderabad

xO)id<J:I>HG>I>H,D= msgbox x 3 &utputB HG>I>H valO]C;-C;-C;] xO)id<val,D= msgbox x 3 &utputB ;A:;C; @> )trReverse retuns reverse value of a string !xampleB #im val,x valON1yderabadN xOStr everse<val= msgbox x 3&utput dabaredy1 valON;;CN xOStr everse<val= msgbox x 3&utputB C;; valOC;;: xOStr everse<val= msgbox x 3&utputB :;;C valO]C;-C;-C;] xOStr everse<val= msgbox x 3&utputB ;C;:A;CA;C xOStr everse<N1yderabadN= msgbox x 3&utputB dabaredy1 xOStr everse<C;;= msgbox x 3&utputB ;;C A> )trComp *unction It compares two string <,inary and textual= if a= ,ot" are e4ual, returns ;<%ero=

b= String C greater t"an string :, returns C<one= b= String : greater t"an string C, returns -C !xampleB #im strC,str:,x strCONIndiaN str:ONIndiaN xOStr(omp<strC,str:,C= msgbox x 3&utput ; strCONindiaN str:ONI8#I$N xOStr(omp<strC,str:,C= msgbox x 3&utput ; strCONIndiaN str:ONIndianN xOStr(omp<strC,str:,C= msgbox x 3&utput -C strCONIndianN str:ON8diaN xOStr(omp<strC,str:,C= msgbox x 3&utput -C strCONIndianN str:ONIndiaN xOStr(omp<strC,str:,C= msgbox x 3&utput C strCOC;; str:OC;; xOStr(omp<strC,str:,C= msgbox x 3&utput ; strCOC;; str:OC;C xOStr(omp<strC,str:,C= msgbox x 3&utput -C B> 4case function

(overts /pper case values into 7ower case #im val,x valON1V#! $,$#N xO7case<val= msgbox x 3&utput "yderabad valON1yderabadN xO7case<val= msgbox x 3&utput "yderabad valON1ederaba#N xO7case<val= msgbox x 3&utput "yderabad valON"yderabadN xO7case<val= msgbox x 3&utput "yderabad xO7case<N1V#! $,$#N= msgbox x 3&utput "yderabad C> 0case function (overts 7ower case values into /pper case !xampleB #im val,x valON1V#! $,$#N xO/case<val= msgbox x 3&utput 1V#! $,$# valON1yderabadN xO/case<val= msgbox x 3&utput 1V#! $,$# valON1ederaba#N xO/case<val= msgbox x 3&utput 1V#! $,$# valON"yderabadN

xO/case<val= msgbox x 3&utput 1V#! $,$# xO/case<N1V#! $,$#N= msgbox x 3&utput 1V#! $,$# E> 4BoundI 0Bound *unctions
!xampleB #im x<G=, y<I,D= )sgbox 7bound<x= 3; )sgbox /,ound<x=3G 2Find si3e of the Arra" )sgbox /,ound<x=QC )sgbox 7bound<y,C= 3; )sgbox 7bound<y,:= 3; )sgbox /,ound<y,C= 3I )sgbox /,ound<y,:= 3D

&nvironment .aria#les in QTP


T"ese are global variables5 if you want to use some variables globally <.romnumber of tests= declaring as global variables is better. If we declare as local variables in number of tests, modifications are difficult.

Types of &nvironment varia#les8 C. Built in varia#les8 T"ese are system defined variables, we can access from all tests but t"ese are designed as read only. :. 0ser defined varia#les8 +ariables t"at we predefine in t"e active external environment variables file. 0e can create as many files as we want and we can c"ange values of variables. 0sage of environment varia#les8 SyntaxB +ariable O !nvironment<Tenvironment variable nameU= !xB @O!nvironment <T$ction8ameU= )sgbox x &,ample )cript8 Product#ir Oenvironment <NProduct#irN= appO NPsamplesPflig"tPappPflig"tIa.exeN Systemutil. un Product#ir 6 app #ialog<N7oginN=.$ctivate #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set Nka'alN #ialog<N7oginN=.0in!dit<NPasswordBN=.SetSecure NIbGcHEf:C;>ffDEDccCJDbaEc:I>GJ;JCbEDEI;>N #ialog<N7oginN=.0in,utton<N&?N=.(lick Creating user defined environment varia#les8 8avigationB .ile L settings L !nvironment L select variable type as user defined L click addicon <Q= L enter variable name 6 +alue L click ok <like t"is we can create numberof variables= L click export L browse pat" 6 enter file name, save wit" xml extension L click ok. Associating environment varia#le file8 8avigationB

.ile L settings L!nvironment L select variable type as user defined L c"eck Tload variables and values from t"e external fileU L browse pat" of t"e xml file L click apply 6 ok. &r 1e can load environment file directly !nvironment.loadfromfileUpat" of t"e xml fileU 0sage of user defined &nvironment varia#les8 $ssociate environment file to current testB +ariable O !nvironment <T+ariable 8ameU= @Oenvironment <TcityU= )sgbox x Modifying &nvironment files8 Select @)7 fileLopen wit" notepadLmodify t"e valuesLSave.

Regular &,pressions in QTP


1!at is Regular &,pressionJ It is a way of representing data using symbols. T"ey are often used wit"in matc"ing, searc"ing or replacing algorit"ms. Regular &,pressions in QTP8 egular expressions can be used in QTP for identifying ob'ects and text strings wit" varying values. 1!ere we use8 o #efining t"e property values of an ob'ect in #escriptive programming for "andling dynamic ob'ects o .or parameteri%ing a step o creating c"eckpoints wit" varying values 0sing Regular &,pressions in QTP8

0e can define a regular expression for a constant value, a #ata Table parameter value, an !nvironment parameter value, or a property value in #escriptive programming. 0e can define a regular expression in standard c"eckpoint to verify t"e property values of an ob'ect5 we can set t"e expected value of an ob'ect3s property as aregular expression so t"at an ob'ect wit" a varying value can be verified. 0e can define t"e text string as a regular expression, w"en creating a text c"eckpoint to c"eck t"at a varying text string is displayed on our application, .or @)7 c"eckpoints we can set attribute or element values as regular expressions. 1ays of Regular &,pressions8 a> Bac'slas! C!aracter8 $ backslas" <P= can serve two purposes. It can be used in con'unction wit" a special c"aracter to indicate t"at t"e next c"aracter be treated as a literal c"aracter. $lternatively, if t"e backslas" <P= is used in con'unction wit" some c"aracters t"at would ot"erwise be treated as literal c"aracters, suc" as t"e letters n, t, w, or d, t"e combination indicates a special c"aracter. #> Matc!ing Any )ingle C!aracter8 $ period <.= instructs QTP to searc" for any single c"aracter <except for Pn=. !xB welcome. )atc"es welcomes, welcomed, or welcome followed by a space or any ot"er single c"aracter. c> Matc!ing Any )ingle C!aracter in a 4ist8 S4uare brackets instruct QTP to searc" for any single c"aracter wit"in a list of c"aracters. !xB To searc" for t"e date CHE>, CHEH, or CHEJ, enterB

CHE^>HJ_ d> Matc!ing Any )ingle C!aracter 2ot in a 4ist8 0"en a caret <`= is t"e first c"aracter inside s4uare brackets, it instructs QTP to matc" any c"aracter in t"e list except for t"e ones specified in t"e string. !xampleB ^`ab_ )atc"es any c"aracter except a or b. e> Matc!ing Any )ingle C!aracter wit!in a Range8 To matc" a single c"aracter wit"in a range, we can use s4uare brackets <^ _= wit" t"e "yp"en <-= c"aracter. !xampleB .or matc"ing any year in t"e :;C;s, enterB :;C^;-J_ f> Matc!ing Kero or More )pecific C!aracters8 $n asterisk <*= instructs QTP to matc" %ero or more occurrences of t"e preceding c"aracter. .or exampleB ca*r )atc"es car, caaaaaar, and cr g> Matc!ing "ne or More )pecific C!aracters8 $ plus sign <Q= instructs QTP to matc" one or more occurrences of t"e preceding c"aracter. .or exampleB caQr )atc"es car and caaaaaar, but not cr. !> Matc!ing Kero or "ne )pecific C!aracter8 $ 4uestion mark <a= instructs QTP to matc" %ero or one occurrences of t"e preceding c"aracter. .or exampleB

caar )atc"es car and cr, but not"ing else. i> Grouping Regular &,pressions8 Parent"eses <<== instruct QTP to treat t"e contained se4uence as a unit, 'ust as in mat"ematics and programming languages. /sing groups is especially useful for delimiting t"e argument<s= to an alternation operator < b = or a repetition operator < * , Q , a , c d =. $> Matc!ing "ne of )everal Regular &,pressions8 $ vertical line <b= instructs QTP to matc" one of a c"oice of expressions. '> Matc!ing t!e Beginning of a 4ine8 $ caret <`= instructs QTP to matc" t"e expression only at t"e start of a line, or after a newline c"aracter. l= )atc"ing t"e !nd of a 7ineB $ dollar sign <e= instructs QTP to matc" t"e expression only at t"e end of a line, or before a newline c"aracter. m> Matc!ing Any Alp!a2umeric C!aracter %ncluding t!e 0nderscore8 Pw instructs QTP to matc" any alp"anumeric c"aracter and t"e underscore <$-\, a-%, ;-J, X=. n> Matc!ing Any 2on-Alp!a2umeric C!aracter8 P0 instructs QTP to matc" any c"aracter ot"er t"an alp"anumeric c"aracters and underscores. o> Com#ining Regular &,pression "perators8 0e can combine regular expression operators in a single expression to ac"ieve t"e exact searc" criteria we need. .or example, start.* )atc"es start, started, starting, starter, and so fort". we can use a combination of brackets and an asterisk to limit t"e searc" to a combination of non-numeric c"aracters.

.or exampleB ^a-%$-\_* To matc" any number between ; and C:;;, we need to matc" numbers wit" C digit, : digits, G digits, or I digits between C;;;-C:;;. T"e regular expression below matc"es any number between ; and C:;;. <^;-J_a^;-J_a^;-J_bC^;C_^;-J_^;-J_bC:;;=

Reg&,p o#$ect
+, Script is providing eg!xp ob'ect for defining egular expressions, It provides simple support for defining regular expressions. egular !xpression &b'ect Properties and )et"odsB Properties8 a= Global Property b= Ignore(ase Property c= Pattern Property Met!ods8 a= !xecute )et"od b= eplace )et"od

c= Test )et"od

Regular &,pressions &,amples8


:> Matc! *ile 2ames in a irectory against Regular &,pression

Set ob'.S O (reate&b'ect<NScripting..ileSystem&b'ectN= Set ob'S"ell O (reate&b'ect<N0Script.S"ellN= str(urrent#irectory O ob'S"ell.(urrent#irectory Set ob'.older O ob'.S.Get.older<str(urrent#irectory= Set col.iles O ob'.older..iles Set ob' ! O 8ew eg!xp ob' !.Global O True

ob' !.Ignore(ase O .alse ob' !.Pattern O 0Script.$rguments<;= .or !ac" ob'.ile In col.iles b)atc" O ob' !.Test<ob'.ile.8ame= If b)atc" T"en 0Script.!c"o ob'.ile.8ame !nd If 8ext => Matc! Content in a *ile against a Regular &,pression str.ile8ame O N!BPgcreddy.txtN Set ob'.S O (reate&b'ect<NScripting..ileSystem&b'ectN= Set ob'TS O ob'.S.&penText.ile<str.ile8ame= str.ile(ontents O ob'TS. ead$ll 0Script.!c"o NSearc"ing 0it"inB N 0Script.!c"o str.ile(ontents ob'TS.(lose Set ob' ob' ob' ob' ! O 8ew eg!xp !.Global O True !.Ignore(ase O .alse !.Pattern O 0Script.$rguments<;=

Set col)atc"es O ob' !.!xecute<str.ile(ontents= 0Script.!c"o vb8ew7ine 6 N esulting )atc"esBN .or !ac" ob')atc" In col)atc"es 0Script.!c"o N$t position N 6 ob')atc"..irstIndex 6 N matc"ed N 6 ob')atc".+alue 8ext

Virtual Object Configuration


.irtual "#$ect Configuration8
+irtual &b'ect (onfiguration is a process of making t"e QTP to treat a specified area or a user defined ob'ect as +irtual &b'ect. +irtual ob'ects enable us to create and run tests on ob'ects t"at are not normally recogni%ed by QTP.

0e can manage t"e virtual ob'ects defined on our computer using t"e +irtual &b'ect )anager.

2avigation8
o o Select Tools )enu Go to +irtual ob'ects Select Y8ew +irtual &b'ectM option (lick 8ext )ark t"e area in t"e $pplication wit" "elp of mark ob'ect button (lick next Select one of t"e following options !ntire Parent "ierarc"y Parent only (lick on 8ext Specify t"e #esired ob'ect name Specify t"e #esired collection name (lick finis"

.irtual "#$ect Manager8 +irtual ob'ect )anager feature enable us to create and manage +irtual &b'ects

Batc! Testing or Batc! &,ecution


!xecuting a group of Tests or series of tests at a time is known as ,atc" Testing or ,atc" !xecution. .or performing ,atc" Testing, QTP is providing a separate Tool called Test ,atc" unner. )teps for Batc! Testing8 C=. (reate Individual Tests and :=. &pen 3Test batc" un once.

unner3 Tool and .orm ,atc"es. unner3 to run tests unner.

G= Provide permission to 3Test batc" I=.

un or !xecute Test ,atc"es from Test ,atc" esult in 3Test esult +iewer3.

D= +iew Test wise

2ote8 QTP doesnMt provide ,atc" wise result. *orming a Test Batc!8 4aunc! Test Batc! Runner7 8avigationB StartLprogramL4uicktest professionalLToolsLTest ,atc" unnerL.ileLnewLbatc"LaddLbrowse pat" of t"e test <like t"is add number of tests=Lsave wit" )T, extension <)odule test batc"e=Lclose test batc" runner. Running or &,ecuting a Test Batc! &pen Test ,atc" unner Tool

8avigationB .ileLopenLbrowse pat" of t"e test batc"Lbatc"Lrun 8oteB Test ,atc" unner launc"es QTP Tool, QTP runs Tests one by one. un Tests.

8oteB $llowing ot"er products to

8avigationB ToolsL&ptionsL unLc"eck allow ot"er mercury productsLapply 6 &k &,ecuting partial Test Batc! &pen Test ,atc" test batc". unner Lopen Test ,atc"LSelect or deselect testsLrun

Recovery )cenario Manager To recover from unexpected events and errors t"at are occurred in t"e test environment during run session, we can use ecovery Scenario )anager. .or good recovery, error must be known t"e occurrence is unknown. T!ere are D@> Types of events suc! as8 Di> Application Cras! $n open application fails during Test 2avigation8 un.

esources )enu -L ecovery Scenario )anager- L (lick 8ew- L (lick 8ext - L Select $pplication (ras" as Trigger event-L8ext - LSelect selected executable application-L8ext -LSelect ecovery &peration ^?eyboard, )ouse &peration, (lose $pplication Process, function (all, estart, )icrosoft 0indows_ -L8ext - LIf you want to c"eck $dd anot"er operation else unc"eck-L8ext - L8ext - L!nter Scenario 8ame -L8ext- LSelect &ption - L.inis" - L(lose - LSave t"e scenario in specified location wit" T.4rsU <4rs stands for QuickTest ecovery Scenario.= Dii> Popup 1indow7 To "andle unwanted popups. 2avigation8 esources )enu -L ecovery Scenario )anager -L8ew - L8ext - LSelect TPopup 0indowU as Trigger event -L8ext - L(lick on 1and Icon - LS"ow unwanted window wit" 1and icon -L8ext - L8ext - LSelect function call as ecovery &peration -L8ext ^&pen 8otepad - LSave empty file wit" .vbs extension_ - L,rowse t"e .vbs fie pat" -L8ext - L/nc"eck $dd anot"er ecovery &peration - L8ext - L Select Post- ecovery Test un &ption ^ epeat current step and continue, Proceed to 8ext step, Proceed to 8ext $ction, Proceed to next test iteration, estart current test run, Stop t"e Test un_ -L8ext - L!nter Scenario 8ame -L8ext - LSelect &ption - L .inis" -LSave t"e scenario wit" T.4rsU -L ecord re4uired ecovery &peration ^(lick ok, (lick (ancel_ take t"e script into function -LSave t"e library file -L(lick un Diii> Test Run &rror7

$ step in your test does not run successfully t"en Test can be raised. 2avigation 8

un !rror

esources )enu -L ecovery Scenario )anager - L8ew - L8ext - LSelect TTestrunerror 0indowU as Trigger event -L8ext -Lselect any error o - L8ext - L8ext - LSelect function call as ecovery &peration -L8ext ^&pen 8otepad - LSave empty file wit" .vbs extension_ -L,rowse t"e .vbs fie pat" -L8ext - L/nc"eck $dd anot"er ecovery &peration - L8ext -L Select Post- ecovery Test un &ption ^ epeat current step and continue, Proceed to 8ext step, Proceed to 8ext $ction, Proceed to next test iteration, estart current test Select &ption 8ext !nter Scenario 8ame 8ext run, Stop t"e Test un_ ecord re4uired ecovery &peration ^(lick Save t"e scenario wit" T.4rsU .inis" (lick un Save t"e library file ok, (lick (ancel_ take t"e script into function Div> "#$ect )tate7 T"e property values of an ob'ect in your application matc" specified values. Vou can specify property values for eac" ob'ect in t"e "ierarc"y. 2avigation8 esources )enu -L ecovery Scenario )anager -L 8ew -L 8ext -L Select T&b'ect state 0indowU as Trigger event -L 8ext -L (lick on 1and Icon -L S"ow ob'ect wit" "and icon -L 8ext -L 8ext-Lselect ob'ect property wit" value <enabled ,false=Lclick next -L Select function call as ecovery &peration -L 8ext ^&pen 8otepad -L Save empty file wit" .vbs extension_ -L ,rowse t"e .vbs fie pat" -L 8ext -L /nc"eck $dd anot"er ecovery &peration -L 8ext -L

Select Post- ecovery Test un &ption ^ epeat current step and continue, Proceed to 8ext step, Proceed to 8ext $ction, Proceed to next test iteration, estart current test run, Stop t"e Test un_ -L 8ext-L !nter Scenario 8ame -L 8ext -L Select &ption -L .inis" -L Save t"e scenario wit" T.4rsU -L ecord re4uired ecovery &peration ^(lick ok, (lick (ancel_ take t"e script into function -L Save t"e library file -L (lick un

*ile )ystem "perations


*ile )ystem8 Its an operating system feature, it allows users to create, modify, view and delete5 drives,folders and files +, Script is providing an ob'ect called scripting.filesystemob'ect and some met"ods for performing file systems operations *ile )ystem "#$ect Model8 T"e .ile System &b'ect <.S&= model provides an ob'ect-based tool for working wit" folders and files. It allows us to use t"e familiar ob'ect.met"od syntax wit" a ric" set of properties, met"ods, and events to process folders and files. 0e can also employ t"e traditional +isual ,asic statements and commands. T"e .S& model gives our application t"e ability to create, alter, move, and delete folders, or to determine if and w"ere particular folders exist. It also enables us to get information about folders, suc" as t"eir names and t"e date t"ey were created or last modified. T"e .S& model makes processing files muc" easier as well. 0"en processing files, our primary goal is to store data in an efficient, easy-toaccess format. 0e need to be able to create files, insert and c"ange t"e data, and output <read= t"e data. $lt"oug" we can store data in a database, doing so adds a significant amount of over"ead to our application. 0e may not want to "ave suc" over"ead, or our data access re4uirements may not call for t"e extra functionality associated wit" a

full-featured database. In t"is case, storing our data in a text file or binary file is t"e most efficient solution. T"e .S& model, contained in t"e Scripting type library <Scrrun.dll=, supports t"e creation and manipulation of text files t"roug" t"e TextStream ob'ect5 "owever, t"e .S& model does not support binary files. To manipulate binary files, use t"e .ile&pen .unction wit" t"e ,inary keyword. &,amples8 :> Create a folder #im fso, str.older str.olderON#BP#ocuments and SettingsPgcreddyP#esktopP#ibyalokN Set fsoOcreateob'ect<Nscripting.filesystemob'ectN= fso.(reate.older<str.older=

=> Create a folder #im fso, str.older str.olderON#BP#ocuments and SettingsPgcreddyP#esktopP#ibyalokN Set fsoOcreateob'ect<Nscripting.filesystemob'ectN= If fso..older!xists<str.older= T"en msgbox N.older already existsN else fso.(reate.older<str.older= !nd If ?> ata file7 riven Testing #y fetc!ing Test data directly from a Te,t

3********************************************************* LTest ReGuirement8 #ata #riven Testing by .etc"ing Test data directly from a Text file. 3$ut"orB G ( eddy

L ate of Creation8 CG-;H-:;C; LPre-reGuisites8 3vinod.txt <Test #ata= LTest *low8

3(reating an $utomation &b'ect in .ileSystem class 3&pening t"e !xternal Test #ata file using t"e &b'ect 3 ead t"e #ata 6 Split t"e #ata 3Generating t"e 7ogin &peration 3Pass Parameters 3******************************************************** #im ob'.so, my.ile, my7ine, my.ield Set ob'.soO(reate&b'ect<NScripting..ileSystem&b'ectN= Set my.ileOob'.so.&penText.ile<N(BP#ocuments and SettingsPgcr.G( (J$C:.,#G#JP#esktopPvindod.txtN,C= 3C for ead, :-0rite 6 H-$ppend my.ile.Skip7ine #o /ntil my.ile.$t!nd&fStream my7ineOmy.ile. ead7ine my.ieldOSplit<my7ine,N,N= System/til. un N(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN #ialog<NtextBO7oginN=.$ctivate #ialog<NtextBO7oginN=.0in!dit<Nattac"ed textBO$gent 8ameBN=.Set my.ield<;= #ialog<NtextBO7oginN=.0in!dit<Nattac"ed textBOPasswordBN=.Set my.ield<C= wait : #ialog<NtextBO7oginN=.0in,utton<NtextBO&?N=.(lick 0indow<NtextBO.lig"t eservationN=.(lose 7oop my.ile.(lose Set ob'.soO8ot"ing for more !xamples visitB

*ile )ystem )cripts *lat *ile )cripts

Database connections
Database connection is a #acility in co%!uter science that allows client so#tware to co%%unicate with database server so#tware, whether on the sa%e %achine or not.

SQ Ser!er connection strings

(Q? ODB$ connection strings (tandard (ecurity2 @DriverAB(Q?(erverCD(erverAEourF(erverF4a%eDDatabaseAEourFDatabaseF4a%eD >idAEourF>serna%eDPwdAEourFPasswordD@ Trusted connection2 @DriverAB(Q?(erverCD(erverAEourF(erverF4a%eDDatabaseAEourFDatabaseF4a%eD TrustedF$onnectionAyesD@ (Q? O?7 DB connection strings (tandard (ecurity2 @ProviderA(Q?O?7DBDData (ourceAEourF(erverF4a%eD"nitial $atalogA EourFDatabaseF4a%eD>ser"dAEourF>serna%eDPasswordAEourFPasswordD@ Trusted connection2 @ProviderA(Q?O?7DBDData (ourceAEourF(erverF4a%eD"nitial$atalogAEourFDatab aseF4a%eD"ntegrated (ecurityA((P"D@ (Q? OleDb$onnection .47T strings (tandard (ecurity2 @ProviderA(Q?O?7DBDData (ourceAEourF(erverF4a%eD"nitial $atalogA EourFDatabaseF4a%eD>ser"dAEourF>serna%eDPasswordAEourFPasswordD@ Trusted connection2 @ProviderA(Q?O?7DBDData (ourceAEourF(erverF4a%eD"nitial$atalogAEourFDatab aseF4a%eD"ntegrated (ecurityA((P"D@ (Q? (<l$onnection .47T strings (tandard (ecurity2 3. @Data (ourceAEourF(erverF4a%eD"nitial $atalogA EourFDatabaseF4a%eD>ser"dAEourF>serna%eDPasswordAEourFPasswordD@ G br;5. @(erverAEourF(erverF4a%eDDatabaseAEourFDatabaseF4a%eD>ser"DAEourF>sern a%eDPasswordAEourFPasswordDTrustedF$onnectionAFalse@ Trusted connection2 3. @Data (ourceAEourF(erverF4a%eD"nitial $atalogAEourFDatabaseF4a%eD"ntegrated (ecurityA((P"D@

5.@(erverAEourF(erverF4a%eDDatabaseAEourFDatabaseF4a%eDTrustedF$onnecti onATrueD@ MS Access connection strings M( -ccess ODB$ connection strings (tandard (ecurity2 @DriverA BMicroso#t-ccessDriver/H.%db0CDDBQA$2I-!!3IEourFDatabaseF4a%e.%dbD>idAEou rF>serna%eDPwdAEourFPasswordD@ 1or&grou!2 @DriverABMicroso#t -ccess Driver /H.%db0CD Db<A$2I-!!3IEourFDatabaseF4a%e.%dbD (yste%DBA$2I-!!3IEourFDatabaseF4a%e.%dwD@ 78clusive @DriverABMicroso#t -ccess Driver /H.%db0CD DBQA$2I-!!3IEourFDatabaseF4a%e.%dbD 78clusiveA3D >idAEourF>serna%eD PwdAEourFPasswordD@ M( -ccess O?7 DB . OleDb$onnection /.47T #ra%ewor&0 connection strings O!en connection to -ccess database2 @ProviderAMicroso#t.Jet.O?7DB.K.LD Data (ourceAc2I-!!3IEourFDatabaseF4a%e.%dbD >ser "dAad%inD PasswordA@ O!en connection to -ccess database using 1or&grou! /(yste% database02 @ProviderAMicroso#t.Jet.O?7DB.K.LD Data (ourceAc2I-!!3IEourFDatabaseF4a%e.% dbD Jet O?7DB2(yste% DatabaseAc2I-!!3IEourF(yste%FDatabaseF4a%e.%dw@ O!en connection to !assword !rotected -ccess database2 @ProviderAMicroso#t.Jet.O?7DB.K.LD Data (ourceAc2I-!!3IEourFDatabaseF4a%e.%dbD Jet O?7DB2Database PasswordAEourFPassword@ O!en connection to -ccess database located on a networ& share2 @ProviderAMicroso#t.Jet.O?7DB.K.LD Data(ourceAII(erverF4a%eI(hareF4a%eI(har eFPathIEourFDatabaseF4a%e.%db@ O!en connection to -ccess database located on a re%ote server2 @ProviderAM( Re%oteD Re%ote (erverAhtt!2::Eour-Re%ote-(erver-"PD Re%ote ProviderAMicroso#t.Jet.O?7DB.K.LD Data (ourceAc2I-!!3IEourFDatabaseF4a%e.%db@

MySQ connection strings My(Q? ODB$ connection strings O!en connection to local My(Q? database using My(Q? ODB$ 6.M3 Driver @ProviderAM(D-(Q?D DR"+7RABMy(Q? ODB$ 6.M3DriverCD (7R+7RA localhostD D-T-B-(7AEourFMy(Q?FDatabaseD >"DA EourF>serna%eD P-((1ORDAEourFPasswordD OPT"O4A6@ My(Q? O?7 DB . OleDb$onnection /.47T #ra%ewor&0 connection strings O!en connection to My(Q? database2 @ProviderAMy(Q?ProvDData (ourceAEourFMy(Q?FDatabaseD>ser "dAEourF>serna%eD PasswordAEourFPasswordD@

Oracle connection strings Oracle ODB$ connection strings O!en connection to Oracle database using ODB$ @DriverA BMicroso#t ODB$#orOracleCD(erverAEourFOracleF(erver.worldD>idAEourF>serna%eDPwdAEour FPasswordD@ Oracle O?7 DB . OleDb$onnection /.47T #ra%ewor&0 connection strings O!en connection to Oracle database with standard security2 3. @ProviderAM(D-OR-DData (ourceA EourFOracleFDatabaseD>ser"dAEourF>serna%eDPasswordAEourFPasswordD@ 5. @ProviderA OraO?7DB.OracleDEourFOracleFDatabaseD>ser"dAEourF>serna%eDPasswordAEour FPasswordD@ O!en trusted connection to Oracle database @ProviderA OraO?7DB.OracleDData(ourceAEourFOracleFDatabaseDO(-uthentA3D@

A"M )cripting DAutomation "#$ect Model>


"#$ect Model8 $n ob'ect model is a structural representation of software ob'ects <classes= t"at comprise t"e implementation of a system or application. $n ob'ect model defines a set of classes and interfaces, toget"er wit" t"eir properties, met"ods and events, and t"eir relations"ips. 0e can use QTP $utomation ob'ect )odel to write scripts, t"at automate our QTP operations.

QTP $utomation ob'ect model provides ob'ects, met"ods and properties t"at enable us to control QTP from anot"er application. 0e can use Scripting languages or programming languages suc" as +,script, 2ava script or +(QQ, .8et for automating QTP operations.

!xampleB :> 1rite an A"M )cript to launc! QTP ToolI &,ecute Tests and to close t!e QTP Tool option explicit #im 4t$pp Set 4t$ppOcreateob'ect <NQuicktest.$pplicationN= 4t$pp.7aunc" 4t$pp.visibleOTrue 4t$pp.open N(BP#ocuments and SettingsPadminP)y #ocumentsPloginN 4t$pp.Test. un 4t$pp.Test.(lose 4t$pp.open N(BP#ocuments and SettingsPadminP)y #ocumentsPopen orderN 4t$pp.Test. un 4t$pp.Test.(lose 4t$pp.4uit Set 4t$ppO8ot"ing 8oteB $&) Script can be used in $utomation framework as an Initiali%ation script. 3-----------------------------------------------------------------=> 1rite an A"M script to e,ecute series of tests #im ob'.so,ob'Qtp,my.ile,i,gcreddy Set ob'Qtp O (reate&b'ect<NQuicktest.$pplicationN= ob'Qtp.+isible O True ob'Qtp.7aunc" Set ob'.so O(reate&b'ect<NScripting..ileSystem&b'ectN= Set my.ile O ob'.so.&penText.ile<N(BP/sersP("inniP#esktopPTestPgcreddy.txtN= i OC

#o /ntil my.ile.$t!nd&fStream OTrue testurl O my.ile. ead7ine ob'Qtp.&pen gcreddy ob'Qtp.Test. un ob'Qtp.Test.(lose i O iQC 7oop ob'Qtp.Quit Set ob'Qtp O 8ot"ing

ynamic !andling of o#$ect Repositories


7oading repositories during running, finding pat" of t"e repositories and removing repositories is called #ynamic 1andling of &b'ect epositories. /sing t"is feature we can increase QTP performance. To do t"is, QTP is providing an ob'ect called TRepositoriesCollectionU. )ynta, for 4oading a Repository8 epositories(ollection.$dd TPat" of t"e

epository .ileU

)ynta, for finding Position of t!e Repository8 +ariableO epositories(ollection..ind<TPat" of t"e epositoryU= )ynta, for Removing t!e Repository8 epositories(ollection. emove<position= )ynta, for Removing All Repositories8 epositories(ollection. emove$ll &,ample8 epPat"ON(BP#ocuments and SettingsP$dministratorP)y #ocumentsP7ogi n.tsrN epositories(ollection.$dd < epPat"= systemutil. un N(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN #ialog<N7oginN=.$ctivate #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set Nsud"akarN #ialog<N7oginN=.0in!dit<NPasswordBN=.Set NmercuryN #ialog<N7oginN=.0in,utton<N&?N=.(lick

posO epositories(ollection..ind< epPat"= epositories(ollection. emove<pos= epositories(ollection. emove$ll

QTP )cripting
QTP Tests in +, Script orientation provides a real-time approac" on Scripting. Itexplains .lat file scripts, !xcel Scripts, G/I Scripts, 0eb scripts, #atabase scripts and xml scripts wit" syntax and examples.

File (yste% (cri!ts


"# Create a $ol%er O!tion 78!licit Di% ob F(O, ob Folder, strDirectory strDirectory A @D2I=creddy@ (et ob F(O A $reateOb ect/@(cri!ting.File(yste%Ob ect@0 (et ob Folder A ob F(O.$reateFolder/strDirectory0 &# Delete a $ol%er (et oF(O A $reateOb ect/@(cri!ting.File(yste%Ob ect@0 oF(O.DeleteFolder/@72I=creddy@0 '# Copying $ol%ers (et oF(OAcreateob ect/@(cri!ting.Filesyste%ob ect@0 oF(O.$o!yFolder @72Igcr@, @$2I vr@, True (# C)ecking *eat)er t)e fol%er a!ailable or not+ if not creating t)e fol%er O!tion 78!licit Di% ob F(O, ob Folder, strDirectory strDirectory A @D2I=creddy@ (et ob F(O A $reateOb ect/@(cri!ting.File(yste%Ob ect@0 "# ob F(O.Folder78ists/strDirectory0 Then (et ob Folder A ob F(O.=etFolder/strDirectory0 %sgbo8 strDirectory . @ already created @ else (et ob Folder A ob F(O.$reateFolder/strDirectory0 end i# ,# Returning a collection of Disk Dri!es (et oF(O A $reateOb ect/@(cri!ting.File(yste%Ob ect@0 (et colDrives A oF(O.Drives

For 7ach oDrive in colDrives MsgBo8 @Drive letter2 @ . oDrive.Drive?etter 4e8t -# .etting a!ailable space on a Disk Dri!e (et oF(O A $reateOb ect/@(cri!ting.File(yste%Ob ect@0 (et oDrive A oF(O.=etDrive/@$2@0 MsgBo8 @-vailable s!ace2 @ . oDrive.-vailable(!ace

Flat File (cri!ts

Computer *ile )ystem It is a feature of t"e &perating System, used to (reateA)odifyAviewAdelete #rives, .olders and .iles ") istri#ution &perating System and &t"er /tilities *ile)ystem"#$ect +,Script "as Provided *ile)ystem"#$ect to perform file system operations t"roug" scripting #im ob'.so 3(reating an $utomation &b'ect in .ile System class, t"at can be used to perform&perations on (omputer .ile System Set ob'.soO(reate&b'ect<Nscripting..ileSystem&b'ectN= :> Creating a *ile #im ob'.so Set ob'.soO(reate&b'ect<Nscripting..ileSystem&b'ectN= ob'.so.(reateText.ile <N!BPGcreddy.txtN= ob'.so.(reateText.ile <N!BPGcreddy.docN= ob'.so.(reateText.ile <N!BPGcreddy.xlsN= ob'.so.(reateText.ile <N!BPGcreddy.pdfN= 2ote8 0e can (reate ot"er files also, but t"ey act as TextA.lat .iles Set ob'.ile O ob'.S&.(reateText.ile<N!BPGcreddy.txtN= => C!ec'ing weat!er t!e *ile is availa#le or notI if not creating t!e *ile str#irectoryON!BPN str.ileONGcreddy.txtN

Set ob'.S& O (reate&b'ect<NScripting..ileSystem&b'ectN= If ob'.S&..ile!xists<str#irectory 6 str.ile= T"en Set ob'.older O ob'.S&.Get.older<str#irectory= !lse Set ob'.ile O ob'.S&.(reateText.ile<N!BPGcreddy.txtN= !nd if ?> Reading ata c!aracter #y c!aracter from a *lat *ile

Set ob'.S& O (reate&b'ect<NScripting..ileSystem&b'ectN= Set ob'.ile O ob'.S&.&penText.ile<N!BPGcreddy.txtN, C= #o /ntil ob'.ile.$t!nd&fStream str("aracters O ob'.ile. ead<C= msgbox str("aracters 7oop @> Reading ata line #y line from a *lat *ile

Set ob'.S& O (reate&b'ect<NScripting..ileSystem&b'ectN= Set ob'.ile O ob'.S&.&penText.ile<N!BPGcreddy.txtN, C= #o /ntil ob'.ile.$t!nd&fStream str("aracters O ob'.ile. eadline msgbox str("aracters 7oop A> ata file7 riven Testing #y fetc!ing Test data directly from a Te,t

************************************************** LTest ReGuirement8 #ata #riven Testing by .etc"ing Test data directly from a Text file.

LAut!or8 G (

eddy

3#ate of (reationB CG-;H-:;C; LPre-reGuisites8 3gcr.txt <Test #ata= LTest *low8 3(reating an $utomation &b'ect in .ileSystem class 3&pening t"e !xternal Test #ata file using t"e &b'ect 3 ead t"e #ata 6 Split t"e #ata 3Generating t"e 7ogin &peration

3Pass Parameters 3************************************************* #im ob'.so, my.ile, my7ine, my.ield Set ob'.soO(reate&b'ect<NScripting..ileSystem&b'ectN= Set my.ileOob'.so.&penText.ile<N(BP#ocuments and SettingsPgcr.G( (J$C:.,#G#JP#esktopPvindod.txtN,C= 3C for ead, :-0rite 6 H-$ppend my.ile.Skip7ine #o /ntil my.ile.$t!nd&fStream my7ineOmy.ile. ead7ine my.ieldOSplit<my7ine,N,N= System/til. un N(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN #ialog<NtextBO7oginN=.$ctivate #ialog<NtextBO7oginN=.0in!dit<Nattac"ed textBO$gent 8ameBN=.Set my.ield<;= #ialog<NtextBO7oginN=.0in!dit<Nattac"ed textBOPasswordBN=.Set my.ield<C= wait : #ialog<NtextBO7oginN=.0in,utton<NtextBO&?N=.(lick 0indow<NtextBO.lig"t eservationN=.(lose 7oop my.ile.(lose Set ob'.soO8ot"ing
B> 1riting data to a te,t file #im Stuff, my.S&, 0riteStuff, dateStamp dateStamp O #ate<= Stuff O NI am Preparing t"is scriptB N 6dateStamp Set my.S& O (reate&b'ect<NScripting..ileSystem&b'ectN= Set 0riteStuff O my.S&.&penText.ile<NeBPGcreddy.txtN, H, True= 0riteStuff.0rite7ine<Stuff= 0riteStuff.(lose S!T 0riteStuff O 8&T1I8G S!T my.S& O 8&T1I8G C> elete a te,t file

Set ob'.S&Ocreateob'ect<NScripting.filesystemob'ectN= Set txt.ilepat" O ob'.S&.Get.ile<N!BPgcr.txtN= txt.ilepat".#elete<=

E> C!ec'ing weat!er t!e *ile is availa#le or notI if availa#le delete t!e *ile str#irectoryON!BPN str.ileONgcr.txtN Set ob'.S& O (reate&b'ect<NScripting..ileSystem&b'ectN= If ob'.S&..ile!xists<str#irectory 6 str.ile= T"en Set ob'.ile O ob'.S&.Getfile<str#irectory 6 str.ile= ob'.ile.delete <= !nd if F> Comparing two te,t files #im fC, f: fCONeBPGcreddyC.txtN f:ONeBPGcreddy:.txtN Public .unction (ompare.iles <.ilePat"C, .ilePat":= #im .S, .ileC, .ile: Set .S O (reate&b'ect<NScripting..ileSystem&b'ectN= If .S.Get.ile<.ilePat"C=.Si%e ZL .S.Get.ile<.ilePat":=.Si%e T"en (ompare.iles O True !xit .unction !nd If Set .ileC O .S.Get.ile<.ilePat"C=.&pen$sTextStream<C, ;= Set .ile: O .S.Get.ile<.ilePat":=.&pen$sTextStream<C, ;= (ompare.iles O .alse #o 0"ile .ileC.$t!nd&fStream O .alse StrC O .ileC. ead Str: O .ile:. ead (ompare.iles O Str(omp<StrC, Str:, ;= If (ompare.iles ZL ; T"en (ompare.iles O True !xit #o !nd If 7oop .ileC.(lose<= .ile:.(lose<= !nd .unction (all (omparefiles<fC,f:= If (ompare.iles<fC, f:= O .alse T"en )sg,ox N.iles are identical.N !lse )sg,ox N.iles are different.N !nd If :;> Counting t!e num#er of times a word appears in a file

s.ile8ameON!BPgcr.txtN sStringONgcreddyN (onst .& X !$#I8G O C #im o.so, oTxt.ile, s eadTxt, o eg!x, o)atc"es Set o.so O (reate&b'ect<NScripting..ileSystem&b'ectN= Set oTxt.ile O o.so.&penText.ile<s.ile8ame, .& X !$#I8G= s eadTxt O oTxt.ile. ead$ll Set o eg!x O 8ew eg!xp o eg!x.Pattern O sString o eg!x.Ignore(ase O bIgnore(ase o eg!x.Global O True Set o)atc"es O o eg!x.!xecute<s eadTxt= )atc"es.ound O o)atc"es.(ount Set oTxt.ile O 8ot"ing B Set o.so O 8ot"ing B Set o eg!x O 8ot"ing msgbox )atc"es.ound ::> Read a C). *ile 0sing &n !rror esume 8ext ata#ase Tec!niGues

(onst ad&penStatic O G (onst ad7ock&ptimistic O G (onst ad(mdText O 61;;;C Set ob'(onnection O (reate&b'ect<N$#&#,.(onnectionN= Set ob' ecordSet O (reate&b'ect<N$#&#,. ecordsetN= strPat"toText.ile O N(BP#atabasesPN ob'(onnection.&pen NProviderO)icrosoft.2et.&7!#,.I.;5N 6 X N#ata SourceON 6 strPat"toText.ile 6 N5N 6 X N!xtended PropertiesONNtext51# OV!S5.)TO#elimitedNNN ob' ecordset.&pen NS!7!(T * . &) P"one7ist.csvN, X ob'(onnection, ad&penStatic, ad7ock&ptimistic, ad(mdText #o /ntil ob' ecordset.!&. 0script.!c"o N8ameB N 6 ob' ecordset..ields.Item<N8ameN= 0script.!c"o N#epartmentB N 6 X ob' ecordset..ields.Item<N#epartmentN= 0script.!c"o N!xtensionB N 6 ob' ecordset..ields.Item<N!xtensionN= ob' ecordset.)ove8ext 7oop :=> Read a Te,t *ile into an Array

(onst .or eading O C Set ob'.S& O (reate&b'ect<NScripting..ileSystem&b'ectN= Set ob'Text.ile O ob'.S&.&penText.ile X <NeBPgcreddy.txtN, .or eading= #o /ntil ob'Text.ile.$t!nd&fStream str8ext7ine O ob'Text.ile. eadline arrService7ist O Split<str8ext7ine , N,N= 0script.!c"o NServer nameB N 6 arrService7ist<;= .or i O C to /bound<arrService7ist= 0script.!c"o NServiceB N 6 arrService7ist<i= 8ext 7oop :?> LCalculate si(e of a Te,t file #im ob'.so, .ileC,.ile: .ileCON(BP#ocuments and SettingsPC Set ob'.soO(reate&b'ect<N Scripting..ileSystem&b'ectN= xO ob'.so.Get.ile<.ileC=.Si%e )sgbox x6 N ,ytesN IG1$T0$VP#esktopPxy%.txtN

:@> LTest ReGuirement8 "pen : to :; orders in *lig!t Reservation I Capture Customer names and &,port into a Te,t file 3Test .lowB 37ogin &peration 3&pen &rder &peration and form t"e 7oop to open C to C; &rders 3(apture (usomer names using Get &Property )et"od 3(reate .ile system &b'ect and &pen t"e Text file using t"e &b'ect and !xport (usomer names 3---------------------------------------------------------------------------&ption !xplicit #im &rderX8umber, (ustomerX8ame, ob'.so, my.ile Set ob'.soO(reate&b'ect<NScripting..ileSystem&b'ectN= Set my.ileO ob'.so.(reateText.ile <N(BP#ocuments and SettingsPC IG1$T0$VP#esktopPabc8ew.txtN,:= my.ile.0rite7ine N(usomer 8amesN my.ile.0rite7ine N--------------------N If 8ot 0indow<N.lig"t eservationN=.!xist<G= T"en System/til. un N(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN,NN,N(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPN,NopenN

#ialog<N7oginN=.$ctivate #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set NasdfN #ialog<N7oginN=.0in!dit<NPasswordBN=.SetSecure NIcIHDJ;H>;IEEbHdc;D;bbd:IeHCEHJ;c>I>ccfHN #ialog<N7oginN=.0in,utton<N&?N=.(lick !nd If .or &rderX8umberO C to C; step C 0indow<N.lig"t eservationN=.$ctivate 0indow<N.lig"t eservationN=.0in,utton<N,uttonN=.(lick 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N&rder 8o.N=.Set N&8N 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in!dit<N!ditN=.Set &rderX8umber 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in,utton<N&?N=.(lick (ustomerX8ame O 0indow<N.lig"t eservationN=.0in!dit<N8ameBN=.Get &Property<NtextN= wait <:= my.ile.0rite7ine (ustomerX8ame 8ext my.ile.(lose Set ob'.soO8ot"ing CD= 3****************************************************** LTest ReGuirement8 Capturing all Buttons 2ames from t!e 4ogin ialog #o, and e,porting to a Te,t file 3$ut"orB G C Reddy 3#ate of (reationB CG-;H-:;C; LPre-reGuasites8 3gcr.txt LTest *low8 3(reating an $utomation &b'ect in .ileSystem class 3&pening t"e !xternal Test #ata file using t"e &b'ect 3(reating (ollection ob'ect and (apturing ,utton 8ames using t"e &b'ect 30riting ,utton 8ames to an !xternal Text file 3******************************************************** #im ob'.so, my.ile, o,utton, ,uttons, Tot,uttons Set ob'.soO(reate&b'ect<NScripting..ileSystem&b'ectN= Set my.ileOob'.so.&penText.ile<N(BP#ocuments and SettingsPgcr.G( (J$C:.,#G#JP#esktopPvindod.txtN,:= 3C for ead, :-0rite 6 H-$ppend

my.ile.0rite7ine N,utton 8amesN my.ile.0rite7ine N----------N Set o,uttonO#escription.(reate o,utton<NmicclassN=.valueON0in,uttonN System/til. un N(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN Set ,uttonsO#ialog<NtextBO7oginN=.("ild&b'ects<o,utton= Tot,uttonsO,uttons.(ount .or iO ; to Tot,uttons-C my,uttonO,uttons<i=.Get oProperty<NtextN= my.ile.0rite7ine my,utton 8ext my.ile.(lose Set ob'.soO8ot"ing :B> elete a Te,t file if it is an empty file

#im ob'.so, .ilePat" .ilePat"ON(BP#ocuments and SettingsPgcreddyP#esktopPabc.txtN Set ob'.soO(reate&b'ect<NScripting..ileSystem&b'ectN= .ileSi%eOob'.so.Get.ile<.ilePat"=.Si%e 3)sgbox .ileSi%e If .ileSi%eO; T"en ob'.so.#elete.ile<.ilePat"= !nd If Set ob'.soO8ot"ing

ata#ase )cripts-%
:> Get Test ata *rom a Dt!roug! )cripting> ata#ase and use in ata riven Testing

#im ob'(on, ob' s 3(reating an automation ob'ect in database connection class, it is used forconnecting to databases. Set ob'(onO(reate&b'ect<N$dodb.(onnectionN= 3(reating an automation ob'ect in database record set class, it is used forperforming operations on database tables<records=. Set ob' sO (reate&b'ect<N$dodb. ecordsetN= 3!stablis"ing connection string for )s-$ccess database.

ob'(on.ProviderO<N)icrosoft.2et.oledb.I.;N= ob'(on.&pen N(BP#ocuments and SettingsPgcr.G( (J$C:.,#G#JP#esktopP.lig"ts.mdbN ob' s.&pen NSelect * from 7oginN, ob'(on #o /ntil ob' s.!&.OTrue System/til. un N(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN,NN,N(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPN,NopenN #ialog<N7oginN=.$ctivate #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set ob' s..ields<N$gentN= #ialog<N7oginN=.0in!dit<NPasswordBN=.Set ob' s..ields<NPwdN= #ialog<N7oginN=.0in,utton<N&?N=.(lick 0indow<N.lig"t eservationN=.(lose ob' s.)ove8ext 7oop ob' s.(lose ob'(on.(lose Set ob'(onO8ot"ing Set ob' sO8ot"ing => &,porting ata from a ata#ase to an &,cel )!eet

C= #im con,rs := Set conOcreateob'ect<Nadodb.connectionN= G= Set rsOcreateob'ect<Nadodb.recordsetN= I= con.providerONmicrosoft.'et.oledb.I.;N D= con.openN(BP#ocuments and SettingsPadminP)y #ocumentsPGcreddy.md bN E= rs.openNselect*from 7oginN,con >= Set exOcreateob'ect<N!xcel.$pplicationN= H= Set aOex.workbooks.open<N(BP#ocuments and SettingsPadminP)y#ocuments PGcreddy.xlsN= J= Set bOa.works"eets<Ns"eetCN= C;= iOC CC= #o 0"ile 8ot rs.!&. C:= b.cells <i,C=.valueOrs.fields<NagentN= CG= b.cells<i,:=.valueOrs.fields<NpasswordN= CI= rs.movenext CD= iOiQC CE= 7oop C>= a.save

CH= a.close ?> &,porting ata from a ata#ase to a Te,t file

#im ob'(on,ob' s,&b'.so,my.ile,my#ata,rc,r Set ob'(onOcreateob'ect<N$dodb.connectionN= Set ob' sOcreateob'ect<N$dodb. ecordsetN= set ob'.soOcreateob'ect<NScripting..ilesystemob'ectN= Set my.ileOob'.so.&penText.ile<N(BP#ocuments and SettingsPgcrP)y#ocume ntsPgcreddy.txtN,H= ob'con.providerO<N)icrosoft.'et.oledb.I.;N= ob'con.openN(BP#ocuments and SettingsPgcrP)y #ocumentsPgcreddy.mdb N ob'rs.open Nselect * from loginN,ob'(on rOC #o until ob' s.!&. aOob' s..ields <N$gentN= bOob' s..ields <NPwdN= my.ile.0riteline a 6N,N6 b rOrQC ob' s.)ove8ext 7oop my.ile.(lose ob'(on.(lose @> Connecting to a )Q4 )ever data#ase (onst ad&penStatic O G (onst ad7ock&ptimistic O G Set ob'(onnection O (reate&b'ect<N$#&#,.(onnectionN= Set ob' ecordSet O (reate&b'ect<N$#&#,. ecordsetN= ob'(onnection.&pen X NProviderOSQ7&7!#,5#ata SourceOatl-s4l-;C5N 6 X NTrustedX(onnectionOVes5Initial (atalogO8ort"wind5N 6 X N/ser I#OfabrikamPkenmyer5PasswordOGI#!EtIGW5N ob' ecordSet.&pen NS!7!(T * . &) (ustomersN, X ob'(onnection, ad&penStatic, ad7ock&ptimistic ob' ecordSet.)ove.irst

0script.!c"o ob' ecordSet. ecord(ount A> "pen a ata#ase 0sing a )2

(onst ad&penStatic O G (onst ad7ock&ptimistic O G Set ob'(onnection O (reate&b'ect<N$#&#,.(onnectionN= Set ob' ecordSet O (reate&b'ect<N$#&#,. ecordsetN= ob'(onnection.&pen X N8ort"wind5fabrikamPkenmyer5GIg"fn6W'N ob' ecordSet.&pen NS!7!(T * . &) (ustomersN, X ob'(onnection, ad&penStatic, ad7ock&ptimistic ob' ecordSet.)ove.irst 0script.!c"o ob' ecordSet. ecord(ount

B> "pen Two Recordsets

(onst ad&penStatic O G (onst ad7ock&ptimistic O G Set ob'(onnection O (reate&b'ect<N$#&#,.(onnectionN= Set ob' ecordSet O (reate&b'ect<N$#&#,. ecordsetN= Set ob' ecordSet: O (reate&b'ect<N$#&#,. ecordsetN= ob'(onnection.&pen X NProviderO )icrosoft.2et.&7!#,.I.;5 N 6 X N#ata SourceOinventory.mdbN ob' ecordSet.&pen NS!7!(T * . &) GeneralProperties 0"ere (omputer8ame O 3(omputerC3N, X ob'(onnection, ad&penStatic, ad7ock&ptimistic ob' ecordSet.)ove.irst

ob' ecordSet:.&pen NS!7!(T * . &) Storage 0"ere (omputer8ame O 3(omputerC3N, X ob'(onnection, ad&penStatic, ad7ock&ptimistic ob' ecordSet:.)ove.irst #o /ntil ob' ecordset.!&. 0script.!c"o ob' ecordset..ields.Item<N(omputer8ameN= 0script.!c"o ob' ecordset..ields.Item<N&S8ameN= ob' ecordSet.)ove8ext 7oop #o /ntil ob' ecordset:.!&. 0script.!c"o ob' ecordset:..ields.Item<N#rive8ameN=, X ob' ecordset:..ields.Item<N#rive#escriptionN= ob' ecordSet:.)ove8ext 7oop ob' ecordSet.(lose ob' ecordSet:.(lose ob'(onnection.(lose

C> )earc!ing a

ata#ase 0sing )tring Criteria

(onst ad&penStatic O G (onst ad7ock&ptimistic O G Set ob'(onnection O (reate&b'ect<N$#&#,.(onnectionN= Set ob' ecordSet O (reate&b'ect<N$#&#,. ecordsetN= ob'(onnection.&pen X NProvider O )icrosoft.2et.&7!#,.I.;5 N 6 X N#ata Source O eventlogs.mdbN ob' ecordSet.&pen NS!7!(T * . &) !ventTable N 6 X N01! ! Type O 3!rror3N, ob'(onnection, ad&penStatic, X ad7ock&ptimistic ob' ecordSet.)ove.irst 0script.!c"o N8umber of recordsB N 6 ob' ecordset. ecord(ount

ob' ecordSet.(lose ob'(onnection.(lose

Database Scripts/00
:> %nsert "#$ect ata into a data#ase ta#le using ata#ase Command

#im ob'(on,ob'(om Set ob'(onO(reateob'ect<N$#&#,.connectionN= ob'(on.openNProviderO)icrosoft.2et.&7!#,.I.;5#ata SourceO(BPgcreddy.mdb5N Set ob'(omO(reateob'ect<N$#&#,.(ommandN= ob'(om.$ctive(onnectionOob'(on ob'(om.(ommandTextONinsert into !mp values<3G ( eddy3,HH:GG,G;;;;=N ob'(om.!xecute ob'(on.(lose Set ob'(omO8ot"ing Set ob'(onO8ot"ing => %nsert multiple sets of ata Dusing &,cel s!eet> into a data#ase ta#le using ata#ase Command "#$ect #im ob'(on,ob'(om,str!mp8ame,int!mp8o,int!mpSal,int owcount,i Set ob'(onO(reateob'ect<N$#&#,.connectionN= ob'(on.openNProviderO)icrosoft.2et.&7!#,.I.;5#ata SourceO(BPgcred dy.mdb5N Set ob'(omO(reateob'ect<N$#&#,.(ommandN= ob'(om.$ctive(onnectionOob'(on #atatable.$ddS"eet<NinputN= #atatable.ImportS"eet N(BPgcreddy.xlsN,C,NinputN int owcountO#atatable.GetS"eet<NinputN=.Get ow(ount )sgbox int owcount .or iOC to int owcount step C

#ataTable.Set(urrent ow<i= str!mp8ameO #ataTable.+alue<C,NinputN= int!mp8oO #ataTable.+alue<:,NinputN= int!mpSalO #ataTable.+alue<G,NinputN= ob'(om.(ommandTextONinsert into !mp values< 3N6str!mp8ame6N 3,N6int!mp8o6N,N6int!mpSal6N=N ob'(om.!xecute 8ext ob'(on.(lose Set ob'(omO8ot"ing Set ob'(onO8ot"ing ?> *etc! data from a data#aseI and compare wit! e,pected data in &,cel file7 ---------#im ob'(on, ob' s, ob'!xcel, my.ile, mys"eet Set ob'(onO(reate&b'ect<N$dodb.(onnectionN= Set ob' sO (reate&b'ect<N$dodb. ecordsetN= Set ob'!xcelO(reate&b'ect<N!xcel.$pplicationN= Set my.ileOob'!xcel.0orkbooks.&pen <N(BP#ocuments and SettingsPgcr.G( (-J$C:.,#G#JP#esktopPTest#ata:.xlsN= Set myS"eetOmy.ile.0orks"eets<NS"eetCN= cOmyS"eet.usedrange.rows.count 3)sgbox c ob'(on.ProviderO<N)icrosoft.2et.oledb.I.;N= ob'(on.&pen N(BP#ocuments and SettingsPgcr.G( (J$C:.,#G#JP#esktopP(omp.mdbN ob' s.&pen NSelect !)P8ame from !mployeeN, ob'(on

#o /ntil ob' s.!&.OTrue xOob' s..ields<N!)P8ameN= .or 'O : to c yOmyS"eet.cells<',N$N= If xOy T"en eporter. eport!vent micPass,N esN,N8ameB N6 y 6N $vailableN 3 !lse 3 eporter. eport!vent mic.ail,N esN,N8ameB N6 y 6N 8ot $vailableN

!nd If 8ext ob' s.)ove8ext 7oop ob'!xcel.Quit Set ob'!xcelO8ot"ing ob' s.(lose ob'(on.(lose Set ob' sO8ot"ing Set ob'(omO8ot"ing

QTP

ata#ase )cript &,amples

----------------------------------------------------------------------------:> ata riven Testing for 4ogin "peration #y *etc!ing Test ata directly *rom a ata#ase &ption !xplicit #im ob'(onnection, ob' ecordSet 'Creating an Automation Object in Database Connection Class, that can be used to connect to Databases Set ob'(onnectionO(reate&b'ect<N$dodb.(onnectionN= 'Creating an Automation Object in Database RecordSet Class, that can be used to Perform Operations on Database Tables (Records Set ob' ecordSetO(reate&b'ect<N$dodb. ecordSetN= L&sta#lis!ing Connection )tring for M) Access ata#ase ob'(onnection.ProviderO<N)icrosoft.2et.&7!#,.I.;N= ob'(onnection.&pen N(BP#ocuments and SettingsPbannuP#esktopPgcreddy.mdbN L*etc!ing Test ata using Record)et "#$ect ob' ecordSet.&pen NSelect * .rom 7oginN,ob'(onnection #o /ntil ob' ecordSet.!&.OTrue System/til. un N(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN #ialog<NtextBO7oginN=.$ctivate #ialog<NtextBO7oginN=.0inedit<Nattac"ed textBO$gent 8ameBN=.Set ob' ecordSet..ields<N$gentN= #ialog<NtextBO7oginN=.0inedit<Nattac"ed textBOPasswordBN=.Set ob' ecordSet..ields<NPasswordN= 0ait : #ialog<NtextBO7oginN=.0inbutton<NtextBO&?N,Nwidt"BOE;N=.(lick

0indow<NtextBO.lig"t eservationN=.(lose ob' ecordSet.)ove8ext 7oop ob' ecordSet.(lose ob'(onnection.(lose Set ob' ecordSetO8ot"ing Set ob'(onnectionO8ot"ing => 1rite ata to a ata#ase Ta#le

#im ob'(onnection, ob'(ommand Set ob'(onnectionO(reate&b'ect<N$dodb.(onnectionN= Set ob'(ommandO(reate&b'ect<N$dodb.(ommandN= ob'(onnection.ProviderO<N)icrosoft.$(!.&7!#,.C:.;N= ob'(onnection.&pen N(BP#ocuments and SettingsPTest classP#esktopP.lig"ts.mdbN ob'(ommand.$ctive(onnectionOob'(onnection ob'(ommand.(ommandText ONInsert into 7ogin values <H,3("ennai3,3)ercury3=N ob'(ommand.!xecute ob'(onnection.(lose Set ob'(ommandO8ot"ing Set ob'(onnectionO8ot"ing ----------------------------------------------------?> 1rite Multiple )ets of ata to a ata#ase Ta#le #im ob'(onnection, ob'(ommand #im ob'!xcel, ob'0ork,ook, ob'0orks"eet Set ob'!xcelO(reate&b'ect<N!xcel.$pplicationN= Set ob'0ork,ookOob'!xcel.0orkbooks.&pen <N(BP#ocuments and SettingsPTest classP#esktopPdataC.xlsN= Set ob'0orkS"eetOob'0ork,ook.0orks"eets<NS"eetCN= Set ob'(onnectionO(reate&b'ect<N$dodb.(onnectionN= Set ob'(ommandO(reate&b'ect<N$dodb.(ommandN=

ob'(onnection.ProviderO<N)icrosoft.$(!.&7!#,.C:.;N= ob'(onnection.&pen N(BP#ocuments and SettingsPTest classP#esktopP.lig"ts.mdbN ob'(ommand.$ctive(onnectionOob'(onnection owsX(ountOob'0orkS"eet./sedrange. ows.(ount .or iO : To owsX(ount Step C S8&Oob'0orkS"eet.(ells<i,N$N= $gentOob'0orkS"eet.(ells<i,N,N= PasswordOob'0orkS"eet.(ells<i,N(N= ob'(ommand.(ommandText ONInsert into 7ogin values <3N6S8&6N3,3N6$gent6N3,3N6Password6N3=N ob'(ommand.!xecute 8ext ob'0ork,ook.(lose ob'!xcel.Quit Set ob'!xcelO8ot"ing ob'(onnection.(lose Set ob'(ommandO8ot"ing Set ob'(onnectionO8ot"ing --------------------------------------------------------@> &,port ata from a ata#ase Ta#le to an &,cel file D=nd )!eet>

&ption !xplicit #im ob'(onnection, ob' ecordset #im ob'!xcel, ob'0orkbook, ob'0orks"eet, i Set ob'(onnection O (reateob'ect <N$dodb.(onnectionN= Set ob' ecordset O (reateob'ect <N$dodb. ecordsetN= Set ob'!xcel O (reate&b'ect<N!xcel.$pplicationN= Set ob'0orkbook O ob'!xcel.0orkbooks.&pen<N(BP#ocuments and SettingsPTest classP#esktopPdataC.xlsN= Set ob'0orks"eet O ob'0orkbook.0orks"eets<NS"eet:N= ob'0orks"eet.cells<C,N$N= O N$gentsN ob'0orks"eet.cells<C,N,N= O NPasswordN ob'(onnection.Provider O <N)icrosoft.$(!.&7!#,.C:.;N= ob'(onnection.&pen N(BP#ocuments and SettingsPTest classP#esktopP.lig"ts.mdbN

ob' ecordset.&pen NSelect $gent, Password from 7oginN, ob'(onnection i O : 3 ows #o /ntil ob' ecordset.!&. ob'0orks"eet.cells<i, N$N= O ob' ecordset..ields<N$gentN= ob'0orks"eet.cells<i, N,N= O ob' ecordset..ields<NPasswordN= iOiQC ob' ecordset.)ove8ext 7oop ob'0orkbook.Save ob'0orkbook.(lose ob'!xcel.Quit Set ob'!xcel O 8ot"ing ob' ecordset.(lose ob'(onnection.(lose Set ob' ecordset O 8ot"ing Set ob'(onnection O 8ot"ing ---------------------------------------------------A> &,port ata from a ata#ase Ta#le to a Te,t file &ption !xplicit #im ob'(onnection, ob' ecordset #im ob'.so,my.ile Set ob'(onnection O (reateob'ect <N$dodb.(onnectionN= Set ob' ecordset O (reateob'ect <N$dodb. ecordsetN= Set ob'.so O (reate&b'ect<NScripting..ilesystemob'ectN= Set my.ileOob'.so.&penText.ile<N(BP#ocuments and SettingsPTest classP#esktopPdataC.txtN,:= my.ile.0rite7ine N$gent N6N PasswordN my.ile.0rite7ine N--------------------N ob'(onnection.Provider O <N)icrosoft.$(!.&7!#,.C:.;N= ob'(onnection.&pen N(BP#ocuments and SettingsPTest classP#esktopP.lig"ts.mdbN ob' ecordset.&pen NSelect $gent, Password from 7oginN, ob'(onnection

#o /ntil ob' ecordset.!&. my.ile.0rite7ine ob' ecordset..ields<N$gentN=6N ,N 6 ob' ecordset..ields<NPasswordN= ob' ecordset.)ove8ext 7oop my.ile.(lose Set ob'.soO8ot"ing ob' ecordset.(lose ob'(onnection.(lose Set ob' ecordset O 8ot"ing Set ob'(onnection O 8ot"ing -----------------------------------------------B> &,port ata from a Te,t *ile to a ata#ase Ta#le &ption !xplicit #im ob'(onnection, ob'(ommand #im ob'.so,my.ile,my7ine,my.ield,S8&,$gent,Password Set ob'(onnection O (reateob'ect <N$dodb.(onnectionN= Set ob'(ommand O (reateob'ect <N$dodb.(ommandN= Set ob'.so O (reate&b'ect<NScripting..ilesystemob'ectN= Set my.ileOob'.so.&penText.ile<N(BP#ocuments and SettingsPTest classP#esktopPdatC.txtN,C= ob'(onnection.Provider O <N)icrosoft.$(!.&7!#,.C:.;N= ob'(onnection.&pen N(BP#ocuments and SettingsPTest classP#esktopP.lig"ts.mdbN my.ile.Skip7ine my.ile.Skip7ine #o 0"ile my.ile.$t!nd&fStream O .$7S! my7ine O my.ile. ead7ine my.ield O Split<my7ine,N,N= S8& O my.ield<;= $gent O my.ield<C= Password O my.ield<:=

ob'(ommand.$ctive(onnection O ob'(onnection ob'(ommand.(ommandText O NInsert into 7ogin: values<3N6S8&6N3,3N6$gent6N3,3N6Password6N3=N ob'(ommand.!xecute 7oop

my.ile.(lose Set ob'.soO8ot"ing Set ob'(ommand O 8ot"ing ob'(onnection.(lose Set ob'(onnection O 8ot"ing ---------------------------------------------------------------

78cel (cri!ts

:> Create an &,cel fileI enter some data and save t!e file t!roug! .B scriptJ C= := G= I= D= E= >= #im ob'excel Set ob'!xcel O createob'ect<N!xcel.applicationN= ob'excel.+isible O True ob'excel.0orkbooks.add ob'excel.(ells<C, C=.+alue O NTestingN ob'excel.$ctive0orkbook.Save$s<NfBPexceltest.xlsN= ob'excel.Quit

=> C!ec' if t!e &,cel file e,ists or notI if e,ists open t!e file and enter some data I %f not &,ists create t!e file and enter some data and save t!e file t!roug! .B scriptJ #im ob'!xcel, .ilePat" .ilePat"ON(BP#ocuments and SettingsPgcr.G( (J$C:.,#G#JP#esktopPgcr.xlsN Set ob'!xcelO(reate&b'ect<N!xcel.$pplicationN= set ob'.soO(reate&b'ect<NScripting..ileSystem&b'ectN= ob'!xcel.+isibleOTrue If 8ot ob'.so..ile!xists<.ilePat"= T"en ob'!xcel.0orkbooks.$dd ob'!xcel.(ells<C,C=.valueONQTPN ob'!xcel.$ctive0orkbook.Save$s <.ilePat"= !lse

set my.ileO ob'!xcel.0orkbooks.&pen <.ilePat"= Set myS"eetOmy.ile.0orks"eets<NS"eetCN= myS"eet.cells<C,C=.valueONQTPN ob'!xcel.$ctive0orkbook.Save !nd If ob'!xcel.Quit Set ob'!xcelO8ot"ing ?> ata riven Testing t!roug! an &,ternal &,cel )!eet

C= Set my!xcelO(reateob'ect<N!xcel.$pplicationN= := Set my.ileOmy!xcel.workbooks.open <N(BP#ocuments andSettingsPadminP)y #ocumentsPgcreddy.xlsN= G= Set myS"eetOmy.ile.works"eets<NS"eetCN= I= owsX(ountOmyS"eet.usedrange.rows.count D= .or iO C to owsX(ount E= $gentOmyS"eet.cells<i,N$N= >= pwdOmyS"eet.(ells<i,N,N= H= System/til. un N(BPProgram .ilesP)ercury InteractivePQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN,NN,N(BPProgram .ilesP)ercury InteractivePQuickTest ProfessionalPsamplesPflig"tPappPN,NopenN J= #ialog<N7oginN=.$ctivate C;= #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set $gent CC= #ialog<N7oginN=.0in!dit<NPasswordBN=.SetSecure pwd C:= #ialog<N7oginN=.0in!dit<NPasswordBN=.Type mic eturn CG= 0indow<N.lig"t eservationN=.(lose CI= 8ext @> Compare two e,cel files Set ob'!xcel O (reate&b'ect<N!xcel.$pplicationN= ob'!xcel.+isible O True Set ob'0orkbookCO ob'!xcel.0orkbooks.&pen<N!BPgcreddyC.xlsN= Set ob'0orkbook:O ob'!xcel.0orkbooks.&pen<N!BPgcreddy:.xlsN= Set ob'0orks"eetCO ob'0orkbookC.0orks"eets<C= Set ob'0orks"eet:O ob'0orkbook:.0orks"eets<C= .or !ac" cell In ob'0orks"eetC./sed ange If cell.+alue ZL ob'0orks"eet:. ange<cell.$ddress=.+alue T"en msgbox Nvalue is differentN !lse msgbox Nvalue is sameN !nd If 8ext

ob'0orkbookC.close ob'0orkbook:.close ob'!xcel.4uit set ob'!xcelOnot"ing A> ata riven Testing using ata Ta#le met!ods

#atatable.$ddS"eet NgcreddyN #atatable.ImportS"eet N(BP#ocuments andSettingsP$dministratorP#esktopPgcreddy.xlsN,C,G nOdatatable.GetS"eet <G=.Get ow(ount .or iO C to n #atatable.Set(urrent ow<i= Invokeapplication N(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN #ialog<N7oginN=.$ctivate #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set datatable<NagentN,G= #ialog<N7oginN=.0in!dit<NPasswordBN=.Set datatable<NpwdN,G= #ialog<N7oginN=.0in,utton<N&?N=.(lick 0indow<N.lig"t eservationN=.(lose 8ext &,ample =>8 #atatable.$ddS"eet NgcreddyN #atatable.ImportS"eet N(BP#ocuments andSettingsP$dministratorP#esktopPgcreddy.xlsN,C,G nOdatatable.GetS"eet <G=.Get ow(ount .or iO C to n #atatable.Set(urrent ow<i= +b0indow<N.ormCN=.$ctivate +b0indow<N.ormCN=.+b!dit<NvalCN=.Set datatable<N+CN,G= +b0indow<N.ormCN=.+b!dit<Nval:N=.Set datatable<N+:N,G= +b0indow<N.ormCN=.+b,utton<N$##N=.(lick eresO #atatable.+alue <NresN,G= aresO+b0indow<N.ormCN=.+b!dit<NresN=.Get &Property <NtextN= If eresOares T"en datatable<NresN,G=Opass else datatable<NresN,G=Ofail !nd If 8ext B> "pen an &,cel )preads!eet

Set ob'!xcel O (reate&b'ect<N!xcel.$pplicationN= Set ob'0orkbook O ob'!xcel.0orkbooks.&pen<N(BPScriptsPgcreddy.xlsN= C> Read an &,cel )preads!eet Set ob'!xcel O (reate&b'ect<N!xcel.$pplicationN= Set ob'0orkbook O ob'!xcel.0orkbooks.&pen X <N(BPScriptsP8ewXusers.xlsN= int ow O : #o /ntil ob'!xcel.(ells<int ow,C=.+alue O NN 0script.!c"o N(8B N 6 ob'!xcel.(ells<int ow, C=.+alue 0script.!c"o Ns$)$ccount8ameB N 6 ob'!xcel.(ells<int ow, :=.+alue 0script.!c"o NGiven8ameB N 6 ob'!xcel.(ells<int ow, G=.+alue 0script.!c"o N7ast8ameB N 6 ob'!xcel.(ells<int ow, I=.+alue int ow O int ow Q C 7oop ob'!xcel.Quit E> Add *ormatted ata to a )preads!eet

Set ob'!xcel O (reate&b'ect<N!xcel.$pplicationN= ob'!xcel.+isible O True ob'!xcel.0orkbooks.$dd ob'!xcel.(ells<C, C=.+alue O NTest valueN ob'!xcel.(ells<C, C=..ont.,old O T /! ob'!xcel.(ells<C, C=..ont.Si%e O :I ob'!xcel.(ells<C, C=..ont.(olorIndex O G F> )ort an &,cel )preads!eet on T!ree (onst xl$scending O C (onst xl#escending O : (onst xlVes O C Set ob'!xcel O (reate&b'ect<N!xcel.$pplicationN= ob'!xcel.+isible O True Set ob'!xcel O (reate&b'ect<N!xcel.$pplicationN= ob'!xcel.+isible O True Set ob'0orkbook O X ifferent Columns

ob'!xcel.0orkbooks.&pen<N(BPScriptsPSortXtest.xlsN= Set ob'0orks"eet O ob'0orkbook.0orks"eets<C= Set ob' ange O ob'0orks"eet./sed ange Set ob' ange: O ob'!xcel. ange<N$CN= Set ob' angeG O ob'!xcel. ange<N,CN= Set ob' angeI O ob'!xcel. ange<N(CN= ob' ange.Sort ob' ange:,xl$scending,ob' angeG,,xl#escending, X ob' angeI,xl#escending,xlVes :;> )!ort an e,cel s!eet column Set ob'!xcel O (reate&b'ect<N!xcel.$pplicationN= ob'!xcel.+isible O True Set ob'0orkbook O ob'!xcel.0orkbooks.$dd Set ob'0orks"eet O ob'0orkbook.0orks"eets<C= ob'!xcel.(ells<C, ob'!xcel.(ells<:, ob'!xcel.(ells<G, ob'!xcel.(ells<I, C=.+alue C=.+alue C=.+alue C=.+alue O O O O NDN NCN N;N NGN

Set ob' angeOob'works"eet.usedrange ob'range.sort<ob'range= ::> Add 2ew )!eet to &,cel *ile #im ob'!xcel Set ob'!xcel O createob'ect<N!xcel.$pplicationN= ob'!xcel.+isibleOTrue ob'!xcel.0orkbooks.$dd ob'excel.$ctive0orkbook.Save$s <N(BP#ocuments and SettingsPgcr.G( (J$C:.,#G#JP#esktopPgcreddy.xlsN= ob'!xcel.0orks"eets.$dd ob'!xcel.$ctive0orkbook.Save ob'!xcel.Quit Set ob'!xcelO8ot"ing :=> Rename )!eets in an &,cel *ile D1or'Boo'>

#im ob'!xcel Set ob'!xcel O createob'ect<N!xcel.$pplicationN= ob'!xcel.+isibleOTrue ob'!xcel.0orkbooks.$dd ob'excel.$ctive0orkbook.Save$s <N(BP#ocuments and SettingsPgcr.G( (J$C:.,#G#JP#esktopPgcreddy.xlsN= ob'!xcel.0orks"eets<NS"eetCN=.8ameONgcrN ob'!xcel.0orks"eets<NS"eet:N=.8ameON4tpN ob'!xcel.0orks"eets<NS"eetGN=.8ameONtrainingN ob'!xcel.$ctive0orkbook.Save ob'!xcel.Quit Set ob'!xcelO8ot"ing :?> Add a )!eet to an &,cel *ile D1or'Boo'> and c!ange t!e Position #im ob'!xcel Set ob'!xcel O createob'ect<N!xcel.$pplicationN= ob'!xcel.+isibleOTrue Set my.ileO ob'!xcel.0orkbooks.$dd ob'excel.$ctive0orkbook.Save$s <N(BP#ocuments and SettingsPgcr.G( (J$C:.,#G#JP#esktopPgcreddy.xlsN= ob'!xcel.0orks"eets.$dd my.ile.S"eets<NS"eetIN=.)ove, my.ile.S"eets<I= ob'!xcel.$ctive0orkbook.Save ob'!xcel.Quit Set ob'!xcelO8ot"ing

G0% )cript8
QTP (cri!ts e8a%!les
:> .erify 4ogin Boundary <("eck all t"e boundary conditions of t"e 7ogin dialog box. ("ecks to see if t"e correct message appears in t"e error window <.lig"t eservation )essage= C= := G= I= D= E= $pplication#ir O !nvironment<NProduct#irN= $pplicationPat" O NPsamplesPflig"tPappPflig"tIa.exeN If 0indow<N.lig"t eservationN=.!xist<:= T"en 0indow<N.lig"t eservationN=.(lose System/til. un $pplication#ir 6 $pplicationPat" !lseif 8ot #ialog<N7oginN=.!xist<C= T"en

>= System/til. un $pplication#ir 6 $pplicationPat" H= !nd If J= #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set #atatable.+alue <N$gent8ameN,dtGlobalS"eet= C;= #ialog<N7oginN=.0in!dit<NPasswordBN=.Set #atatable.+alue <NPasswordN,dtGlobalS"eet= CC= #ialog<N7oginN=.0in,utton<N&?N=.(lick C:= If #ialog<N7oginN=.#ialog<N.lig"t eservationsN=.!xist<C= and #atatable.+alue <NStatusN,dtGlobalS"eet=ON.ailN T"en CG= #ialog<N7oginN=.#ialog<N.lig"t eservationsN=.Static<N$gent name must be atN=.("eck ("eckPoint<N$gent name must be at least I c"aracters long.N= CI= #ialog<N7oginN=.#ialog<N.lig"t eservationsN=.0in,utton<N&?N=.(lick CD= !lseif 0indow<N.lig"t eservationN=.!xist<C;= and #atatable.+alue <NStatusN,dtGlobalS"eet=ONPassN T"en CE= eporter. eport!vent P$SS,N7oginB N,NSucceededN C>= !lse CH= eporter. eport!vent .ail,N7oginB N,N(ombination ]N 6 #atatable.Get(urrent ow 6 N was not according to !xcel fileN CJ= !nd If => .erify Cancel "peration <in 7ogin #ialog box, if user selects cancel button, before enter any data after enter data dialog box s"ould be disappeared.= C= Invokeapplication N(BPProgram .ilesP)ercury InteractivePQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN := #ialog<N7oginN=.$ctivate G= #ialog<N7oginN=.0in,utton<N(ancelN=.(lick I= If #ialog<N7oginN=.!xist <:= OTrue T"en D= eporter. eport!vent C,NsdN,N.ailN E= !lse >= eporter. eport!vent ;,NsdN,NPassN H= Invokeapplication N(BPProgram .ilesP)ercury InteractivePQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN J= !nd If C;= #ialog<N7oginN=.$ctivate CC= #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set NasdfN C:= #ialog<N7oginN=.0in,utton<N(ancelN=.(lick CG= If #ialog<N7oginN=.!xist <:= OTrue T"en CI= eporter. eport!vent C,NsdN,N.ailN CD= !lse CE= eporter. eport!vent ;,NsdN,NPassN C>= Invokeapplication N(BPProgram .ilesP)ercury InteractivePQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN CH= !nd If

CJ= #ialog<N7oginN=.$ctivate :;= #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set NasdfN :C= #ialog<N7oginN=.0in!dit<NPasswordBN=.SetSecure NIaJJGafIDdcbdD;EcHIDCb:>Id:da;>bGHffDDGCN ::= #ialog<N7oginN=.0in,utton<N(ancelN=.(lick :G= If #ialog<N7oginN=.!xist <:=OTrue T"en :I= eporter. eport!vent C,NsdN,N.ailN :D= !lse :E= eporter. eport!vent ;,NsdN,NPassN :>= Invokeapplication N(BPProgram .ilesP)ercury InteractivePQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN :H= !nd If :J= #ialog<N7oginN=.$ctivate G;= #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set NasdfN GC= #ialog<N7oginN=.0in!dit<NPasswordBN=.SetSecure NIaJJGafIDdcbdD;EcHIDCb:>Id:da;>bGHffDDGCN G:= #ialog<N7oginN=.0in,utton<N&?N=.(lick ?> .erify AdditionI )u#tractionI Multiplication and "perations in Calculator Application7 ivision

C= #im a es,s es,d es,m es := +b0indow<N+b0indowN=.$ctivate G= +b0indow<N+b0indowN=.+b!dit<N+b!ditN=.Set NC;N I= +b0indow<N+b0indowN=.+b!dit<N+b!ditX:N=.Set N:;N D= vCO+b0indow<N+b0indowN=.+b!dit<N+b!ditN=.Get &Property <NtextN= E= v:O+b0indow<N+b0indowN=.+b!dit<N+b!ditX:N=.Get &Property <NtextN= >= +b0indow<N+b0indowN=.+b,utton<N$##N=.(lick H= a esO+b0indow<N+b0indowN=.+b!dit<N+b!ditXGN=.Get+isibleText J= +b0indow<N+b0indowN=.+b,utton<NS/,N=.(lick C;= s esO+b0indow<N+b0indowN=.+b!dit<N+b!ditXGN=.Get+isibleText CC= +b0indow<N+b0indowN=.+b,utton<N)/7N=.(lick C:= m esO+b0indow<N+b0indowN=.+b!dit<N+b!ditXGN=.Get+isibleText CG= +b0indow<N+b0indowN=.+b,utton<N#I+N=.(lick CI= d esO+b0indow<N+b0indowN=.+b!dit<N+b!ditXGN=.Get+isibleText CD= vCOcdbl<vC= CE= v:Ocdbl<v:= C>= a esOcdbl <a es= CH= s esOcdbl <s es= CJ= m esOcdbl <m es= :;= d esOcdbl <d es= :C= If a esOvCQv: T"en ::= eporter. eport!vent ;,N esN,N$ddition PassedN :G= else :I= eporter. eport!vent C,N esN,N$ddition .ailedN

:D= :E= :>= :H= :J= G;= GC= G:= GG= GI= GD= GE= G>= GH= GJ= I;=

!nd If If s esOvC-v: T"en eporter. eport!vent else eporter. eport!vent !nd If If m esOvC*v: T"en eporter. eport!vent else eporter. eport!vent !nd If If d esOvCAv: T"en eporter. eport!vent else eporter. eport!vent !nd If

;,N esN,NSubtraction PassedN C,N esN,NSubtraction .ailedN ;,N esN,N)ultiplecation PassedN C,N esN,N)ultiplecation .ailedN ;,N esN,N#ivision PassedN C,N esN,N#ivision .ailedN

@> .erify state of 0pdate "rder ButtonI #efore open an "rder and after open an "rder <in .lig"t eservation before opening an order /pdate &rder button s"ould be disabled after opening an order enabled.= C= &ption explicit := #im bo,ao G= If 8ot window<N.lig"t eservationN=.!xist <:= T"en I= System/til. un N(BPProgram .ilesP)ercury InteractivePQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN D= #ialog<N7oginN=.$ctivate E= #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set NGcreddyN >= #ialog<N7oginN=.0in!dit<NPasswordBN=.SetSecure NIaaHbceJJHIfCaCDeaCH>a:daDbCHcDIDabb;CcfN H= #ialog<N7oginN=.0in,utton<N&?N=.(lick J= !nd If C;= 0indow<N.lig"t eservationN=.$ctivate CC= boO0indow<N.lig"t eservationN=.0in,utton<N/pdate &rderN=.Get &Property <N!nabledN= C:= 0indow<N.lig"t eservationN=.0in,utton<N,uttonN=.(lick CG= 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N&rder 8o.N=.Set N&8N CI= 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in!dit<N!ditN=.Set NCN CD= 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in,utton<N&?N=.(lick CE= aoO0indow<N.lig"t eservationN=.0in,utton<N/pdate &rderN=.Get &Property <N!nabledN= C>= If boO.alse T"en CH= eporter. eport!vent ;,N esN,N/pdate &rder ,utton #isabledN

CJ= :;= :C= ::= :G= :I= :D= :E=

else eporter. eport!vent C,N esN,N/pdate &rder ,utton !nabledN !nd If If aoOTrue T"en eporter. eport!vent ;,N esN,N/pdate &rder ,utton !nabledN else eporter. eport!vent C,N esN,N/pdate &rder ,utton #isabledN !nd If

A> Price ConsistencyI %n *lig!t Reservation <In .lig"t eservation, .irst class priceOG*!conomy class price and ,usiness class priceO:*!conomy class price= C= &ption explicit := #im n,f,b,e G= If 8ot window<N.lig"t eservationN=.!xist <:= T"en I= System/til. un N(BPProgram .ilesP)ercury InteractivePQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN D= #ialog<N7oginN=.$ctivate E= #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set NasdfN >= #ialog<N7oginN=.0in!dit<NPasswordBN=.SetSecure NIaaHb>b>cDH:GEH;cfcb:IdG;>CIcJbbf;dffCebN H= #ialog<N7oginN=.0in,utton<N&?N=.(lick J= !nd If C;= .or nO C to C; step C CC= 0indow<N.lig"t eservationN=.$ctivate C:= 0indow<N.lig"t eservationN=.0in,utton<N,uttonN=.(lick CG= 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N&rder 8o.N=.Set N&8N CI= 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in!dit<N!ditN=.Set n CD= 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in,utton<N&?N=.(lick CE= 0indow<N.lig"t eservationN=.0in adio,utton<N.irstN=.Set C>= fO0indow<N.lig"t eservationN=.0in!dit<NPriceBN=.Get+isibleText CH= 0indow<N.lig"t eservationN=.0in adio,utton<N,usinessN=.Set CJ= bO0indow<N.lig"t eservationN=.0in!dit<NPriceBN=.Get+isibleText :;= 0indow<N.lig"t eservationN=.0in adio,utton<N!conomyN=.Set :C= eO0indow<N.lig"t eservationN=.0in!dit<NPriceBN=.Get+isibleText ::= fOcdbl<mid<f,:,len <f-C=== :G= bOcdbl<mid<b,:,len <b-C=== :I= eOcdbl<mid<e,:,len <e-C=== :D= If fOG*e and bO:*e T"en :E= eporter. eport!vent ;,N esN,NPricy (onsistancy is t"ereN :>= else :H= eporter. eport!vent C,N esN,NPricy (onsistancy is 8&T t"ereN :J= !nd If

G;= 0indow<N.lig"t eservationN=.0in,utton<N,uttonX:N=.(lick GC= 0indow<N.lig"t eservationN=.#ialog<N.lig"t eservationsN=.0in,utton<N8oN=.(lick G:= 8ext B> .erify TotalI %n *lig!t Reservation <In .lig"t O Tickets * Price= eservation, Total

C= &ption !xplicit := #im t,p,tot,n G= .or nO C to C; step C I= If 8ot window<N.lig"t eservationN=.!xist <:= T"en D= System/til. un N(BPProgram .ilesP)ercury InteractivePQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN,NN,N(BPProgram .ilesP)ercury InteractivePQuickTest ProfessionalPsamplesPflig"tPappPN,NopenN E= #ialog<N7oginN=.$ctivate >= #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set NGcreddyN H= #ialog<N7oginN=.0in!dit<NPasswordBN=.SetSecure NIaaHJ:dE:cD:JfCc:G:JHC>Dad>HcDHfIGdaHeGIN J= #ialog<N7oginN=.0in,utton<N&?N=.(lick C;= !nd If CC= 0indow<N.lig"t eservationN=.$ctivate C:= 0indow<N.lig"t eservationN=.0in,utton<N,uttonN=.(lick CG= 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N&rder 8o.N=.Set N&8N CI= 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in!dit<N!ditN=.Set n CD= 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in,utton<N&?N=.(lick CE= tO0indow<N.lig"t eservationN=.0in!dit<NTicketsBN=.Get+isibleText C>= pO0indow<N.lig"t eservationN=.0in!dit<NPriceBN=.Get+isibleText CH= totO0indow<N.lig"t eservationN=.0in!dit<NTotalBN=.Get+isibleText CJ= tOcdbl <t= :;= pO(dbl<mid<p,:,len <p-C=== :C= totO(dbl<mid<tot,:,len <tot-C=== ::= If totOt*p T"en :G= eporter. eport!vent ;,N esN,N(alculation PassedN :I= else :D= eporter. eport!vent C,N esN,N(alculation .ailedN :E= !nd If :>= 8ext C> .erify *lig!t *rom - *lig!t To Com#o Bo,es <In .lig"t reservation, select an item from .ly .romB combo box and verify weat"er t"at item

available or not in .ly ToB combo box, like t"is select all items one by one in .ly .rom and verify weat"er selected items available or not in .ly To.= C= &ption explicit := #im 4tp,flig"tXapp,f,t,i,',x,y G= If 8ot 0indow<NtextBO.lig"t eservationN=.!xist <>=O True T"en I= QTPO!nvironment<NProduct#irN= D= .lig"tXappONPsamplesPflig"tPappPflig"tIa.exeN E= System/til. un QTP 6 .lig"tXapp >= #ialog<NtextBO7oginN=.$ctivate H= #ialog<NtextBO7oginN=.0in!dit<Nattac"ed textBO$gent 8ameBN=.Set NasdfN J= #ialog<NtextBO7oginN=.0in!dit<Nattac"ed textBOPasswordBN=.SetSecure NIaaDedGdafEH;e>a>DJbeeCcDICJGJdGaDIaDbEDN C;= #ialog<NtextBO7oginN=.0in,utton<NtextBO&?N=.(lick CC= !nd If C:= 0indow<NtextBO.lig"t eservationN=.$ctivate CG= 0indow<NtextBO.lig"t eservationN=.0in,utton<Nwindow idBOEN=.(lick CI= 0indow<NtextBO.lig"t eservationN=.$ctive@<NacxXnameBO)ask!d,oxN,Nwindow idBO;N=.Type N;J;JC;N CD= fO0indow<NtextBO.lig"t eservationN=.0in(ombo,ox<Nattac"ed textBO.ly .romBN=.GetItems(ount CE= .or iO ; to f-C step C C>= 0indow<NtextBO.lig"t eservationN=.0in(ombo,ox<Nattac"ed textBO.ly .romBN=.Select <i= CH= xO0indow<NtextBO.lig"t eservationN=.0in(ombo,ox<Nattac"ed textBO.ly .romBN=.Get &Property <NtextN= CJ= tO0indow<NtextBO.lig"t eservationN=.0in(ombo,ox<Nattac"ed textBO.ly ToBN,NxBO:IIN,NyBOCI>N=.GetItems(ount :;= .or 'O ; to t-C step C :C= 0indow<NtextBO.lig"t eservationN=.0in(ombo,ox<Nattac"ed textBO.ly ToBN,NxBO:IIN,NyBOCI>N=.Select <'= ::= yO0indow<NtextBO.lig"t eservationN=.0in(ombo,ox<Nattac"ed textBO.ly ToBN,NxBO:IIN,NyBOCI>N=.Get &Property <NtextN= :G= If x ZL y T"en :I= eporter. eport!vent ;,N esN,NTest PassedN :D= !lse :E= eporter. eport!vent C,N esN,NTest .ailedN :>= !nd If :H= 8ext :J= 8ext E> .erify "rder 2o &ntry in *lig!t Reservation7 <In &pen &rder dialog box, &rder 8o ob'ect accepts numeric values only.=

C= If 8ot window<N.lig"t eservationN=.!xist <:= T"en := System/til. un N(BPProgram .ilesP)ercury InteractivePQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN G= #ialog<N7oginN=.$ctivate I= #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set NasdfN D= #ialog<N7oginN=.0in!dit<NPasswordBN=.SetSecure NIaaJccaeGbb;;JE:bI>ff>fb;ceGD:IcCdHHcbIGN E= #ialog<N7oginN=.0in,utton<N&?N=.(lick >= !nd If H= 0indow<N.lig"t eservationN=.$ctivate J= 0indow<N.lig"t eservationN=.0in,utton<N,uttonN=.(lick C;= 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N&rder 8o.N=.Set N&8N CC= 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in!dit<N!ditN=.Set NaN C:= ordO0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in!dit<N!ditN=.Get+isibleText CG= If ordO NaN T"en CI= eporter. eport!vent C,N esN,N&rder 8o &b'ect is taking invalid dataN CD= else CE= 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in!dit<N!ditN=.Set NCN C>= 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in,utton<N&?N=.(lick CH= !nd If F> Get Test ata from a *lat file and use in Dt!roug! )cripting> ata riven Testing

C= #im fso,myfile := Set fsoOcreateob'ect<Nscripting.filesystemob'ectN= G= Set myfileO fso.opentextfile <N.BPgcr.txtN,C= I= myfile.skipline D= 0"ile myfile.atendofline ZL True E= xOmyfile.readline >= sOsplit <x, N,N= H= System/til. un N(BPProgram .ilesP)ercury InteractivePQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN J= #ialog<N7oginN=.$ctivate C;= #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set s<;= CC= #ialog<N7oginN=.0in!dit<NPasswordBN=.SetSecure s<C= C:= #ialog<N7oginN=.0in,utton<N&?N=.(lick CG= 0indow<N.lig"t eservationN=.(lose CI= 0end

:;> CountI !ow many Buttons and &dit #o,es availa#le in *lig!t Reservation main window7 C= If 8ot window<N.lig"t eservationN=.!xist <:= T"en := System/til. un N(BPProgram .ilesP)ercury InteractivePQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN G= #ialog<N7oginN=.$ctivate I= #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set NGcreddyN D= #ialog<N7oginN=.0in!dit<NPasswordBN=.Set NmercuryN E= #ialog<N7oginN=.0in,utton<N&?N=.(lick >= !nd If H= Set o#esc O #escription.(reate<= J= o#esc<NmicclassN=.+alue O N0in,uttonN C;= Set ,uttons O 0indow<NtextBO.lig"t eservationN=.("ild&b'ects <o#esc= CC= 8umX,uttons O ,uttons.(ount<= C:= Set o#escCO#escription.(reate<= CG= o#escC<NmicclassN=.+alueON0in!ditN CI= Set !ditboxesO0indow<NtextBO.lig"t eservationN=.("ild&b'ects <o#escC= CD= 8umX!ditboxesO editboxes.count <= CE= sumO 8umX,uttonsQ8umX!ditboxes C>= eporter. eport!vent :, N esN,NTotal ,uttonsB N6 8umX,uttons 6NTotal !dit boxesB N6 8umX!ditboxes ::> .erify searc! options in "pen "rder ialog #o,

<$fter selecting open order, G searc" options s"ould be enabled and not c"ecked, $fter selecting &rder 8o option, ot"er options s"ould be disabled, $fter selecting (ustomer 8ame, .lig"t date option enabled and &rder 8o disabled $fter selecting .lig"t date option, (ustomer 8ame enabled and &rder 8o disabled= C= If 8ot window<N.lig"t eservationN=.!xist <:= T"en := System/til. un N(BPProgram .ilesP)ercury InteractivePQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN G= #ialog<N7oginN=.$ctivate I= #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set NGcreddyN D= #ialog<N7oginN=.0in!dit<NPasswordBN=.SetSecure NIaaJed:Dbc;ebdeEEed>:EadH>d>eJJCGI>dHbJcN E= #ialog<N7oginN=.0in,utton<N&?N=.(lick >= !nd If H= 0indow<N.lig"t eservationN=.$ctivate J= 0indow<N.lig"t eservationN=.0in,utton<N,uttonN=.(lick

C;= 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.$ctivate CC= oeO0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N&rder 8o.N=.Get &Property <N!nabledN= C:= ceO0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N(ustomer 8ameN=.Get &Property <N!nabledN= CG= feO0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N.lig"t #ateN=.Get &Property<N!nabledN= CI= ocO0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N&rder 8o.N=.Get &Property <N("eckedN= CD= ccO0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N(ustomer 8ameN=.Get &Property <N("eckedN= CE= fcO0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N.lig"t #ateN=.Get &Property<N("eckedN= C>= If <oeOtrue and ceOtrue and feOtrue= and <ocON&..N and ccON&..N and fcON&..N= T"en CH= eporter. eport!vent ;,N esN,NPassN CJ= else :;= eporter. eport!vent C,N esN,N.ailN :C= !nd If ::= 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N&rder 8o.N=.Set N&8N :G= onoO0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N&rder 8o.N=.Get &Property <N("eckedN= :I= If onoON&8N T"en :D= fdO0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N.lig"t #ateN=.Get &Property <N!nabledN= :E= onoO0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N(ustomer 8ameN=.Get &Property <N!nabledN= :>= fdOfalse :H= onoOfalse :J= eporter. eport!vent ;,N esN,NPassN G;= else GC= eporter. eport!vent C,N esN,N.ailN G:= !nd If GG= 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N&rder 8o.N=.Set N&..N GI= 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N(ustomer 8ameN=.Set N&8N GD= cnO0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N(ustomer 8ameN=.Get &Property <N("eckedN= GE= If cnON&8N T"en G>= onoO0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N&rder 8o.N=.Get &Property <N!nabledN= GH= fdO0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N.lig"t #ateN=.Get &Property <N!nabledN= GJ= fdOTrue

I;= onoOfalse IC= eporter. eport!vent ;,N esN,NPassN I:= else IG= eporter. eport!vent C,N esN,N.ailN II= !nd If ID= 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N(ustomer 8ameN=.Set N&..N IE= 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N.lig"t #ateN=.Set N&8N I>= fdO0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N.lig"t #ateN=.Get &Property <N("eckedN= IH= If fdON&8N T"en IJ= onoO0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N&rder 8o.N=.Get &Property <N!nabledN= D;= cnO0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N(ustomer 8ameN=.Get &Property <N!nabledN= DC= cnOTrue D:= onoOfalse DG= eporter. eport!vent ;,N esN,NPassN DI= else DD= eporter. eport!vent C,N esN,N.ailN DE= !nd If :=> %n 4ogin ialog #o,I .erify /elp message <T"e message is YT"e password is 3)! (/ V3= C= If 8ot #ialog<N7oginN=.!xist <:= T"en := System/til. un N(BPProgram .ilesP)ercury InteractivePQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN G= !nd If I= #ialog<N7oginN=.$ctivate D= #ialog<N7oginN=.0in,utton<N1elpN=.(lick E= messageO#ialog<N7oginN=.#ialog<N.lig"t eservationsN=.Static<NT"e password is 3)! (/ V3N=.Get &Property<NtextN= >= If messageONT"e password is 3)! (/ V3N T"en H= eporter. eport!vent ;,N esN,N(orrect message N6message J= else C;= eporter. eport!vent C,N esN,N0orng message N CC= !nd If

1eb (cri!ts

:> Count all opened Browsers on des'top and close t!em allJ Set o#esc O #escription.(reate<= o#esc<NmicclassN=.+alue O N,rowserN

Set ,rowsers O#esktop.("ild&b'ects <o#esc= 8umberof,rowsers O ,rowsers.(ount<= eporter. eport!vent :,N esN,N8umber of ,rowsers areB N68umber&f,rowsers .or (ounterO; to 8umberof,rowsers-C ,rowsers<(ounter=.(lose 8ext => CountI !ow many lin's availa#le in Mercury Tours /ome Page7 Set o#esc O #escription.(reate<= o#esc<NmicclassN=.+alue O N7inkN Set 7ists O ,rowser<N0elcomeB )ercuryN=.Page<N0elcomeB )ercuryN=.("ild&b'ects <o#esc= 8umber&f7inks O 7ists.(ount<= eporter. eport!vent :,N esN,N8umber of 7inks areB N68umber&f7inks ?> .erify w!et!er t!e LGmailL lin' availa#le or not on Google /omepage &ption explicit #im o7ink, 7inks, Tot7inks, i, my7ink Set o7ink O description.(reate o7ink<NmicclassN=.value O N7inkN System/til. un N#BPProgram .ilesPInternet !xplorerPI!@P7& !.!@!N set 7inks O ,rowser<NnameBOGoogleN=.page<NtitleBOGoogleN=.("ild&b'ects<o7ink= Tot7inks O 7inks.count .or i O; to Tot7inks-C my7ink O 7inks<i=.getroproperty<NinnertextN= If mylink O NGmailN T"en reporter. eport!vent ;,NresN,N7ink Gmail availableN !nd If 8ext @> Count num#er of 4in'sI &dit Bo,es availa#le on Google /omepageJ #im o7ink Set o7inkOdescription.(reate Set o!ditOdescription.(reate o7ink<NmicclassN=.valueON7inkN o!dit<NmicclassN=.valueON0eb!ditN Set 7inksObrowser<NnameBOGoogleN=.page<NtitleBOGoogleN=.("ild&b'ects<o7in

k= Set !dit,oxesObrowser<NnameBOGoogleN=.page<NtitleBOGoogleN=.("ild&b'ects <o!dit= Tot7inksO 7inks.count Tot!dit,oxesO!dit,oxes.count msgbox Tot7inks msgbox Tot!dit,oxes eporter. eport!vent ;,N esultN,NTotal 7inks areB N6Tot7inks6NTotal edit ,oxes areB N6Tot!dit,oxes A> Count !ow many lin's availa#le in a 1e# PageDany we# pageI using Regular &,pressions> #im o7ink,7inks, Tot7inks Set o7inkO#escription.(reate o7ink<NmicclassN=.valueON7inkN Set 7inksO,rowser<NtitleBO.*N=.page<NtitleBO.*N=.("ild&b'ects<o7ink= Tot7inksO7inks.count msgbox Tot7inks eporter. eport!vent :,N esN,NTotal 7inks areB N6Tot7inks B> .erify Cost in $$perfumes7com LTest *low Li> 4aunc! $$perfumes7com Lii> )elect a product and enter some Guantity Liii> select Add to CartI capture 0nit priceI Quantity and Cost Li.> Remove M sym#ols and compare L---------------------------------- ----System/til. un N(BPProgram .ilesPInternet !xplorerPiexplore.exeN,NN,N(BP#ocuments and SettingsPgcr.G( (J$C:.,#G#JN,NopenN ,rowser<NGoogleN=.Page<NGoogleN=.Sync ,rowser<NGoogleN=.8avigate N"ttpBAAwww.''perfumes.comAN ,rowser<NGoogleN=.Page<N22 Perfumes-#iscount perfumeN=.Image<Nt"umbXCHIDX07I8PD;PS0N=.(lick ,rowser<NGoogleN=.Page<N22 Perfumes-#iscount perfumeX:N=.0eb!dit<N4uantityN=.Set NIN ,rowser<NGoogleN=.Page<N22 Perfumes-#iscount perfumeX:N=.0eb,utton<N$dd To (artN=.(lick /nitXPrice O ,rowser<NGoogleN=.Page<N22 Perfumes-#iscount perfumeXGN=.0eb!lement<N^ emove_N=.Get &Property<NinnertextN= Qty O ,rowser<NGoogleN=.Page<N22 Perfumes-#iscount

perfumeXGN=.0eb!dit<N4uantity^_N=.Get &Property<NvalueN= (ost O ,rowser<NGoogleN=.Page<N22 Perfumes-#iscount perfumeXGN=.0eb!lement<N^ emove_X:N=.Get &Property<NinnertextN= QtyO(int<Qty= /nitXPriceO(dbl <)id </nitXPrice,G== (ostO(dbl <)id <(ost, G== 3)sgbox /nitXPriceB )sgbox QtyB )sgbox (ost If (ostOQty * /nitXPrice T"en eporter. eport!vent micPass,N esN,N(ost is (orrectN !lse eporter. eport!vent mic.ail,N esN,N(ost is In(orrectN !nd If *unction To Create /TM4 Report #im StartTime,stTime, enTime #im fso, ts,int(nt, intPass,int.ail intPassO; int.ailO; (onst .or0riting O : .unction &pen.ile <str.ile8ame= StartTime O Timer stTime O Time Set fso O (reate&b'ect<NScripting..ileSystem&b'ectN= Set ts O fso.&penText.ile<str.ile8ame,:= 3&pen.ile O str.ile/ 7 (reate1eader !nd .unction ***************************** *unction To Close *ile #im ob'I!,str.ile/ 7 .unction (lose.ile < str.ile/ 7,str!nv = .ooter<str!nv= ts.close<= Set ob'I! O (reate&b'ect<NInternet!xplorer.$pplicationN= ob'I!.visible O True ob'I!.8avigate str.ile/ 7 wait<D= Set ob'I!Onot"ing !nd .unction ***********************

*unction to Clear Coo'iesD> .unction (lear(ookies<= System/til. un Niexplore.exeN 0eb/til.#elete(ookies Set ob',rowserO#escription.(reate ob',rowser<NmicclassN=.valueON,rowserN Set ob',(ount O #esktop.("ild&b'ects<ob',rowser= int,rowser(ount O ob',(ount.(ount str1wndO,rowser<NcreationtimeBON 6 int,rowser(ount=.Get &Property<N"wndN= System/til.(loseProcess,y1wnd<str1wnd= !nd .unction *********************** *unction to send &mail .unction Send)ail<= If kO; T"en 38ot"ing !lse msgsub O N GeoXPostal(ode pattern searc"Test esultsBN 6vbcr7f 6N&ne or more of t"e Test (ases .ailed.N 6vbcr7f 6NSee attac"ment for details.N !nd If Set ob'(onf O (reate&b'ect<N(#&.(onfigurationN= cdoSend/singPortO: s)ailServer8ameONsmtp.p"x.move.comN cdo$nonymousOcdo8&8! ob'(onf.fields.item<N"ttpBAAsc"emas.microsoft.comAcdoAconfigurationAsen dusingN= O cdoSend/singPort ob'(onf.fields.item<N"ttpBAAsc"emas.microsoft.comAcdoAconfigurationAsmt pserverN= O s)ailServer8ame ob'(onf.fields.item<N"ttpBAAsc"emas.microsoft.comAcdoAconfigurationAsmt paut"enticateN= O cdo$nonymous 3cdo,asic ob'(onf.fields.Item<N"ttpBAAsc"emas.microsoft.comAcdoAconfigurationAsmt pusesslN= O .alse ob'(onf.fields.Item<N"ttpBAAsc"emas.microsoft.comAcdoAconfigurationAsmt pserverportN= O :D 3ob'(onf.fields.item<N"ttpBAAsc"emas.microsoft.comAcdoAconfigurationAsen dusernameN= O NcorpP 8 ao2 N 3ob'(onf.fields.item<N"ttpBAAsc"emas.microsoft.comAcdoAconfigurationAsen dpasswordN= O NC:G?WrIDN ob'(onf.fields.Item<N"ttpBAAsc"emas.microsoft.comAcdoAconfigurationAsmt pconnectiontimeoutN= O E;

ob'(onf.fields./pdate Set ob')sg O (reate&b'ect<N(#&.)essageN= ob')sg.(onfiguration O ob'(onf ob')sg.to O Ngcreddy[gmail.comN ob')sg..rom O Ngcreddy[gmail.comN ob')sg.Sub'ect O NfGeoXPostal(ode pattern searc"N ob')sg.Text,ody Omsgsub docOstr.ilepat" ob')sg.$dd$ttac"ment<doc= ob')sg.Send Set ob')sg O 8ot"ing 8ew)ail O True !nd .unction *********************** *unction to create append e,cel .unction 7og.ile Set ob'!xcelO(reate&b'ect<N!xcel.$pplicationN= ob'!xcel.visibleO.alse ob'!xcel.workbooks.open<str.ilePat"= rOC #o /ntil len<ob'!xcel.cells<r,C==O; rOrQC 7oop ob'!xcel.cells<r,C=.valueONStep 8ameN ob'!xcel.cells<r,:=.valueONStep #escriptionN ob'!xcel.cells<r,G=.valueONTest esultsN ob'!xcel.#isplay$lerts O .alse ob'!xcel.Save ob'!xcel.Quit Set ob'!xcel O 8ot"ing !nd .unction *********************** *unction to get t!e Application &nvironment on w!ic! t!e script is running .unction Get!nv<= Set fsoO(reateob'ect<NScripting..ileSystem&b'ectN= s.ileON(BP0I8#&0SPsystemG:PdriversPetcP"ostsN

Set )y.ileOfso.&penText.ile<s.ile,C, True= #o s!nvO)y.ile. ead7ine If instr<s!nv,NP &#/(TI&8N=L; T"en Get!nvONProductionN !xit do !lseif instr<s!nv,NStagingN=L; T"en Get!nvONStagingN !xit do !lseif instr<s!nv,NQ$ )$I8T!8$8(!N=L; T"en Get!nvONQ$)N !xit do !lseif instr<s!nv,N4ap.N=L; T"en Get!nvON4apN !xit do !nd If 7oop 0"ile )y.ile.$t!nd&fStreamO.alse !nd .unction *********************** *unction To Create /TM4 Report #im StartTime,stTime, enTime #im fso, ts,int(nt, intPass,int.ail intPassO; int.ailO; (onst .or0riting O : .unction &pen.ile <str.ile8ame= StartTime O Timer stTime O Time Set fso O (reate&b'ect<NScripting..ileSystem&b'ectN= Set ts O fso.&penText.ile<str.ile8ame,:= 3&pen.ile O str.ile/ 7 (reate1eader !nd .unction

1e# )cripts-%%
0eb $pplication Testing using QTP. 0eb forms verification, &b'ect state verification, #atabase Testing and 7inks verification. :> )cript to get t!e list of lin's in Google and do spell c!ec' OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO

#im d set mwO(reate&b'ect<N0ord.$pplicationN= set dO#escription.(reate d<NmicclassN=.valueON7inkN set aO,rowser<NGoogleN=.page<NGoogleN=.c"ildob'ects<d= for iO; to a.count-C mw.0ord,asic.filenew sOa<i=.get &Property<NinnertextN= mw.0ord,asic.insert s if mw.$ctive#ocument.Spellingerrors.countL; t"en eporter. eport!vent C,NSpellingN,Nspelling error BN6s end if mw.$ctive#ocument.(lose<.alse= next mw.4uit set mwOnot"ing => )cript to c!ec' "2 t!e c!ec'#o,es in ya!oo mail in#o, OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO #im d Set dO#escription.(reate d<NmicclassN=.valueON0eb("eck,oxN Set cO,rowser<NInbox <C>= - Va"ooW )ailN=.Page<NInbox <C>= - Va"ooW )ailN=.("ild&b'ects<d= .or iOC to C; c<i=.set N&8N 8ext ?> script to select a mail !aving su#$ect L!iL or L/%L OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO nO,rowser<Nya"ooN=.Page<Nya"ooN=.0ebTable<NInboxN=. ow(ount .or iO: to n sO,rowser<Nya"ooN=.Page<Nya"ooN=.0ebTable<NInboxN=.Get(ell#ata<i,>= If lcase<trim<s==ON"iN T"en ,rowser<Nya"ooN=.Page<Nya"ooN=.0eb("eck,ox<NindexBON6i-C=.set N&8N !nd If 8ext @> *unction to send a mail OOOOOOOOOOOOOOOOOOOO .unction Send)ail<SendTo, Sub'ect, ,ody, $ttac"ment= Set otlO(reate&b'ect<N&utlook.$pplicationN= Set mOotl.(reateItem<;=

m.toOSendTo m.Sub'ectOSub'ect m.,odyO,ody If <$ttac"ment ZL NN= T"en )ail.$ttac"ments.$dd<$ttac"ment= !nd If m.Send otl.Quit Set m O 8ot"ing Set otl O 8ot"ing !nd .unction (all Send)ail<Nnages".raoIE[gmail.comN,N"iN,NT"is is test mail for tstingN,NN= $dv +,Scripts A> "pen %nternet &,plorer and navigate to ya!oo mail OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO #im ie Set ieO(reate&b'ect<NInternet!xplorer.$pplicationN= ie.+isibleOTrue ie.8avigate Nwww.ya"oomail.comN xO,rowser<N(reationTimeBO;N=.Get &Property<NtitleN= msgbox x B> *unction for Counting "#$ects from any opened we# page *unction &b'ectsX(ount<my&b'ect= #im &b'ects Set &b'ectsO#escription.(reate &b'ects<NmicclassN=.valueOmy&b'ect Set &b'ectO,rowser<NtitleBO.*N=.Page<NtitleBO.*N=.("ild&b'ects<&b'ects= Tot&b'ectsO&b'ect.(ount )sgbox Tot&b'ects &nd *unction (all &b'ectsX(ount<N0eb,uttonN= C> Create script for lin's validation and set results into an e,cel file Set ob'#escO#escription.(reate ob'#esc<NmicclassN=.valueON7inkN

Set ob'(ollO,rowser<NtitleBO.*N=.page<NtitleBO.*N=.("ild&b'ects<ob'#esc= msgbox ob'(oll.count Set ob'!xcelO(reateob'ect<N!xcel.applicationN= ob'!xcel.+isibleOTrue ob'!xcel.0orkbooks.$dd set ob'S"eetOob'!xcel.$ctiveS"eet ob'S"eet.cells<C,C=ON7ink8ameN set cCOob'S"eet.cells<C,C= cC.font.colorOvb,lue ob'S"eet.cells<C,:=ONTarget/rlN Set c:Oob'S"eet.cells<C,:= c:.font.colorOvb,lue ob'S"eet.cells<C,G=ON$ctual/rlN Set cGOob'S"eet.cells<C,G= cG.font.colorOvb,lue ob'S"eet.cells<C,I=ONStatusN Set cIOob'S"eet.cells<C,I= cI.font.colorOvb,lue .or iO; to ob'(oll.count-G> step C str8ameO,rowser<NtitleBO.*N=.page<NtitleBO.*N=.7ink<NindexBON6i=.Get o Property<NnameN= Target/rlO,rowser<NtitleBO.*N=.page<NtitleBO.*N=.7ink<NindexBON6i=.Get o Property<NurlN=

msgbox Target/rl ,rowser<NtitleBO.*N=.page<NtitleBO.*N=.7ink<NindexBON6i=.click wait<I= $ctual/rlO,rowser<NtitleBO.*N=.Get oProperty<NurlN= msgbox $ctual/rl If instr <C,Target/rl,$ctual/rl,C= L ; T"en eporter. eport!vent micPass,N7ink 8ame N6str8ame,N7ink +alidation doneN ob'S"eet.cells<iQ:,C=Ostr8ame ob's"eet.cells<iQ:,:=OTarget/rl ob's"eet.cells<iQ:,G=O$ctual/rl ob's"eet.cells<iQ:,I=ON7ink +alidation doneN Set cDO ob's"eet.cells<iQ:,I= cD.font.colorOvbGreen !lse eporter. eport!vent mic.ail,N7ink 8ame validation failN ob'S"eet.cells<iQ:,C=Ostr8ame ob's"eet.cells<iQ:,:=OTarget/rl ob's"eet.cells<iQ:,G=O$ctual/rl ob's"eet.cells<iQ:,I=ON7ink +alidation failN Set cDO ob's"eet.cells<iQ:,I= N6str8ame,N7ink

cD.font.colorOvb ed !nd If ,rowser<NtitleBO.*N=.,ack 8ext Set ob'0bookOob'!xcel.$ctive0orkbook ob'0book.Save$s N!BPgcreddy.xlsN ob'!xcel.Quit Set ob'!xcelOnot"ing

<t! real-ti%e scri!t e8a%!le

QuickTest Professional is an Industry leading and famous Testing Tool for .unctional 6 egression Testing QTP uses +, Script for scripting 0e can use QTP Tool features as well as +, Script .low (ontrol statements for inserting verification points. If we want to use +, Script .low (ontrol statements for inserting flow control statements, t"en we need to define Test results. QTP "as provided a facility to define Test esults, using Y eporterM /tility &b'ect to define test results. /sing (omments is a best practice in QTP Scripting to understand t"e code. (reating functions for modular code is a best practice and intelligent task in scripting AProgramming. using $utomation &b'ects is an useful task in QTP scripting using ,uilt-in functions and regular expressions is an useful task. QTP )cripting !as several typesB a= G/I scriptingB using scripting for G/I based $pplications b= 0eb scriptingB $utomation web based applications using vb script c= #atabase scriptingB /sing scripting for #atabase operations suc" as data comparisons and validations. d= !xcel scriptingB 1andling and using !xcel files in Test $utomation

&,cel )cripting &,amples-=


:> ata riven Testing for 4ogin "peration #y fetc!ing from an e,cel file

#im ob'!xcel, my.ile, myS"eet Set ob'!xcelO(reate&b'ect<N!xcel.$pplicationN= Set my.ileOob'!xcel.0orkbooks.&pen<N(BP#ocuments andSettingsPgcreddyP#esktopPdata.xlsN= Set myS"eetOmy.ile.0orks"eets<NS"eetCN= owsX(ountOmyS"eet.usedrange.rows.count .or iO : to owsX(ount step C System/til. un N(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN #ialog<NtextBO7oginN=.$ctivate #ialog<NtextBO7oginN=.0in!dit<Nattac"ed textBO$gent 8ameBN=.Set myS"eet.(ells<i,N$N= #ialog<NtextBO7oginN=.0in!dit<Nattac"ed textBOPasswordBN=.Set myS"eet.(ells<i,N,N= 0ait <:= #ialog<NtextBO7oginN=.0in,utton<NtextBO&?N=.(lick 0indow<NtextBO.lig"t eservationN=.(lose 8ext my.ile.(lose ob'!xcel.Quit Set ob'!xcelO8ot"ing ----------------------------------------=> ata riven Testing for 4ogin "peration #y fetc!ing Test from ane,cel file and &,port Result to t!e )ame file #im ob'!xcel, my.ile, myS"eet Set ob'!xcelO(reate&b'ect<N!xcel.$pplicationN= Set my.ileOob'!xcel.0orkbooks.&pen<N(BP#ocuments andSettingsPgcreddyP#esktopPdata.xlsN= Set myS"eetOmy.ile.0orks"eets<NS"eetCN= owsX(ountOmyS"eet.usedrange.rows.count .or iO : to owsX(ount step C System/til. un N(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN #ialog<NtextBO7oginN=.$ctivate #ialog<NtextBO7oginN=.0in!dit<Nattac"ed textBO$gent 8ameBN=.Set myS"eet.(ells<i,N$N= #ialog<NtextBO7oginN=.0in!dit<Nattac"ed textBOPasswordBN=.Set myS"eet.(ells<i,N,N= 0ait <:= #ialog<NtextBO7oginN=.0in,utton<NtextBO&?N=.(lick

ata

If 0indow<NtextBO.lig"t eservationN=.!xist<C:= T"en 0indow<NtextBO.lig"t eservationN=.(lose esultON7ogin &peration SucessfulN myS"eet.(ells<i,N(N=O esult !lse System/til.(lose#escendentProcesses esultON7ogin &peration .ailedN myS"eet.(ells<i,N(N=O esult !nd If 8ext my.ile.Save my.ile.(lose ob'!xcel.Quit Set ob'!xcelO8ot"ing -----------------------------?> L ata riven Testing for 4ogin "peration #y fetc!ing Test from ane,cel file L &,port Result and &rror message to t!e )ame file 3 #im ob'!xcel, my.ile, myS"eet Set ob'!xcelO(reate&b'ect<N!xcel.$pplicationN= Set my.ileOob'!xcel.0orkbooks.&pen<N(BP#ocuments andSettingsPgcreddyP#esktopPdata.xlsN= Set myS"eetOmy.ile.0orks"eets<NS"eetCN= owsX(ountOmyS"eet.usedrange.rows.count .or iO : to owsX(ount step C System/til. un N(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN #ialog<NtextBO7oginN=.$ctivate #ialog<NtextBO7oginN=.0in!dit<Nattac"ed textBO$gent 8ameBN=.Set myS"eet.(ells<i,N$N= #ialog<NtextBO7oginN=.0in!dit<Nattac"ed textBOPasswordBN=.Set myS"eet.(ells<i,N,N= 0ait <:= #ialog<NtextBO7oginN=.0in,utton<NtextBO&?N=.(lick If 0indow<NtextBO.lig"t eservationN=.!xist<C:= T"en 0indow<NtextBO.lig"t eservationN=.(lose esultON7ogin &peration SucessfulN myS"eet.(ells<i,N(N=O esult !lse

ata

!rrorX)essage O #ialog<N7oginN=.#ialog<N.lig"t eservationsN=.Static<N$gent name must be atN=.Get &Property<NtextN= System/til.(lose#escendentProcesses

esultON7ogin &peration .ailedN myS"eet.(ells<i,N(N=O esult myS"eet.(ells<i,N#N=O!rrorX)essage !nd If 8ext my.ile.Save my.ile.(lose ob'!xcel.Quit Set ob'!xcelO8ot"ing -----------------------------------------------------------------@> L"pen : to :; "rders in *lig!t Reservation window and capture "rder 2um#ers and Customer 2ames 3!xport to an !xcel .ile #im ob'!xcel,my.ile,myS"eet,i Set ob'!xcel O (reate&b'ect<N!xcel.$pplicationN= Set my.ileOob'!xcel.0orkbooks.&pen<N(BP#ocuments andSettingsPgcreddyP#esktopPdata.xlsN= Set myS"eet O my.ile.0orks"eets<NS"eet:N= rowOC myS"eet.(ells<row,N$N=ON&rder8oN myS"eet.(ells<row,N,N=ON(ustomer8ameN If 8ot 0indow<N.lig"t eservationN=.!xist<G= T"en System/til. un N(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN,NN,N(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPN,NopenN #ialog<N7oginN=.$ctivate #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set NasdfN #ialog<N7oginN=.0in!dit<NPasswordBN=.SetSecure NId;a:DIE:GfcfHdC;EG;fC;bEcaHe>>Efcbc;>C>N #ialog<N7oginN=.0in,utton<N&?N=.(lick !nd If .or i O C to C; Step C 0indow<N.lig"t eservationN=.$ctivate 0indow<N.lig"t eservationN=.0in,utton<N,uttonN=.(lick 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N&rder 8o.N=.Set N&8N 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in!dit<N!ditN=.Set i 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in,utton<N&?N=.(lick (ustomerX8ame O 0indow<N.lig"t eservationN=.0in!dit<N8ameBN=.Get &Property<NtextN= rowOrowQC myS"eet.(ells<row,N$N= O i

myS"eet.(ells<row,N,N= O (ustomerX8ame 8ext my.ile.Save my.ile.(lose ob'!xcel.Quit Set ob'!xcel O8ot"ing

)ystem Administration
:> Getting 4ocal Computer %nformation Setob'(omputerO(reate&b'ect<NS"ell.7ocal)ac"ineN= 0script.!c"oN(omputernameBN6ob'(omputer.)ac"ine8ame 0script.!c"oNS"utdownallowedBN6ob'(omputer.IsS"utdown$llowed 0script.!c"oN.riendly/IenabledBN6ob'(omputer.Is.riendly/I!nabled 0script.!c"oNGuestaccessmodeBN6ob'(omputer.IsGuest$ccess)ode 0script.!c"oNGuestaccountenabledBN6X ob'(omputer.IsGuest!nabled<;= 0script.!c"oN)ultipleusersenabledBN6X ob'(omputer.Is)ultiple/sers!nabled 0script.!c"oN&fflinefilesenabledBN6X ob'(omputer.Is&ffline.iles!nabled 0script.!c"oN emoteconnectionsenabledBN6X ob'(omputer.Is emote(onnections!nabled 0script.!c"oN/ndockenabledBN6ob'(omputer.Is/ndock!nabled

=> Restart a Computer str(omputerONatl-dc-;CN Setob'0)IServiceOGet&b'ect<NwinmgmtsBNX 6Ncimpersonation7evelOimpersonate,<S"utdown=dWPPN 6X str(omputer6NProotPcimv:N= Setcol&peratingSystemsOob'0)IService.!xecQueryX <NSelect*from0inG:X&peratingSystemN= .or!ac"ob'&peratingSystemincol&peratingSystems ob'&peratingSystem. eboot<= 8ext ?> )!ut own a Computer str(omputerON.N Setob'0)IServiceOGet&b'ectX <NwinmgmtsBcimpersonation7evelOimpersonate,<S"utdown=dPPN 6X str(omputer6NProotPcimv:N=

Setcol&peratingSystemsOob'0)IService.!xecQueryX <NSelect*from0inG:X&peratingSystemN= .or!ac"ob'&peratingSystemincol&peratingSystems ob'&peratingSystem.0inG:S"utdown<C= 8ext @> Modify )ystem )tartup elay str(omputerON.N Setob'0)IServiceOGet&b'ect<NwinmgmtsBNX 6Ncimpersonation7evelOimpersonatedWPPN6str(omputer6NProotPcimv:N= SetcolStartup(ommandsOob'0)IService.!xecQueryX <NSelect*from0inG:X(omputerSystemN= .or!ac"ob'Startup(ommandincolStartup(ommands ob'Startup(ommand.SystemStartup#elayOC; ob'Startup(ommand.PutX 8ext

M) 1ord )cripts
:> create a word document and write some data OOOOOOOOOOOOOOOOOOOO dim mw set mwO(reate&b'ect<N0ord.$pplicationN= mw.#ocuments.$dd mw.selection.typetext N"elloN mw.$ctive#ocument.Save$s NeBPgcreddy.docN mw.4uit set mwOnot"ing => Create wordI Create ta#le and write all t!e services names OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO Set mw O (reate&b'ect<N0ord.$pplicationN= mw.+isible O True Set dc O mw.#ocuments.$dd<= Set ob' ange O dc. ange<= dc.Tables.$dd ob' ange,C,G Set ob'Table O dc.Tables<C= xOC str(omputer O N.N Set wmsOGet&b'ect<NwinmgmtsBPPN 6 str(omputer 6 NProotPcimv:N=

Set colItems O wms.!xecQuery<NSelect * from 0inG:XServiceN= .or !ac" s in colItems If x L C T"en ob'Table. ows.$dd<= !nd If ob'Table.(ell<x, C=. ange..ont.,old O True ob'Table.(ell<x, C=. ange.Text O s.8ame ob'Table.(ell<x, :=. ange.text O s.#isplay8ame ob'Table.(ell<x, G=. ange.text O s.State xOxQC 8ext

?> script to display all t!e doc files in all t!e drives in t!e system OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO #im mw Set mwO(reate&b'ect<N0ord.$pplicationN= Set fsOcreateob'ect<NScripting..ileSystem&b'ectN= Set dOfs.#rives mw..ileSearc"..ile8ameON*.docN .or eac" dr in d msgbox dr mw..ileSearc".7ookInOdr mw..ileSearc".Searc"Sub.oldersOTrue mw..ileSearc".!xecute .or eac" i in mw..ileSearc"..ound.iles print i Set fOfs.Get.ile<i= print f.8ame6N N6f.Si%e6N N6f.#ate(reated print N-------------------------------------------------------------------N 8ext 8ext mw.Quit

@> Counting t!e num#er of times a word appears in a word document OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO

Set ob'0ordO(reate&b'ect<N0ord.$pplicationN= Set myfileOob'0ord.#ocuments.&pen <N(BP#ocuments and SettingsPgcr.G( (-J$C:.,#G#JP#esktopPxy%.docN=

strTextONgcreddyN str eadOmyfile.(ontent Set eg!xpOnew regexp regexp.ignorecaseOTrue regexp.globalOTrue regexp.patternOstrText Set matc"esOregexp.execute<str ead= matc"es.oundOmatc"es.count msgbox matc"esfound myfile.close set ob'.soO8ot"ing

.B)cript to read 3M4

3M4 )cripts

Set xml#oc O (reate&b'ect<T)sxml:.#&)#ocumentU= xml#oc.load<T#BPgcreddy.xmlU= Set !lem7ist O xml#oc.get!lements,yTag8ame<TsegmentU= filepat" O !lem7ist.item<;=.get$ttribute<TfilePat"U= )sg,ox filepat" Set !lem7ist O xml#oc.get!lements,yTag8ame<TdescriptionU= plot O !lem7ist.item<;=.Text )sg,ox plot /ow Get Root &lement attri#uteNs value from 3M4 file .unction Get oot!lement$ttribute+alue.rom@)7<s.ile8ame0it"Pat",s $ttribute= Y 0"y we need to $## : because eac" attribute followed by <O= and <T= i7en&f+alueOlen<s$ttribute= Q : Set doc O @)7/til.(reate@)7<= doc.7oad.ile s.ile8ame0it"Pat" Set root O doc.Get oot!lement<= I. instr<C,root,s$ttribute= ZO ; t"en eporter. eport!vent mic.ail,s$ttribute,U8ot .ound in @)7 file.U exitrun<;= !lse sStartPosOinstr<C,root,s$ttribute= Q i7en&f+alue s!ndPosOinstr<sStartPos,root,UNUN= Get oot!lement$ttribute+alue.rom@)7Omid<root,sStartPos,s!ndPos F sStartPos=

!nd if !nd .unction msgbox<Get oot!lement$ttribute+alue.rom@)7<TcBPtempPgcreddy.xm lU,U)erc"antIdU==

QTP (&ills

C )teps to %mprove )'ills in QTP %> QTP Testing Process In order to use QTP I#! properly, you s"ould "ave good command on QTP Testing process. a> Planning a= $naly%ing t"e $/T b= Implementing $utomation .ramework c= (reatingASelecting Test cases d= (ollecting Test #ata e= $utomation Infrastrucure development f= Tool settings (onfiguration 6 Globali%ation #> Generating t!e #asic Test C= ?eyword driven met"odologyAS"ared ob'ect repository met"odAPreparing t"e script manually := #escriptive programmingAProgrammatic #escriptions i= !ntering Programmatic #escriptions #irectly into Statements ii= /sing #escription &b'ects for Programmatic #escriptions iii= etrieving ("ild &b'ects iv= /sing t"e Index Property in Programmatic #escriptions c> &n!ancing t!e Test a= $dding (omments b= (reating ("eckpoints Programmatically c= Sync"roni%ation d= Parameteri%ation e= Inserting Programmatic statements f= !n"ancing Tests wit" t"e windows $PI g= (alling .unctions andAor $ctions d> e#ugging t!e Test

e> Running t!e Test f> Analy(ing t!e Test Results

g> Reporting

efects

a. )anual #efect eporting b. Tool based #efect eporting c. Integration wit" Quality (enter %%> .B )cript +bScript is t"e QTP Tool #efault Scripting 7anguage for applaying Progamming 7ogic, so learn +bscript indept". ,elow fundamentals 6 .eatures are ImportantB a> .B)cript *undamentals C=Introduction a= Scripting 7anguages vs. Programming 7anguages b= ,asic .eatures of +,Script c= 1osting !nvironments 6 Script !ngines d= (rating 6 running a Script := +ariables and (onstants a= +,Script data types b= #eclaring +ariables and &ption !xplicit Statement c= $ssigning +alues to +ariables d= Scalar +ariables and $rray +ariables e= #ynamic $rrays, #imensional $rrays f= (onstants g= +ariables +s. (onstants G= +,Script &perators a= &perator Precedence b= $rit"metic &perators c= (omparison &perators d= (oncatenation &perators e= 7ogical &perators I= .low (ontrol <I. (onditional Statements= a= +,Script (onditional Statements b= unning a state if condition is true <Single line Syntax= c= unning a block of Statements if (ondition is true d= unning (ertain Statements if a (ondition is True and unning &t"ers if a (ondition is .alse e= #eciding $mong Several $lternatives <I...!lse IfS=

f= !xecuting a certain block of statements w"en two A more conditions are True <8ested If...= g= #eciding $mong Several $lternatives <Selct case Statement= D= .low (ontrol <II. 7ooping t"roug" t"e code= a= #o...7oop <7oops w"ile or until a condition is True.= b= 0"ile...0end <7oops w"ile a condition is True.= c= .or...8extB /ses a counter to run statements a specified number of times. d= .or !ac"...8ext < epeats a group of statements for eac" item in a collection or eac" element of an array.= e= 8ested 7oops E= +,Script Procedures a= Sub Procedures b= .unction Procedures c= (reating 6 (alling Procedures >= (oding (onventions a= (onstant 8aming (onventions b= +ariable 8aming (onventions c= +ariable Scope Prefixes d= &b'ect 8aming (onventions e= (ode (ommenting (onventions #> Advanced .B)cript C= +,Script Intrinsic <Pre-#efined= .unctions a= (onversions b= #atesATimes c= .ormatting Strings d= InputA&utput e= )at" f= )iscellaneous g= ounding "= Strings i= +ariants := egular !xpressions a= /ses for egular !xpressions b= egular !xpression Syntax c= ,uild a egular !xpression d= &rder of Precedence e= &rdinary ("aracters f= ("aracter )atc"ing g= $nc"ors

"= $lternation and Grouping i= ,ackreferences '= egular !xpression < eg!xp= &b'ect G= .ile System &perations a= (omputer .ile System b= 0orking wit" #rives and .olders c= 0orking wit" .lat .iles d= 0orking wit" 0ord #ocs e= 0orking wit" !xcel S"eets I= #atabase &perations a= $ctive@ #ata &b'ects b= $#&#, (onnection &b'ect 6 ecordset &b'ect c= Test #atabase (reation 6 (ollecting Test #ata d= #atabases (onnections <)s-$ccess, SQ7 Server and &racle= e= #ata #riven Testing by fetc"ing #ata from a #atabase f= #ata (omparisons D= )et"ods, &b'ects and (lasses a= +,Script Global )et"ods b= QTP )et"ods c= .ileSystem&b'ect d= #ictionary &b'ect e= (lasses E= !rror 1andling a= !rror 1andling Guidelines b= !rror 1andling in QuickTest Professional c= !rror Preventing d= Sync"roni%ation e= QTP !xit Statements f= +,Script error "andling vs. ecovery Scenarios g= &n !rror Statement "= !rr &b'ect %%%> Automation *ramewor' $utomation .ramework is a Systamatic $pproac" for $utomating, SoftwareTesting Process. In order to (reate 6 un Tests as well oragani%ing 6 )anaging $utomation esources, a well defined .ramework re4uired.

.ramework may vary from one company to anot"er. ,elow concepts are important to learnB o Test $utomation .ramework o Types of .ramework o ?eyword #riven .ramework o .ramework Structure o #eveloping a obust $utomation .ramework o Implementing 6 )anaging $utomation esources %.> C"M+ C"M Tec!nologies 0"en working wit" QTP, It is important to know, )icrosoft $pplications likeB o o o o )S !xcel, )s 0ord, &utlook !xpress and Internet !xplorer

.> 3M4 @)7 is an extremely popular and useful format. It can be used in several areas in QTP. !xB o !xporting ob'ects, o !nvironment +ariables, o #ata driven Testing o #ata transporting etc. .%> )Q4 SQ7 ?nowledge is "ig"ly recomendable in order to perform #atabase Testing using QTP ,elow concepts are importantB o #atabase .undamentals o #ata (reation 6 !xporting o #atabase (onnections o Select Statements .%%> /TM4I "M In order to work wit" 0eb based $pplications, It is important to femiliar wit" web tec"nologies likeB o 1T)7, #1T)7 o .las"

o 1TTP like Protocols o #&) <#ocumentation &b'ect )odel=

&rror /andling in QTP


&rror /andling8 !rror "andling refers to t"e anticipation, detection, and resolution of programming, application, and communications errors. 0it"in every Script we "ave to t"ink about possible exceptions and "ow to "andle t"em. !specially in t"e uppermost layers of t"e script, it is important to "andle all exceptions. &rror /andling in Quic'Test Professional8 QTP and +,Script give t"e Test !ngineer some tools to "andle errors and !xceptions. &rror Preventing8 $ good met"od for using error "andling is to try to prevent t"em. 0"en an error occurred, eport it in detail. 0"en working wit" G/I ob'ects, use t"e 0indow.!xist property. !very IfST"en..!nd If statement "as t"e !lse part, t"e same for Select (ase. /se (ase !lse. &rror /andling Met!ods in QTP and .B )cript8 a= b= c= d> Sync"roni%ation !xist Property ecover Scenarios "n &rror )tatement

0it"out an &n !rror statement, any run-time error t"at occurs is fatalB an error message is displayed, and execution stops. 0"enever possible, you use structured exception "andling in your code, rat"er t"an resorting to unstructured exception "andling and t"e &n !rror statement. Parts8

GoToline !nables t"e error-"andling routine t"at starts at t"e line specified in t"e re4uired line argument. T"e line argument is any line label or line number. If a run-time error occurs, control branc"es to t"e specified line, making t"e error "andler active. T"e specified line must be in t"e same procedure as t"e &n !rror statement, or a compile-time error will occur. GoTo ; #isables enabled error "andler in t"e current procedure and resets it to 8ot"ing. GoTo -: #isables enabled exception in t"e current procedure and resets it to 8ot"ing. Resume 2e,t Specifies t"at w"en a run-time error occurs, control goes to t"e statement immediately following t"e statement w"ere t"e error occurred, and execution continues from t"at point. /se t"is form rat"er t"an &n !rror GoTo w"en accessing ob'ects. on &rror Resume 2e,t &,ample:8 #im a aOC b-: )sg,ox a Q b 3 displays result wit"out s"owing error &,ample=8 .unction Sum<8umC, 8um:= If Is8umeric<8umC= O .alse &r Is8umeric<8um:= O .alse T"en &n !rror esume 8ext !rr. aise vb&b'ect!rror Q C;;, NSum .unctionN, X N&ne or more parameters are invalid.N !xit .unction

!nd If Sum O 8umC Q8um: !nd .unction (all Sum<NgcreddyN,NQTPN= 3(omes out wit"out s"owing error (all Sum<C;;,:;;= 3 returns sum of C;;,:;; as G;; e> &rror "#$ect T"e !rr ob'ect is an intrinsic ob'ect wit" global scope R t"ere is no need to create an instance of it in your code. T"e properties of t"e !rr ob'ect are set by t"e generator of an error R +isual ,asic, an $utomation ob'ect, or t"e +,Script programmer. T"e default property of t"e !rr ob'ect is 8umber. !rr.8umber contains an integer and can be used by an $utomation ob'ect to return an S(&#!. 0"en a run-time error occurs, t"e properties of t"e !rr ob'ect are filled wit" information t"at uni4uely identifies t"e error and information t"at can be used to "andle it. To generate a run-time error in your code, use t"e aise met"od. T"e !rr ob'ect3s properties are reset to %ero or %ero-lengt" strings <NN= after an &n !rror esume 8ext statement. T"e (lear met"od can be used to explicitly reset !rr. &,ample8 &n !rror esume 8ext !rr. aise E 3 aise an overflow error. )sg,ox <N!rror ] N 6 (Str<!rr.8umber= 6 N N 6 !rr.#escription= !rr.(lear 3 (lear t"e error. &rr "#$ect Properties and Met!ods Properties #escription Property 1elp(ontext Property

1elp.ile Property 8umber Property Source Property Met!ods (lear )et"od aise )et"od

f>

&,it )tatement

"pen ?; to @; "rders in *lig!t Reservation 1indowI if some records not availa#le !andle t!e situation &ption !xplicit #im &rderX8umber If 8ot 0indow<N.lig"t eservationN=.!xist<G= T"en System/til. un N(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN,NN,N(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPN,NopenN #ialog<N7oginN=.$ctivate #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set NgcreddyN #ialog<N7oginN=.0in!dit<NPasswordBN=.SetSecure NIc:eCeEDbf:JJIGGJGbEJI;fCCEdGD:GCceDfb>eN #ialog<N7oginN=.0in,utton<N&?N=.(lick !nd If .or &rderX8umberO G; to I; step C 0indow<N.lig"t eservationN=.$ctivate 0indow<N.lig"t eservationN=.0in,utton<N,uttonN=.(lick 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N&rder 8o.N=.Set N&8N 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in!dit<N!ditN=.Set &rderX8umber 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in,utton<N&?N=.(lick If 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.#ialog<N.lig"t eservationsN=.!xist<G= T"en 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.#ialog<N.lig"t

eservationsN=.0in,utton<N&?N=.(lick 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in,utton<N(ancelN=.(lick eporter. eport!vent mic0arning,N esN, N/p to N6 &rderX8umber-C 6N &rder only availableN !xit .or !nd If 8ext

.B )cript for QTP


It explains +, Script in QTP orientation, It covers all most all +, Script .undamentals and .eatures. It describes, +ariables, constants declarations, usage of operators, +, Script flow control statements, Procedures, (oding conventions, egular !xpressions, .ile system &perations, #atabase &perations etc..

)cripting .s Programming
)cripting 4anguage8 Scripting 7anguage is a 7ig"t weig"t language, no need to compile t"em separately, during execution t"ey automatically compile an run. C= It is an Interpreter based 7anguage := Interpreter converts "ig" level instructions into mac"ine language line by line G= It doesnMt create executable file. I= 8o need to compile t"e program D= It takes less code for ac"ieving tasks. E= It greatly reduces development time >= It reduces maintenance of cost H= Implicit Support of #ata Types. J= 7imited support for /ser Interface #esign C;= 7imited or 8o Support for Grap"ics #esign !xample Scripting 7anguages areB S"ell, Perl, +, Script, 2ava Script, Pyt"on, Programming 4anguage8 uby, exx, P1P !tc..

C= It is a compiler based 7anguage. := (ompiler converts t"e w"ole program in single s"ort into mac"ine language. G= It (reates .exe file. 8eed to compile t"e program I= It takes numerous lines of code D= It increases development time >= It Increases maintenance of cost H= !xplicit support of #ata Types J= ic" support for /ser Interface #esign C;= ic" Support for Grap"ics #esign !xample Programming 7anguages areB (&,&7, ,asic, (, (QQ, +(QQ, +, !tc...

+B (cri!t Funda%entals -nd Features


.B )cript !as several purposes8 a= (lient side scripting in t"e 0eb <1T)7=<,rowser= <I!= b= Server side scripting in t"e 0eb <$SP= <0eb Server=<IIS= c= 8etwork $dministration <Server &S= <0S1-0indows Script 1ost= d= System $dministration <(lient &S= <0S1-0indows Script 1ost= e= Test $utomation <QTP= <QTP= "ur QTP Point of view #elow are t!e learning o#$ectives8 a= $dding (omments b= #ata types c= #eclarations <+ariables <Scalar and $rray=,(onstants== d= +, Script &perators i= $rit"metic &perators <Including (oncatination operators= ii= (omparison iii= 7ogical e= .low (ontrol Statements <a. (onditional Statements= i= If...T"en...!lse...!nd If ii= Select (ase...(ase...(ase !lse...!nd Select

f= .low (ontrol Statements <b. 7oop Statements= i= .or...8ext ii= 0"ile...0end iii= #o 0"ileA/ntil...7oop i+= .or !ac"...8ext g= +, Script Procedures<.unctions= i= ,uilt-in .unctions<String, $rray, )at",#ate 6 Time, (onversion functions etc...= ii= /ser defined C= Sub Procedures := .unction Procedures "= (oding (onvensions -------------------i= .ile System &perations '= !xcel s"eet &perations k= database &perations l= &t"er +, Script &b'ects i= #ictionary &b'ect ii= 0ord iii= Internet !xplorer &b'ect i+= eg!xp &b'ect m= egular expressions

k= !rror 1andling

.B )cript .aria#les
#efinition C=B +ariable is a named memory location for storing program information #efinition :=B $ variable is a convenient place"older t"at refers to a computer memory location w"ere we can store program information t"at may c"ange during t"e time our script is running. Purpose of .aria#le8

a= (omparing values !xampleB #im x,y,a xOC;; yOC;; aOxOy )sgbox a 3It returns True b= 1olding Program !xampleB (ostOTickets*Price c= Passing parameters d= To store data t"at returned by functions !xampleB my#ateO8ow Y It returns current data 6 time e= To "old data !xampleB my8ameOUgcreddyU eclaring .aria#les 0e declare variables explicitly in our script using t"e #im statement, t"e Public statement, and t"e Private statement. .or exampleB #im city #im x 0e declare multiple variables by separating eac" variable name wit" a comma. .or !xampleB #im x, y, city, gcreddy 0e can also declare a variable implicitly by simply using its name in our script. T"at is notgenerally a good practice because we could misspell t"e variable name in one or more places, causing unexpected results w"en our script is run. .or t"at reason, t"e &ption !xplicit statement is available to re4uire explicit declaration of all variables. T"e &ption !xplicit statement s"ould be t"e first statement in our esult

script. "ption &,plicit )tatement .orces explicit declaration of all variables in a script. &ption !xplicit 3 .orce explicit variable declaration. #im )y+ar 3 #eclare variable. )yInt O C; 3 /ndeclared variable generates error. )y+ar O C; 3 #eclared variable does not generate error. 2aming Restrictions for .aria#les +ariable names follow t"e standard rules for naming anyt"ing in +,Script. $ variable nameB a= )ust begin wit" an alp"abetic c"aracter. #im abc 3 ig"t #im Jab 30rong #im abJ 3 ig"t b= (annot #im abc #im ab.c #im ab-c #im ab c #im abXc contain an embedded period. 3 ig"t 3worng 3wrong 3wrong 3 ig"t

c= )ust not exceed :DD c"aracters. d= )ust be uni4ue in t"e scope in w"ic" it is declared. )cope of .aria#les $ variable3s scope is determined by w"ere we declare it. 0"en we declare a variable wit"in a procedure, only code wit"in t"at procedure can access or c"ange t"e value of t"at variable. If we declare a variable outside a procedure, we make it recogni%able to all t"e procedures in our script. T"is is a script-level variable, and it "as script-level scope. !xampleB #im x,y,%

xOC; yO:; %OxQy msgbox % 3 eturns G; .unction res #im a,b,c aOG; bOI; cOaQbQy msgbox c 3 eturns J; !nd .unction (all res 4ife Time of .aria#les T"e lifetime of a variable depends on "ow long it exists. T"e lifetime of a script-level variable extends from t"e time it is declared until t"e time t"e script is finis"ed running. $t procedure level, a variable exists only as long as you are in t"e procedure. Assigning .alues to .aria#les +alues are assigned to variables creating an expression as followsB T"e variable is on t"e left side of t"e expression and t"e value you want to assign to t"e variable is on t"e rig"t. .or exampleB $ O :;; (ity O T1yderabadU @OC;;B VO:;; )calar .aria#les and Array .aria#les $ variable containing a single value is a scalar variable. $ variable containing a series of values, is called an array variable. $rray variables and scalar variables are declared in t"e same way, except t"at t"e declaration of an array variable uses parent"eses <= following t"e variable name.

!xampleB #im $<G= $lt"oug" t"e number s"own in t"e parent"eses is G, all arrays in +,Script are %ero-based, so t"is array actually contains I elements. 0e assign data to eac" of t"e elements of t"e array using an index into t"e array. ,eginning at %ero and ending at I, data can be assigned to t"e elements of an array as followsB $<;= $<C= $<:= $<G= O O O O :DE G:I C;; DD

Similarly, t"e data can be retrieved from any element using an index into t"e particulararray element you want. .or exampleB Some+ariable O $<I= $rrays aren3t limited to a single dimension. 0e can "ave as many as E; dimensions, alt"oug" most people can3t compre"end more t"an t"ree or four dimensions. In t"e following example, t"e )yTable variable is a two-dimensional array consisting of E rows and CC columnsB #im )yTable<D, C;= In a two-dimensional array, t"e first number is always t"e number of rows5 t"e secondnumber is t"e number of columns. ynamic Arrays 0e can also declare an array w"ose si%e c"anges during t"e time our script is running. T"is is called a dynamic array. T"e array is initially declared wit"in a procedure using eit"er t"e #im statement or using t"e e#im statement. 1owever, for a dynamic array, no si%e or number of dimensions is

placed inside t"e parent"eses. .or exampleB #im )y$rray<= e#im $not"er$rray<= To use a dynamic array, you must subse4uently use e#im to determine t"e number of dimensions and t"e si%e of eac" dimension. In t"e following example, e#im sets t"e initial si%e of t"e dynamic array to :D. $ subse4uent e#im statement resi%es t"e array to G;, but uses t"e Preserve keyword to preserve t"e contents of t"e array as t"e resi%ing takes place. e#im )y$rray<:D= e#im Preserve )y$rray<G;= T"ere is no limit to t"e number of times we can resi%e a dynamic array, alt"oug" if we make an array smaller, we lose t"e data in t"e elimina

.B )cript "perators
&perators are used for performing mat"ematical, comparison and logical operations. +, Script "as a full range of operators, including arit"metic operators, comparisonoperators, concatenation operators, and logical operators. (omparison operators all "ave e4ual precedence5 t"at is, t"ey are evaluated in t"e left-to-rig"t order in w"ic" t"ey appear. $rit"metic and logical operators are evaluated in t"e following order of precedence. :> Arit!metic "perators8 &perator #escription C= !xponentiation &perator DO> exponent

aises a number to t"e power of an

:= )ultiplication &perator D5> )ultiplies two numbers.

G= #ivision &perator D+> #ivides two numbers and returns a floatingpoint result. I= Integer #ivision &perator DP> #ivides two numbers and returns an integer result. D= Mod &perator #ivides two numbers and returns only t"e remainder. E= $ddition &perator DH> Sums two numbers. >= Subtraction &perator D-> .inds t"e difference between two numbers or indicates t"e negative value of a numeric expression. H= (oncatenation &perator D-> .orces string concatenation of two expressions. &,ample8 #im a,b,c aOC; bOG cOa`b msgbox c 3C;;; cOa*b msgbox c 3G; cOaAb msgbox c 3G.GGGGGGGG cOaPb msgbox c 3G cOa mod b msgbox c 3C cOa-b msgbox c 3> #im a,b,c aOC;

bO: cOG dOc*a`b 3cOaQb msgbox d 3C;;; Addition DH> operator #im a,b,c aOC; bO: cOaQb msgbox c 3C: <if bot" are numeric, t"en it adds= aONC;N bO: cOaQb msgbox c 3C: <one is string anot"er numeric, t"en it adds= aONC;N bON:N cOaQb msgbox c 3C;: <if bot" are strings, t"en it concatenates= aON"yderaN bONbadN cOaQb msgbox c 3"yderabad aONgaganN bO: cOaQb msgbox c 3error Concatenation "perator #im a,b,c aOC; bO: cOa6b msgbox c 3C;: aONC;N

bO: cOa6b msgbox c 3C;: aONC;N bON:N cOa6b msgbox c 3C;: aON"yderaN bONbadN cOa6b msgbox c 3C;: => Comparison "perators /sed to compare expressions. &perator #escription C= O <!4ual to= /sed to compare expressions. := ZL <8ot e4ual to= /sed to compare expressions. G= Z 7ess t"an I= L Grater t"an D= ZO 7ess t"an or e4ual to E= LO Greater t"an or e4ual to >= Is &b'ect e4uivalence &,ample8 #im x,y,% xOC; yO:; %OxOy )sgbox % 3.alse xOC; yO:; %OxLy )sgbox % 3.alse xOC; yO:; %OxLOy )sgbox % 3.alse

xOC; yO:; %OxZLy )sgbox % 3True xOC; yO:; %OxZy )sgbox % 3True xOC; yO:; %OxZOy )sgbox % 3True ?> Concatenation "perators &perator #escription C= $ddition &perator <Q= Sums two numbers If T"en C= ,ot" expressions are numeric $dd. := ,ot" expressions are strings (oncatenate. G= &ne expression is numeric and t"e ot"er is a string $dd. := (oncatenation &perator <6= .orces string concatenation of two expressions.

@> 4ogical "perators &perator #escription Syntax C= 8ot Performs logical negation on an expression resultO 8ot expression := $nd Performs a logical con'unction on two expressions. resultO expressionC $nd expression: G= &r Performs a logical dis'unction on two expressions. resultO expressionC &r expression: I= @or Performs a logical exclusion on two expressions. resultO expressionC @or expression: D= !4v Performs a logical e4uivalence on two expressions. resultO expressionC !4v expression:

E= Imp Performs a logical implication on two expressions. resultO expressionC Imp expression:

Methods

%nput and "ut Put "perations


%nputBo, *unction #isplays a prompt in a dialog box, waits for t"e user to input text or click a button, and returns t"e contents of t"e text box. &,ample8 #im Input Input O Input,ox<N!nter your nameN= )sg,ox <NVou enteredB N 6 Input= MsgBo, *unction #isplays a message in a dialog box, waits for t"e user to click a button, andreturns a value indicating w"ic" button t"e user clicked. &,ample8 #im )y+ar )y+ar O )sg,ox <N1ello 0orldWN, ED, N)sg,ox !xampleN= )y+ar contains eit"er C or :, depending on w"ic" button is clicked.

$onditional (tate%ents

$lo* Control 1Con%itional Statements#


1e can control the #low o# our scri!t with conditional state%ents and loo!ing state%ents. >sing conditional state%ents, we can write +B(cri!t code that %a&es decisions and re!eats actions. The #ollowing conditional state%ents are available in +B(cri!t2 "# 0f2T)en23lse Statement &# Select Case Statement Making Decisions 4sing 0f555T)en5553lse The "#...Then...7lse state%ent is used to evaluate whether a condition is True or False and, de!ending on the result, to s!eci#y one or %ore state%ents to run. >sually the condition is an e8!ression that uses a co%!arison o!erator to co%!are one value or variable with another.

"#...Then...7lse state%ents can be nested to as %any levels as you need. "# Running a Statement if a Con%ition is True 1single statement# To run only one state%ent when a condition is True, use the single-line synta8 #or the "#...Then...7lse state%ent. Di% %yDate %yDate A N5:36:OPN "# %yDate G 4ow Then %yDate A 4ow &# Running Statements if a Con%ition is True 1multiple statements# To run %ore than one line o# code, we %ust use the %ulti!le-line /or bloc&0 synta8. This synta8 includes the 7nd "# state%ent. Di% 8 8A 5L "# 8;3L Then %sgbo8 @8 value is2 @.8 %sgbo8 @Bye Bye@ 7nd "# '# Running Certain Statements if a Con%ition is True an% Running Ot)ers if a Con%ition is $alse 1e can use an "#...Then...7lse state%ent to de#ine two bloc&s o# e8ecutable state%ents2 one bloc& to run i# the condition is True, the other bloc& to run i# the condition is False. 78a%!le2 Di% 8 8A "n!utbo8 /@ 7nter a value@0 "# 8;3LL Then Msgbo8 @Qello =.$.Reddy@ Msgbo8 @R is a Big 4u%ber@ Msgbo8 @R value is2 @.R 7lse Msgbo8 @=$R@ Msgbo8 @R is a (%all 4u%ber@ Msgbo8 @R value is2 @.R 7nd "# (# Deci%ing 6et*een Se!eral Alternati!es - variation on the "#...Then...7lse state%ent allows us to choose #ro% several alternatives. -dding 7lse"# clauses e8!ands the #unctionality o# the "#...Then...7lse

state%ent so we can control !rogra% #low based on di##erent !ossibilities. 78a%!le2 Di% 8 8A "n!utbo8 /@ 7nter a value@0 "# 8;L and 8GA3LL Then Msgbo8 @Qello =.$.Reddy@ Msgbo8 @R is a (%all 4u%ber@ Msgbo8 @R value is @.8 7lse "F 8;3LL and 8GAMLL Then Msgbo8 @Qello =$R@ Msgbo8 @R is a Mediu% 4u%ber@ 7lse "F 8;MLL and 8GA3LLL Then Msgbo8 @Qello $handra Mohan Reddy@ Msgbo8 @R is a ?arge 4u%ber@ 7lse Msgbo8 @Qello (ir@ Msgbo8 @R is a =rand 4u%ber@ 7nd "# 7nd "# 7nd "# ,# 37ecuting a certain block of statements *)en t*o 8 more con%itions are True 19este% 0f555# 78a%!le2 Di% (tate, Region (tateA"n!utbo8 /@7nter a (tate@0 RegionA"n!utbo8 /@7nter a Region@0 "# stateA @-P@ Then "# RegionA @Telangana@ Then %sgbo8 @Qello =.$.Reddy@ %sgbo8 @Dist count is 3L@ 7lse i# RegionA @Rayalase%a@ Then %sgbo8 @Qello =$R@ %sgbo8 @Dist count is K@ 7lse "# RegionA @$ostal@ Then %sgbo8 @Qello $handra %ohan Reddy@ %sgbo8 @Dist count is O@

7nd "# 7nd "# 7nd "# 7nd "# Making Decisions *it) Select Case The (elect $ase structure !rovides an alternative to "#...Then...7lse"# #or selectively e8ecuting one bloc& o# state%ents #ro% a%ong %ulti!le bloc&s o# state%ents. (elect $ase state%ent !rovides ca!ability si%ilar to the "#...Then...7lse state%ent, but it %a&es code %ore e##icient and readable. 78a%!le2 O!tion e8!licit Di% 8,y, O!eration, Result 8A "n!utbo8 /@ 7nter 8 value@0 yA "n!utbo8 /@7nter y value@0 O!erationA "n!utbo8 /@7nter an O!eration@0 (elect $ase O!eration $ase @add@ ResultA cdbl /80Scdbl /y0 Msgbo8 @Qello =.$.Reddy@ Msgbo8 @-ddition o# 8,y values is @.Result $ase @sub@ ResultA 8-y Msgbo8 @Qello =.$.Reddy@ Msgbo8 @(ubstraction o# 8,y values is @.Result $ase @%ul@ ResultA 8Hy Msgbo8 @Qello =.$.Reddy@ Msgbo8 @Multi!lication o# 8,y values is @.Result $ase @div@ ResultA 8:y Msgbo8 @Qello =.$.Reddy@ Msgbo8 @Division o# 8,y values is @.Result $ase @%od@ ResultA 8 %od y Msgbo8 @Qello =.$.Reddy@ Msgbo8 @Mod o# 8,y values is @.Result $ase @e8!o@ ResultA 8Ty Msgbo8 @Qello =.$.Reddy@

Msgbo8@78!onentation o# 8,y values is @.Result $ase 7lse Msgbo8 @Qello =.$.Reddy@ %sgbo8 @1rong O!eration@ 7nd (elect

?oo!ing Through $ode

$lo* Control 1 oop Statements#


o ?oo!ing allows us to run a grou! o# state%ents re!eatedly. o (o%e loo!s re!eat state%ents until a condition is FalseD o Others re!eat state%ents until a condition is True. o There are also loo!s that re!eat state%ents a s!eci#ic nu%ber o# ti%es. The #ollowing loo!ing state%ents are available in +B(cri!t2 o Do...?oo!2 ?oo!s while or until a condition is True. o 1hile...1end2 ?oo!s while a condition is True. o For...4e8t2 >ses a counter to run state%ents a s!eci#ied nu%ber o# ti%es. o For 7ach...4e8t2 Re!eats a grou! o# state%ents #or each ite% in a collection or each ele%ent o# an array. "# 4sing Do oops 1e can use Do...?oo! state%ents to run a bloc& o# state%ents an inde#inite nu%ber o# ti%es. The state%ents are re!eated either while a condition is True or until a condition beco%es True. a# Repeating Statements :)ile a Con%ition is True Re!eats a bloc& o# state%ents while a condition is True or until a condition beco%es True i0 Do 1hile condition (tate%ents --------------------?oo! Or, we can use this below synta82 78a%!le2 Di% 8 Do 1hile 8GM 8A8S3 Msgbo8 @Qello =.$.Reddy@ Msgbo8 @Qello QTP@

?oo! ii0 Do (tate%ents --------------------?oo! 1hile condition 78a%!le2 Di% 8 8A3 Do Msgbo8 @Qello =.$.Reddy@ Msgbo8 @Qello QTP@ 8A8S3 ?oo! 1hile 8GM b# Repeating a Statement 4ntil a Con%ition 6ecomes True iii0 Do >ntil condition (tate%ents --------------------?oo! Or, we can use this below synta82 78a%!le2 Di% 8 Do >ntil 8AM 8A8S3 Msgbo8 @=.$.Reddy@ Msgbo8 @Qello QTP@ ?oo! Or, we can use this below synta82 iv0 Do (tate%ents --------------------?oo! >ntil condition Or, we can use this below synta82 78a%!le2 Di% 8 8A3 Do

Msgbo8 UQello =.$.ReddyV Msgbo8 @Qello QTP@ 8A8S3 ?oo! >ntil 8AM & :)ile555:en% Statement 78ecutes a series o# state%ents as long as a given condition is True. (ynta82 1hile condition (tate%ents --------------------1end 37ample: Di% 8 8AL 1hile 8GM 8A8S3 %sgbo8 @Qello =.$.Reddy@ %sgbo8 @Qello QTP@ 1end '# $or5559e7t Statement Re!eats a grou! o# state%ents a s!eci#ied nu%ber o# ti%es. (ynta82 For counter A start to end W(te! ste!X state%ents 4e8t 37ample: Di% 8 For 8A 3 to M ste! 3 Msgbo8 @Qello =.$.Reddy@ 4e8t (# $or 3ac)5559e7t Statement Re!eats a grou! o# state%ents #or each ele%ent in an array or collection. (ynta82 For 7ach ite% "n array (tate%ents 4e8t

37ample: 1" Di% a,b,8 /60 aA5L bA6L 8/L0A @-ddition is @. aSb 8/30A@(ubstraction is @ . a-b 8/50A @Multi!lication is @ . aHb 8/60A @Division is @ . a:b For 7ach ele%ent "n 8 %sgbo8 ele%ent 4e8t 37ample: 1& My-rray A -rray/@one@,@two@,@three@,@#our@,@#ive@0 For 7ach ele%ent "n My-rray %sgbo8 ele%ent 4e8t

+B (cri!t Procedures

0ser

efined *unctions

In +,Script, t"ere are two kinds of procedures available5 t"e Sub procedure and t"e .unction procedure. :> )u# Procedures $ Sub procedure is a series of +,Script statements <enclosed by Sub and !nd Sub statements= t"at perform actions but don3t return a value. $ Sub procedure can take arguments <constants, variables, or expressions t"at are passed by a calling procedure=. If a Sub procedure "as no arguments, its Sub statement must include an empty set of parent"eses <=. SyntaxB Sub Procedure name <= Statements --------------------!nd Sub &r Sub Procedure name <argumentC, argument:=

Statements --------------------!nd Sub !xampleB C Sub (onvertTemp<= temp O Input,ox<NPlease enter t"e temperature in degrees ..N, C= )sg,ox NT"e temperature is N 6 (elsius<temp= 6 N degrees (.N !nd Sub !xampleB : => *unction Procedures $ .unction procedure is a series of +,Script statements enclosed by t"e .unction and !nd .unction statements. $ .unction procedure is similar to a Sub procedure, but can also return a value. $ .unction procedure can take arguments <constants, variables, or expressions t"at are passed to it by a calling procedure=. If a .unction procedure "as no arguments, its .unction statement must include an empty set of parent"eses. $ .unction returns a value by assigning a value to its name in one or more statements of t"e procedure. T"e return type of a .unction is always a +ariant. SyntaxB .unction Procedure name <= Statements --------------------!nd .unction &r .unction Procedure name <argumentC, argument:= Statements --------------------!nd .unction !xampleB C

.unction (elsius<f#egrees= (elsius O <f#egrees - G:= * D A J !nd .unction !xampleB : .unction cal<a,b,c= cal O <aQbQc= !nd .unction ?> Getting ata into and out of Procedures

o !ac" piece of data is passed into our procedures using an argument. o $rguments serve as place"olders for t"e data we want to pass into ourprocedure. 0e can name our arguments any valid variable name. o 0"en we create a procedure using eit"er t"e Sub statement or t"e .unction statement, parent"eses must be included after t"e name of t"e procedure. o $ny arguments are placed inside t"ese parent"eses, separated by commas. @> 0sing )u# and *unction Procedures in Code $ .unction in our code must always be used on t"e rig"t side of a variable assignment or in an expression. .or exampleB Temp O (elsius<f#egrees= -&r)sg,ox NT"e (elsius temperature is N 6 (elsius<f#egrees= 6 N degrees.N To call a Sub procedure from anot"er procedure, type t"e name of t"e procedurealong wit" values for any re4uired arguments, eac" separated by a comma. T"e (all statement is not re4uired, but if you do use it, you must enclose any arguments in parent"eses. T"e following example s"ows two calls to t"e )yProc procedure. &ne uses t"e (all statement in t"e code5 t"e ot"er doesn3t. ,ot" do exactly t"e same t"ing. (all )yProc<firstarg, secondarg= )yProc firstarg, secondarg

8otice t"at t"e parent"eses are omitted in t"e call w"en t"e (all statement isn3t used. A> &,amples8 D"ere, I used .lig"t eservation $pplication for creating .unctions, w"y because, It is t"e default application for QTP, anybody can practice easily...G ( eddy> 3******************************************* 3 7ogin &peration 3******************************************* .unction 7ogin<$gent,Pwd= System/til. un N(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeN #ialog<N7oginN=.$ctivate #ialog<N7oginN=.0in!dit<N$gent 8ameBN=.Set $gent #ialog<N7oginN=.0in!dit<NPasswordBN=.Set Pwd #ialog<N7oginN=.0in,utton<N&?N=.(lick If 0indow<N.lig"t eservationN=.!xist<C;= T"en 7oginON7ogin &peration SucessfulN 3)sgbox 7ogin else 7oginON7ogin &peration /nsucessfulN #ialog<N7oginN=.#ialog<N.lig"t eservationsN=.0in,utton<N&?N=.(lick #ialog<N7oginN=.0in,utton<N(ancelN=.(lick 3)sgbox 7ogin !nd If !nd .unction 3*************************************** 3 (losing $pplication 3*************************************** .unction (loseX$pp<= if 0indow<N.lig"t eservationN=.!xist<G= T"en 0indow<N.lig"t eservationN=.(lose !nd If !nd .unction 3*************************************** 3 &pen &rder 3*************************************** .unction &penX&rder<ord= ordnumO; &n !rror esume 8ext

0indow<N.lig"t eservationN=.$ctivate 0indow<N.lig"t eservationN=.0in,utton<N,uttonN=.(lick 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in("eck,ox<N&rder 8o.N=.Set N&8N 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in!dit<N!ditN=.Set ord 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in,utton<N&?N=.(lick ordnumO0indow<N.lig"t eservationN=.0in!dit<N&rder 8oBN=.Get &Property <NtextN= ordnumOcdbl <ordnum= If ordOordnum T"en &penX&rderO N&rder 8umber N6ordnum6N &pened SucuessfullyN 3)sgbox &penX&rder else &penX&rderO N&rder 8umber N6ordnum6N 8ot &penedA 8ot $vailableN 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.#ialog<N.lig"t eservationsN=.0in,utton<N&?N=.(lick 0indow<N.lig"t eservationN=.#ialog<N&pen &rderN=.0in,utton<N(ancelN=.(lick 3)sgbox &penX&rder !nd If !nd .unction 3****************************************** 3 /pdate &rder 3****************************************** .unction /pdateX&rder<Tickets= 0indow<N.lig"t eservationN=.$ctivate 0indow<N.lig"t eservationN=.0in!dit<NTicketsBN=.Set Tickets 0indow<N.lig"t eservationN=.0in,utton<N/pdate &rderN=.(lick wait<C;= updateO0indow<N.lig"t eservationN=.$ctive@<NT"reed Panel (ontrolN=.Get &Property <NtextN= If updateON/pdate #one...N T"en /pdateX&rderO N&rder /pdated SucussfullyN 3)sgbox /pdateX&rder !lse 0indow<N.lig"t eservationN=.#ialog<N.lig"t eservationsN=.0in,utton<N&?N=.(lick /pdateX&rderO N&rder 8ot /pdatedN 3)sgbox /pdateX&rder !nd If !nd .unction 3******************************************

3 .unction to send a mail 3****************************************** .unction Send)ail<SendTo, Sub'ect, ,ody, $ttac"ment= Set otlO(reate&b'ect<N&utlook.$pplicationN= Set mOotl.(reateItem<;= m.toOSendTo m.Sub'ectOSub'ect m.,odyO,ody If <$ttac"ment ZL NN= T"en )ail.$ttac"ments.$dd<$ttac"ment= !nd If m.Send otl.Quit Set m O 8ot"ing Set otl O 8ot"ing !nd .unction (all Send)ail<Ngcreddy[gcreddy.comN,N"iN,NT"is is test mail for testingN,NN=

+B (cri!t 7rrors

Generally !rrors in +, Script are : Types

:> .B )cript Run-time &rrors +, Script run-time errors are errors t"at result w"en your +,Script script attempts to perform an action t"at t"e system cannot execute. +,Script run-time errors occur w"ile your script is being executed5 w"en variable expressions are being evaluated, and memory is being dynamic allocated. &rror 2um#er escription8

I:J $ctive@ component can3t create ob'ect D;> $n exception occurred IIJ $rgument not optional C> (an3t perform re4uested operation IG; (lass doesn3t support $utomation D;E (lass not defined CC #ivision by %ero IH !rror in loading #77 D;:; !xpected 3=3 in regular expression D;CJ !xpected 3_3 in regular expression IG: .ile name or class name not found during $utomation operation J: .or loop not initiali%ed D;;H Illegal assignment

DC Internal error D;D Invalid or un4ualified reference IHC Invalid picture D Invalid procedure call or argument D;:C Invalid range in c"aracter set JI Invalid use of 8ull IIH 8amed argument not found II> &b'ect doesn3t support current locale setting IID &b'ect doesn3t support t"is action IGH &b'ect doesn3t support t"is property or met"od IDC &b'ect not a collection D;I &b'ect not safe for creating D;G &b'ect not safe for initiali%ing D;: &b'ect not safe for scripting I:I &b'ect re4uired JC &b'ect variable not set > &ut of )emory :H &ut of stack space CI &ut of string space E &verflow GD Sub or function not defined J Subscript out of range D;C> Syntax error in regular expression IE: T"e remote server mac"ine does not exist or is unavailable C; T"is array is fixed or temporarily locked CG Type mismatc" D;CH /nexpected 4uantifier D;; +ariable is undefined IDH +ariable uses an $utomation type not supported in +,Script ID; 0rong number of arguments or invalid property assignment => .B )cript )ynta, &rrors +,Script syntax errors are errors t"at result w"en t"e structure of one of your+,Script statements violates one or more of t"e grammatical rules of t"e+,Script scripting language. +,Script syntax errors occur during t"e program compilation stage, before t"e program "as begun to be executed. &rror 2um#er C;D: C;II C;DG C;DH C;D> escription8

(annot "ave multiple default propertyAmet"od in a (lass (annot use parent"eses w"en calling a Sub (lass initiali%e or terminate do not "ave arguments 3#efault3 specification can only be on Property Get 3#efault3 specification must also specify 3Public3

C;;D !xpected 3<3 C;;E !xpected 3=3 C;CC !xpected 3O3 C;:C !xpected 3(ase3 C;I> !xpected 3(lass3 C;:D !xpected end of statement C;CI !xpected 3!nd3 C;:G !xpected expression C;CD !xpected 3.unction3 C;C; !xpected identifier C;C: !xpected 3If3 C;IE !xpected 3In3 C;:E !xpected integer constant C;IJ !xpected 7et or Set or Get in property declaration C;ID !xpected literal constant C;CJ !xpected 37oop3 C;:; !xpected 38ext3 C;D; !xpected 3Property3 C;:: !xpected 3Select3 C;:I !xpected statement C;CE !xpected 3Sub3 C;C> !xpected 3T"en3 C;CG !xpected 3To3 C;CH !xpected 30end3 C;:> !xpected 30"ile3 or 3/ntil3 C;:H !xpected 30"ile,3 3/ntil,3 or end of statement C;:J !xpected 30it"3 C;G; Identifier too long C;CI Invalid c"aracter C;GJ Invalid 3exit3 statement C;I; Invalid 3for3 loop control variable C;CG Invalid number C;G> Invalid use of 3)e3 keyword C;GH 3loop3 wit"out 3do3 C;IH )ust be defined inside a (lass C;I: )ust be first statement on t"e line C;IC 8ame redefined C;DC 8umber of arguments must be consistent across properties specification C;;C &ut of )emory C;DI Property Set or 7et must "ave at least one argument C;;: Syntax error C;DD /nexpected 38ext3 C;CD /nterminated string constant

6uilt/0n $unctions of V6 Script


o (onversions <:D= o #atesATimes <CJ= o .ormatting Strings <I= o InputA&utput <G= o )at" <J= o )iscellaneous <G= o ounding <D=

o Strings <G;= o +ariants <H=

%mportant *unctions
:> A#s *unction eturns t"e absolute value of a number. #im num numOabs<-D;.GG= msgbox num => Array *unction eturns a variant containing an $rray #im $ $O$rray<N"yderabadN,Nc"ennaiN,NmumbaiN= msgbox $<;= e#im $<D= $<I=ONnelloreN msgbox $<I= ?> Asc *unction

eturns t"e $8SI c"aracter code corresponding to t"e first letter in a string. #im num numO$sc<N$N= msgbox num * It returns t"e value ED * @> C!r *unction eturns t"e c"aracter associated wit" t"e specified $8SI c"aracter code. #im c"ar ("arO("r<ED= msgbox c"ar * It returns $ * A> C%nt *unction eturns an expression t"at "as been converted to a +ariant of subtype Integer. #im num numOC:G.ID myIntO(Int<num= msgbox )yInt B> ate *unction eturns t"e (urrent System #ate. #im mydate mydateO#ate msgbox mydate C> ay *unction !xC= #im myday mydayO#ay<NC>,#ecember,:;;JN= msgbox myday !x:= #im myday mydateOdate mydayO#ay<)ydate= msgbox myday E> ate iff *unction

eturns t"e number of intervals between two dates. #im #ateC, #ate:, x #ateCO]C;-C;-;J] #ate:O]C;-C;-CC] xO#ate#iff<NyyyyN, #ateC, #ate:= )sgbox x 3#iffernce in Vears #ateCO]C;-C;-;J] #ate:O]C;-C;-CC] xO#ate#iff<N4N, #ateC, #ate:= )sgbox x 3#iffernce in Quarters #ateCO]C;-C;-;J] #ate:O]C;-C;-CC] xO#ate#iff<NmN, #ateC, #ate:= )sgbox x 3#iffernce in )ont"s #ateCO]C;-C;-;J] #ate:O]C;-C;-CC] xO#ate#iff<NwN, #ateC, #ate:= )sgbox x 3#iffernce in weeks #ateCO]C;-C;-;J] #ate:O]C;-C;-CC] xO#ate#iff<NdN, #ateC, #ate:= )sgbox x 3#iffernce in days #ateCO]C;-C;-;J] #ate:O]C;-C;-CC] xO#ate#iff<N"N, #ateC, #ate:= )sgbox x 3#iffernce in 1ours #ateCO]C;-C;-;J] #ate:O]C;-C;-CC] xO#ate#iff<NnN, #ateC, #ate:= )sgbox x 3#iffernce in )inutes #ateCO]C;-C;-;J] #ate:O]C;-C;-CC] xO#ate#iff<NsN, #ateC, #ate:= )sgbox x 3#iffernce in Seconds

#ateCO]C;-C;-;J] #ate:O]C;-C;-CC] xO#ate#iff<NyN, #ateC, #ate:= )sgbox x 3#iffernce in day of years #ateCO]C;-C;-;J] #ate:O]C;-C;-CC] xO#ate#iff<NaN, #ateC, #ate:= )sgbox x 3!rror #ateCO]C;-C;-;J] #ate:O]C;-C;-CC] xO#ate#iff<#ateC, #ate:= )sgbox x 3!rror F> /our *unction eturns a w"ole number between ; and :G, inclusive, representing t"e "our of t"e day. #im mytime, )y"our mytimeO8ow my"ourO"our <mytime= msgbox my"our :;> 6oin *unction eturns a string created by 'oining a number of substrings contained in an array. #im mystring, myarray<G= myarray<;=ON("andra N myarray<C=ON)o"an N myarray<:=ON eddyN mystringO2oin<)y$rray= msgbox mystring ::> &val *unction !valuates an expression and returns t"e result. :=> Time *unction eturns a +ariant of subtype #ate indicating t"e current system time.

#im mytime mytimeOTime msgbox mytime :?> .arType *unction eturns a value indicating t"e subtype of a variable. #im x,y xOC;; yO+arType<x= )sgbox y 3: <Integer= xON1yderabadN yO+arType<x= )sgbox y 3H <String= xO]C;-C;-C;] yO+arType<x= )sgbox y 3><#ate format= xOC;;.DE yO+arType<x= )sgbox y 3 D<#ouble=

yO+arType<a= )sgbox y 3; <!mpty= Set x O(reate&b'ect<NScripting..ileSystem&b'ectN= yO+arType<x= )sgbox y 3J<$utomation &b'ect= :@> 4eft *unction #im +al, x,y +alON1yderabadN xO7eft<+al,G= )sgbox x 31yd +alOC;; xO7eft<+al,C= )sgbox x 3C

+alON1yderabadN xO7eft<+al,;= )sgbox x 38ull +alON1yderabadN xO7eft<+al,C:= )sgbox x 31yderabad +alO]C;-C;-C;] xO7eft<+al,G= )sgbox x 3C;A +alON1yderabadN xO7eft<+al= )sgbox x 3!rror <7engnt" is )anditory= :@> Rig!t *unction #im $nyString, )yStr $nyString O N1ello 0orldN 3 #efine string. )yStr O ig"t<$nyString, C= 3 eturns NdN. )yStr O ig"t<$nyString, E= 3 eturns N 0orldN. )yStr O ig"t<$nyString, :;= 3 eturns N1ello 0orldN. :A> 4en *unction eturns t"e number of c"aracters in a string or t"e number of bytes re4uired to store a variable. !x C=B #im )ystring mystringO7en<NG.(. eddyN= msgbox mystring !x :=B #im )ystring )ystringOInputbox<N!nter a +alueN= )ystringO7en<)ystring= )sgbox )ystring :B> Mid *unction eturns a specified number of c"aracters from a string.

#im +al, x,y +alON1yderabadN xO)id<+al,G,I= )sgbox x 3dera +alOC;; xO)id<+al,C= )sgbox x 3C;; +alON1yderabadN xO)id<+al,E,>= )sgbox x 3abad +alON1yderabadN xO)id<+al,E,C= )sgbox x 3a +alON1yderabadN xO)id<+al,E,;= )sgbox x 38ull +alON1yderabadN xO)id<+al,C:= )sgbox x 38ull +alO]C;-C;-C;] xO)id<+al,G,G= )sgbox x 3AC; +alO]:;C;-C;-C;] xO)id<+al,D= )sgbox x 3A:;C; +alON1yderabadN xO)id<+al= )sgbox x 3!rror :C> Timer *unction eturns t"e number of seconds t"at "ave elapsed since C:B;; $) <midnig"t=. .unction myTime<8=

#im StartTime, !ndTime StartTime O Timer .or I O C To 8 8ext !ndTime O Timer myTimeO !ndTime - StartTime msgbox myTime !nd .unction (all myTime<:;;;= :C> is2umeric *unction #im )y+ar, )y("eck )y+ar O DG )y("eck O Is8umeric<)y+ar= msgbox )y("eck )y+ar O NIDJ.JDN )y("eck O Is8umeric<)y+ar= msgbox )y("eck )y+ar O NID 1elpN )y("eck O Is8umeric<)y+ar= msgbox )y("eck * It eturns TrueA.alse like esult * :E> %nput#o, *unction #isplays a prompt in a dialog box, waits for t"e user to input text or click a button, and returns t"e contents of t"e text box. #im Input Input O Input,ox<N!nter your nameN= )sg,ox <NVou enteredB N 6 Input= :F> Msg#o, *unction #isplays a message in a dialog box, waits for t"e user to click a button, and returns a value indicating w"ic" button t"e user clicked. #im )y+ar )y+ar O )sg,ox <N1ello 0orldWN, ED, N)sg,ox !xampleN= =;> Create"#$ect

creates and returns reference of t"e filesytemob'ect to an $utomation ob'ect. It can be used for performing operations on computer file system Set ob'.soOcreateob'ect <NScripting..ileSystem&b'ectN= 3creates and returns reference of t"e !xcel b'ect to an $utomation ob'ect. It can be used for performing operations on Spreed s"eet <)s!xcel files= Set ob'!xcel O (reate&b'ect<N!xcel.$pplicationN= 3creates and returns reference of t"e 0ord &b'ect to an $utomation ob'ect. It can be used for performing operations on )s-0ord documents Set ob'0ord O (reate&b'ect<N0ord.$pplicationN= 3creates and returns reference of t"e #atabase (onnection to an $utomation ob'ect. It can be used for (onnecting, opening and (losing databases Set ob'(onnection O (reate&b'ect<N$#&#,.(onnectionN=

3creates and returns reference of t"e #atabase ecordset to an $utomation ob'ect. It can be used for performing operations on database tables< ecords= Set ob' ecordSet O (reate&b'ect<N$#&#,. ecordsetN= 3creates and returns reference of t"e )s-Power point ob'ect to an $utomation ob'ect. It can be used for performing operations on Power point presentations Set ob'PPT O (reate&b'ect<NPowerPoint.$pplicationN= Set xmldoc O 0Script.(reate&b'ect<Nmsxml:.domdocumentN=
=:> Round eturns a number rounded to a specified number of decimal places.

#im num numOC>:.IJJ numO ound<num= msgbox num ==> )trReverse It returns reverse value of t"e given sring xOstrreverse <Ndabaraedy"N= msgbox x =?> strComp It compares two strings based on $S(II +alues and t"an :nd =, ; <!4ual= and C <Cst greater t"an :nd= #im x, y xONcdNB yONbcdN compOstrcomp<x,y= msgbox comp

eturens -C <C st less

=@> Replace It replace a sub string wit" given value <anot"er sub string= mystringO eplace<Nkb scriptN, NkN,NvN= msgbox mystring

0ser

efined *unctions

---------------------------------------------------------i> 4aunc!ing Application


2avigation8 a= 7aunc" t"e ,rowser b= !nter A Select t"e / 7 <Twww.''perfumes.comU= .erification8 (apture t"e ,rowser 8ame and +erify RRRRR *unction 4aunc!QAppD> System/til. un T(BPProgram .ilesPInternet !xplorerPI!@P7& !.!@!U,UN,U(BP#ocuments and SettingsP$dministratorU,UopenU ,rowser<TGoogleU=.Page<TGoogleU=.Sync ,rowser<TGoogleU=.8avigate T"ttpBAAwww.''perfumes.comAU 0ait <H= ,rowserX8ame O ,rowser<TGoogleU=.Get &Property<TtitleU= If ,rowserX8ameOU22 Perfumes-#iscount perfume c"eap brand name perfumes, fragrance 6 cologne onlineU T"en 7aunc"X$ppOU2'perumes.com ,rowser 7aunc"ed SucessfullyU )sgbox 7aunc"X$pp

!lse 7aunc"X$ppOU2'perumes.com ,rowser 8ot 7aunc"edU )sgbox 7aunc"X$pp !nd If &nd *unction

RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR< ii> Customer Registration


Pre-SetupB 7aunc"ing $pplication 2avigation8 a= Select egistration 7ink in ''perfumes.com "omepage b= !nter all )andatory details c= Select Submit button .erify8 (apture confirmation )essage and +erify *unction RegisterD&mail> ,rowser<T22 Perfumes-#iscount perfumeU=.Page<T22 Perfumes-#iscount perfumeU=.7ink<T egisterU=.(lick ,rowser<T22 Perfumes-#iscount perfumeU=.Page<T22 Perfumes-#iscount perfumeX:g=.0eb7ist<TusertypeU=.Select T etailerU ,rowser<T22 Perfumes-#iscount perfumeU=.Page<T22 Perfumes-#iscount perfumeX:g=.0eb!dit<TfirstnameU=.Set TdfgdgU ,rowser<T22 Perfumes-#iscount perfumeU=.Page<T22 Perfumes-#iscount perfumeX:g=.0eb!dit<TlastnameU=.Set TdgdfgdfgU ,rowser<T22 Perfumes-#iscount perfumeU=.Page<T22 Perfumes-#iscount perfumeX:g=.0eb7ist<TgenderU=.Select T)aleU ,rowser<T22 Perfumes-#iscount perfumeU=.Page<T22 Perfumes-#iscount perfumeX:g=.0eb!dit<TaddressCg=.Set TdfgfdgfU ,rowser<T22 Perfumes-#iscount perfumeU=.Page<T22 Perfumes-#iscount perfumeX:g=.0eb!dit<Tp"oneU=.Set TJ::::::::Gg ,rowser<T22 Perfumes-#iscount perfumeU=.Page<T22 Perfumes-#iscount perfumeX:g=.0eb!dit<TemailU=.Set !mail ,rowser<T22 Perfumes-#iscount perfumeU=.Page<T22 Perfumes-#iscount perfumeX:g=.0eb!dit<TcityU=.Set Tc"ennaiU ,rowser<T22 Perfumes-#iscount perfumeU=.Page<T22 Perfumes-#iscount perfumeX:g=.0eb7ist<TstateU=.Select T)S F )ISSISSIPPIU ,rowser<T22 Perfumes-#iscount perfumeU=.Page<T22 Perfumes-#iscount perfumeX:g=.0eb!dit<T%ipU=.Set T:GIDEg ,rowser<T22 Perfumes-#iscount perfumeU=.Page<T22 Perfumes-#iscount perfumeX:g=.0eb!dit<TpasswordU=.SetSecure TGcG;bbc>daa;dccbHGc:JICbbH>fa;>;JdGIg ,rowser<T22 Perfumes-#iscount perfumeU=.Page<T22 Perfumes-#iscount perfumeX:g=.0eb!dit<TconPassU=.SetSecure TGcG;bbcdbCf>aG:d:>aDEf>;aE;f>dCeICDJg ,rowser<T22 Perfumes-#iscount perfumeU=.Page<T22 Perfumes-#iscount

perfumeX:g=.0eb,utton<TSubmitU=.(lick 0ait <D= (onfirmX)essage O ,rowser<T22 Perfumes-#iscount perfumeU=.Page<T22 Perfumes#iscount perfumeXGg=.0eb!lement<T egistered successfully.U=.Get &Property<TinnertextU= If (onfirmX)essageOU egistered successfully. TT"en egisterOU(ustomer egistration SucessfulU )sgbox egister !lse egisterOU egistration .ailedU )sgbox egister !nd If &nd *unction RRRRRR*unction RegisterD&mail> Set my,rowserO,rowser<T22 Perfumes-#iscount perfumeU=.Page<T22 Perfumes#iscount perfumeX:g= ,rowser<T22 Perfumes-#iscount perfumeU=.Page<T22 Perfumes-#iscount perfumeU=.7ink<T egisterU=.(lick my,rowser.0eb7ist<TusertypeU=.Select T etailerU my,rowser.0eb!dit<TfirstnameU=.Set TdfgdgU my,rowser.0eb!dit<TlastnameU=.Set TdgdfgdfgU my,rowser.0eb7ist<TgenderU=.Select T)aleU my,rowser.0eb!dit<TaddressCg=.Set TdfgfdgfU my,rowser.0eb!dit<Tp"oneU=.Set TJ::::::::Gg my,rowser.0eb!dit<TemailU=.Set !mail my,rowser.0eb!dit<TcityU=.Set Tc"ennaiU my,rowser.0eb7ist<TstateU=.Select T)S F )ISSISSIPPIU my,rowser.0eb!dit<T%ipU=.Set T:GIDEg my,rowser.0eb!dit<TpasswordU=.SetSecure TGcG;bbc>daa;dccbHGc:JICbbH>fa;>;JdGIg my,rowser.0eb!dit<TconPassU=.SetSecure TGcG;bbcdbCf>aG:d:>aDEf>;aE;f>dCeICDJg my,rowser.0eb,utton<TSubmitU=.(lick 0ait <D= (onfirmX)essage O ,rowser<T22 Perfumes-#iscount perfumeU=.Page<T22 Perfumes#iscount perfumeXGg=.0eb!lement<T egistered successfully.U=.Get &Property<TinnertextU= If (onfirmX)essageOU egistered successfully. TT"en egisterOU(ustomer egistration SucessfulU )sgbox egister !lse egisterOU egistration .ailedU

)sgbox egister !nd If &nd *unction

iii> 4ogin "peration


Pre- e4uisitesB a= 7aunc"ing $pplication b= (ustomer egistration 2avigation8 a= Select T7oginU 7ink in ''perfumes.com "omepage b= !nter !mail and Password c= Select T7ogin ,uttonU .erify8 ("eck existence of 7og&ut 7ink RRRRRF *unction 4oginD&mailI Pwd> ,rowser<T22 Perfumes-#iscount perfumeU=.Page<T22 Perfumes-#iscount perfumeU=.7ink<T7oginU=.(lick ,rowser<T22 Perfumes-#iscount perfumeU=.Page<T22 Perfumes-#iscount perfumeX:g=.0eb!dit<TusernameU=.Set !mail ,rowser<T22 Perfumes-#iscount perfumeU=.Page<T22 Perfumes-#iscount perfumeX:g=.0eb!dit<TpasswordU=.Set Pwd ,rowser<T22 Perfumes-#iscount perfumeU=.Page<T22 Perfumes-#iscount perfumeX:g=.0eb,utton<T7oginU=.(lick If ,rowser<T22 Perfumes-#iscount perfumeU=.Page<T22 Perfumes-#iscount perfumeXGg=.7ink<T7ogoutU=.!xist<C;= T"en 7oginOU7ogin &peration SucessfulU )sgbox 7ogin !lse 7oginOU7ogin .ailedU )sgbox 7ogin !nd If &nd *unction

iv> Closing Application


RRRRRRRR 2avigation8 RRRR a= ("eck t"e !xistence of ''perfumes.com ,rowser b= (lose t"e ,rowser window <If exists= RRRRRF *unction 4aunc!QAppD> System/til. un T(BPProgram .ilesPInternet !xplorerPI!@P7& !.!@!U,UN,U(BP#ocuments andSettingsP$dministratorU,UopenU

,rowser<TGoogleU=.Page<TGoogleU=.Sync ,rowser<TGoogleU=.8avigate T"ttpBAAwww.''perfumes.comAU 0ait <H= ,rowserX8ame O ,rowser<TGoogleU=.Get &Property<TtitleU= If ,rowserX8ameOU22 Perfumes-#iscount perfume c"eap brand name perfumes, fragrance 6 cologne onlineU T"en 7aunc"X$ppOU2'perumes.com ,rowser 7aunc"ed SucessfullyU )sgbox 7aunc"X$pp !lse 7aunc"X$ppOU2'perumes.com ,rowser 8ot 7aunc"edU )sgbox 7aunc"X$pp !nd If &nd *unction 5555555555555555555555555555555555555555555555555555555555

v> 4ogin "peration %n *lig!t Reservation Application


*unction 4ogin DAgentI Password> System/til. un T(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPflig"tIa.exeU,UN,U(BPProgram .ilesP1PPQuickTest ProfessionalPsamplesPflig"tPappPU,UopenU #ialog<T7oginU=.$ctivate #ialog<T7oginU=.0in!dit<T$gent 8ameBU=.Set $gent #ialog<T7oginU=.0in!dit<TPasswordBU=.Set Password wait : #ialog<T7oginU=.0in,utton<T&?U=.(lick If 0indow<T.lig"t eservationU=.!xist<C:= T"en 0indow<T.lig"t eservationU=.(lose 7oginOU7ogin &peration SucessfulU )sgbox 7ogin !lse System/til.(lose#escendentProcesses YIf #ialog<T7oginU=.#ialog<T.lig"t eservationsU=.!xist<:= T"en Y#ialog<T7oginU=.#ialog<T.lig"t eservationsU=.0in,utton<T&?U=.(lick Y#ialog<T7oginU=.0in,utton<T(ancelU=.(lick Y!nd if 7oginOU7ogin .ailedU )sgbox 7ogin !nd if &nd *unction RRRRRRRRRRR

vi> "pen "rder %n *lig!t Reservation Application


*unction "penQ"rderD"rderQ2um#er> 0indow<T.lig"t eservationU=.$ctivate 0indow<T.lig"t eservationU=.0in,utton<T,uttonU=.(lick

0indow<T.lig"t eservationU=.#ialog<T&pen &rderU=.0in("eck,ox<T&rder 8o.U=.Set T&8U 0indow<T.lig"t eservationU=.#ialog<T&pen &rderU=.0in!dit<T!ditU=.Set &rderX8umber 0indow<T.lig"t eservationU=.#ialog<T&pen &rderU=.0in,utton<T&?U=.(lick &rd8um O 0indow<T.lig"t eservationU=.0in!dit<T&rder 8oBU=.Get+isibleText<= &rd8umO(Int<&rd8um= If &rd8umO&rderX8umber T"en &penX&rderO &rderX8umber6 U &pened sucessfullyU )sgbox &penX&rder !lse &penX&rderO &rderX8umber6 U 8ot &penedU )sgbox &penX&rder !nd If &nd *unction RRRRRRRRRRRRRR

vii> 0pdate "rder %n *lig!t Reservation Application


*unction 0pdateQ"rderDTic'ets> 0indow<T.lig"t eservationU=.$ctivate 0indow<T.lig"t eservationU=.0in,utton<T,uttonU=.(lick 0indow<T.lig"t eservationU=.#ialog<T&pen &rderU=.0in("eck,ox<T&rder 8o.U=.Set T&8U 0indow<T.lig"t eservationU=.#ialog<T&pen &rderU=.0in!dit<T!ditU=.Set T:g 0indow<T.lig"t eservationU=.#ialog<T&pen &rderU=.0in,utton<T&?U=.(lick 0indow<T.lig"t eservationU=.0in!dit<TTicketsBU=.Set Tickets 0indow<T.lig"t eservationU=.0in,utton<T/pdate &rderU=.(lick 0ait <C;= )essage O 0indow<T.lig"t eservationU=.$ctive@<TT"reed Panel (ontrolU=.Get &Property<TtextU= If )essageOU/pdate #oneSU T"en /pdateX&rderOU&rder /pdated SucessfullyU )sgbox /pdateX&rder !lse /pdateX&rderOU&rder 8ot /pdatedU )sgbox /pdateX&rder !nd If &nd *unction RRRRRRRRRRRRRF

viii> S1rite *unction to Count !ow many Browsers opened on des'top and close t!em all
.unction (loseX,rowsers<= #im o,rowser, ,rowsers, Tot,rowsers, i Set o,rowserO#escription.(reate

o,rowser<TmicclassU=.+alueOU,rowserU Set ,rowsersO#esktop.("ild&b'ects<o,rowser= Tot,rowsersO,rowsers.(ount )sgbox Tot,rowsers .or iO ; to Tot,rowsers-C Step C ,rowsers<i=.close 8ext &nd *unction RRRRRRRRR

i,> S1rite *unction to Count !ow many Buttons availa#le in *R 1indow


.unction (ountX,uttons<= #im o,utton, ,uttons, Tot,uttons, i Set o,uttonO#escription.(reate o,utton<T(lass 8ameU=.+alueOU0in,uttonU Set ,uttonsO0indow<TtextBO.lig"t eservationU=.("ild&b'ects<o,utton= Tot,uttonsO,uttons.(ount )sgbox Tot,uttons !nd .unction (all (ountX,uttons<= RRRRRRRRRF

,> S1rite *unction to Count !ow many "#$ects availa#le in *R 1indow #y specified Test "#$ect class
.unction (ountX&b'ects<&b'ect= #im ob', &b'ects, Tot&b'ects, i Set ob'O#escription.(reate ob'<T(lass 8ameU=.+alueO&b'ect Set &b'ectsO0indow<TtextBO.lig"t eservationU=.("ild&b'ects<ob'= Tot&b'ectsO&b'ects.(ount )sgbox Tot&b'ects !nd .unction (all (ountX&b'ects<T0in adio,uttonU= (all (ountX&b'ects<T0in,uttonU= (all (ountX&b'ects<T0in!ditU= (all (ountX&b'ects<T0in(ombo,oxU= RRRRRRRRRRF

,i> S1rite function to capture all #utton names one #y one from 4ogin ialog Bo,
.unction (aptureX,uttons<= #im o,utton, ,uttons, Tot,uttons, i, my,utton Set o,uttonO#escription.(reate o,utton<T(lass 8ameU=.+alueOU0in,uttonU

Set ,uttonsO#ialog<TtextBO7oginU=.("ild&b'ects<o,utton= Tot,uttonsO,uttons.(ount .or iO ; to Tot,uttons-C my,uttonO,uttons<i=.Get oProperty<TtextU= )sgbox my,utton 8ext !nd .unction (all (aptureX,uttons<= RRRRRRRRRRRRRR

,ii> S1rite function to Count /owmany 4in's availa#le in Google /omepage


.unction (ountX7inks<= #im o7ink, 7inks, Tot7inks, i Set o7inkO#escription.(reate o7ink<TmicclassU=.+alueOU7inkU Set 7inksO,rowser<TtitleBOGoogleU=.Page<TtitleBOGoogleU=.("ild&b'ects<o7ink= Tot7inksO7inks.(ount )sgbox Tot7inks !nd .unction (all (ountX7inks<= RRRRRRRRRRRRRRRRRRRRRRRRRR-

.B )cript "#$ects
a> *ile)ystem"#$ect Scripting allows us to process drives, folders, and files using t"e .ileSystem&b'ect <.S&=ob'ect model. Creating *ile)ystem"#$ect8 )et .aria#leTCreate"#$ectDU)cripting7*ile)ystem"#$ectU> &,ample8 #im ob'.so Set ob'.soO(reate&b'ect<NScripting..ileSystem&b'ectN= ob'.so.(teateText.ile<N#BPgcreddy.txtN= #> ictionary ictionary "#$ect8

Creating

)et .aria#leTCreate"#$ectDU)cripting7 ictionaryU> &,ample8 c> &,cel Application Creating &,cel "#$ect8 )et .aria#leTCreate"#$ectDU&,cel7ApplicationU> &,ample8 d> 1ord Application Creating 1ord "#$ect8 )et .aria#leTCreate"#$ectDU1ord7ApplicationU> &,ample8 e> )!ell Creating )!ell "#$ect8 )et .aria#leT 1)cript7Create"#$ectDU1script7)!ellU> &,ample8 f> 2etwor' Creating 2etwor' "#$ect8 )et .aria#leT 1)cript7Create"#$ectDU1)cript72etwor'U> &,ample8 g> PowerPoint Creating PowerPoint"#$ect8 )et .aria#leTCreate"#$ectDUPowerPoint7ApplicationU> &,ample8

!> A " B Connection T"e $#& (onnection &b'ect is used to create an open connection to a data source. T"roug" t"is connection, you can access and manipulate a database. Creating ata#ase Connection "#$ect8

)et .aria#leTCreate"#$ectDUA " B7ConnectionU> &,ample8 i> A " B Record)et T"e $#& ecordset ob'ect is used to "old a set of records from a database table. $ ecordset ob'ect consist of records and columns <fields=. Creating ata#ase Record)et "#$ect8

)et .aria#leTCreate"#$ectDUA " B7Record)etU> &,ample8 $> A " B Command T"e $#& (ommand ob'ect is used to execute a single 4uery against a database. T"e 4uery can perform actions like creating, adding, retrieving, deleting or updating records. Creating ata#ase Command "#$ect8

)et .aria#leTCreate"#$ectDUA " B7CommandU> &,ample8 '> &rror Creating &rror "#$ect8

l> Reg&,p

Creating Reg&,p "#$ect8 )et o#$RegTCreate"#$ectDUv#script7rege,pU> m> %nternet &,plorer

n> "utloo' &,press a> ictionary "#$ect

#ictionary &b'ect t"at stores data key, item pairs. $ #ictionary ob'ect is t"e e4uivalent of a P! 7 associative arrayA1as" +ariable. Items can be any form of data, and are stored in t"e array. !ac" item is associated wit" a uni4ue key. T"e key is used to retrieve an individual item and is usually an integer or a string, but can be anyt"ing except an array.

Creating a

ictionary "#$ect8

Set objDictionary = CreateObject("Scripting.Dictionary")

Dictionary Objects Methods:

Add Met!od $dds a key and item pair to a #ictionary ob'ect &,ists Met!od eturns true if a specified key exists in t"e #ictionary ob'ect, false if it does not.

%tems Met!od eturns an array containing all t"e items in a #ictionary ob'ect. Keys Met!od eturns an array containing all existing keys in a #ictionary ob'ect. Remove Met!od emoves a key, item pair from a #ictionary ob'ect. RemoveAll Met!od T"e emove$ll met"od removes all key, item pairs from a #ictionary ob'ect. &,ample8

#im cities Set cities O (reate&b'ect<NScripting.#ictionaryN= cities.$dd N"N, N1yderabadN cities.$dd NbN, N,angaloreN cities.$dd NcN, N("ennaiN

ictionary "#$ects Properties8 Count Property eturns t"e number of items in a collection or #ictionary ob'ect. only. ead-

CompareMode Property Sets and returns t"e comparison mode for comparing string keys in a #ictionary ob'ect. Key Property Sets a key in a #ictionary ob'ect. %tem Property Sets or returns an item for a specified key in a #ictionary ob'ect. .or

collections, returnsan item based on t"e specified key. &,amples8

eadAwrite.

ato&lements:> Add ictionary

Setob'#ictionaryO(reate&b'ect<NScripting.#ictionaryN= ob'#ictionary.$ddNPrinterCN,NPrintingN ob'#ictionary.$ddNPrinter:N,N&fflineN ob'#ictionary.$ddNPrinterGN,NPrintingN => elete All a&lements from ictionary

Setob'#ictionaryO(reate&b'ect<NScripting.#ictionaryN=

ob'#ictionary.$ddNPrinterCN,NPrintingN ob'#ictionary.$ddNPrinter:N,N&fflineN ob'#ictionary.$ddNPrinterGN,NPrintingN col?eysOob'#ictionary.?eys 0script.!c"oN.irstrunBN .or!ac"str?eyincol?eys 0script.!c"ostr?ey 8ext ob'#ictionary. emove$ll col?eysOob'#ictionary.?eys 0script.!c"o+b(r7f6NSecondrunBN .or!ac"str?eyincol?eys 0script.!c"ostr?ey 8ext ?> elete "ne &lement from a ictionary

Set ob'#ictionary O (reate&b'ect<NScripting.#ictionaryN= ob'#ictionary.$dd NPrinter CN, NPrintingN

ob'#ictionary.$dd NPrinter :N, N&fflineN ob'#ictionary.$dd NPrinter GN, NPrintingN col?eys O ob'#ictionary.?eys 0script.!c"o N.irst runB N .or !ac" str?ey in col?eys 0script.!c"o str?ey 8ext ob'#ictionary. emove<NPrinter :N= col?eys O ob'#ictionary.?eys 0script.!c"o +b(r7f 6 NSecond runB N .or !ac" str?ey in col?eys 0script.!c"o str?ey 8ext @> 4ist t!e 2um#er of %tems in a ictionary

Setob'#ictionaryO(reate&b'ect<NScripting.#ictionaryN= ob'#ictionary.$ddNPrinterCN,NPrintingN ob'#ictionary.$ddNPrinter:N,N&fflineN ob'#ictionary.$ddNPrinterGN,NPrintingN 0script.!c"oob'#ictionary.(ount

A> .erify t!e &,istence of a

ictionary Key

Set ob'#ictionary O (reate&b'ect<NScripting.#ictionaryN= ob'#ictionary.$dd NPrinter CN, NPrintingN ob'#ictionary.$dd NPrinter :N, N&fflineN ob'#ictionary.$dd NPrinter GN, NPrintingN If ob'#ictionary.!xists<NPrinter IN= T"en 0script.!c"o NPrinter I is in t"e #ictionary.N !lse 0script.!c"o NPrinter I is not in t"e #ictionary.N !nd If

V6 Script .eneral 37amples


"# :rite a program for fin%ing out *)et)er t)e gi!en year is a leap year or not; Di% 8year 8yearAin!utbo8 /@7nter Eear@0 "# 8year %od KAL Then %sgbo8 @This is a ?ea! year@ 7lse %sgbo8 @This is 4OT@ 7nd "# &# :rite a program for fin%ing out *)et)er t)e gi!en number is+ 3!en number or O%%number; Di% nu% nu%Ain!utbo8 /@7nter a nu%ber@0 "# nu% %od 5AL Then %sgbo8 @This is a 7ven 4u%ber@ 7lse %sgbo8 @This is a Odd 4u%ber@ 7nd "# '# Rea% t*o numbers an% %isplay t)e sum; Di% nu%3,nu%5, su% nu%3Ain!utbo8 /@7nter nu%3@0 nu%5Ain!utbo8 /@7nter nu%5@0 su%A $dbl /nu%30 S $dbl /nu%50 Yi# we want add two strings conversion re<uire %sgbo8 /@(u% is @ .su%0 (# Rea% <+T+R !alues an% Calculate t)e Simple 0nterest; Di% !,t, r, si !Ain!utbo8 /@7nter Princi!le@0 tAin!utbo8 /@7nter Ti%e@0 rAin!utbo8 /@7nter Rate o# "nterest@0 siA /!HtHr0:3LL Y !A !rinci!le a%ount, tAti%e in years, rA rate o# interest %sgbo8 /@(i%!le "nterest is @ .si0 ,# Rea% $our %igit number+ calculate = %isplay t)e sum of t)e number or %isplay 3rror message if t)e number is not a four %igit number;

Di% nu%, su% nu%Ain!utbo8 /@7nter a Four digit nu%ber@0 "# ?en/nu%0 A K Then su%AL su%Asu%Snu% %od 3L nu%Anu%:3L nu%A le#t /nu%, 60 su%Asu%Snu% %od 3L nu%Anu%:3L nu%A le#t /nu%, 50 su%Asu%Snu% %od 3L nu%Anu%:3L nu%A le#t /nu%, 30 su%Asu%Snu% %od 3L %sgbo8 /@(u% is @ .su%0 else %sgbo8 @4u%ber, you entered is not a K digit nu%ber@ 7nd "# -# Rea% any $our/%igit number an% %isplay t)e number in re!erse or%er; Di% nu%,rev nu%A in!utbo8/@7nter a nu%ber@0 "# len/nu%0AK Then revArevH3L S nu% %od 3L nu%Anu%:3L nu%A le#t/nu%,60 revArevH3L S nu% %od 3L nu%Anu%:3L nu%A le#t/nu%,50 revArevH3L S nu% %od 3L nu%Anu%:3L nu%A le#t/nu%,30 revArevH3L S nu% %od 3L %sgbo8 @Reverse Order o# the nu%ber is @.rev 7lse %sgbo8 @4u%ber, you entered is not a K digit nu%ber@ 7nd "# ># Rea% ( subjects marks? calculate t)e Total marks an% gra%e; a) If average marks Greater than or equal to 75, grade is Distinction b) If average marks Greater than or equal to 60 and less than 75 , then grade is First

c) If average marks Greater than or equal to 50 and less than 60 , then grade is econd d) If average marks Greater than or equal to !0 and less than 50 , then grade is "hird e) #inimum marks $5 for an% sub&ect, other'ise (no grade fail() Di% e,%,!,c, tot eAin!utbo8 /@7nter english Mar&s@0 %Ain!utbo8 /@7nter %aths Mar&s@0 !Ain!utbo8 /@7nter !hysics Mar&s@0 cAin!utbo8 /@7nter che%istry Mar&s@0 totA cdbl/e0 S cdbl/%0 S cdbl/!0 S cdbl/c0 %sgbo8 tot "# cdbl/e0 ;A6M and cdbl/%0 ;A6M and cdbl/!0 ;A6M and cdbl/c0 ;A6M and tot ;A6LL Then %sgbo8 @=rade is Distinction@ else "# cdbl/e0 ;A6M and cdbl/%0 ;A6M and cdbl/!0 ;A6M and cdbl/c0 ;A6M and tot ;A5KL and totG6LL Then %sgbo8 @=rade is First@ else "# cdbl/e0 ;A6M and cdbl/%0 ;A6M and cdbl/!0 ;A6M and cdbl/c0 ;A6M and tot ;A5LL and totG5KL Then %sgbo8 @=rade is (econd@ else "# cdbl/e0 ;A6M and cdbl/%0 ;A6M and cdbl/!0 ;A6M and cdbl/c0 ;A6M and tot ;A3ZL and totG5LL Then %sgbo8 @=rade is Third@ else %sgbo8 @4o =rade, Fail@ 7nd "# 7nd "# 7nd "# 7nd "# @# Display O%% numbers up to n; Di% nu%,n nA"n!utbo8 /@7nter a +aule@0 For nu%A 3 to n ste! 5 %sgbo8 nu% 4e8t A# Display 3!en numbers up to n; Di% nu%,n

nA"n!utbo8 /@7nter a +aule@0 For nu%A 5 to n ste! 5 %sgbo8 nu% 4e8t "B# %isplay natural numbers up to n an% *rite in a te7t file; Di% nu%, n, #so, %y#ile nA in!utbo8 /@7nter any +alue@0 nu%A3 For nu%A 3 to n ste! 3 (et #soA createob ect /@scri!ting.#ilesyste%ob ect@0 set %y#ileA#so.o!ente8t#ile /@72Igcreddy.t8t@, P, true0 %y#ile.writeline nu% %y#ile.close 4e8t ""# Display 9atural numbers in re!erse or%er up to n; Di% nu%,n nA"n!utbo8 /@7nter a +aule@0 For nu%An to 3 ste! -3 %sgbo8 nu% 4e8t "&# Display 9atural numbers sum up to n; 14sing $or5559e7t oop# Di% nu%, n, su% nA in!utbo8 /@7nter a +alue@0 su%AL For nu%A 3 to n ste! 3 su%A su%Snu% 4e8t %sgbo8 su% "'# Display 9atural numbers sum up to n; 1using :)ile555:en% oop# Di% nu%, n, su% nA in!utbo8 /@7nter a +alue@0 1hile nu% GAcdbl /n0 su%A su%Snu% nu%Anu%S3 1end

%sgbo8 su% "(# Display 9atural numbers sum up to n; 14sing Do5554ntil555 oop# Di% nu%, n, su% nA in!utbo8 /@7nter a +alue@0 su%AL nu%A3 Do su%A su%Snu% nu%Anu%S3 ?oo! >ntil nu% Acdbl /nS30 %sgbo8 su% ",# :rite a $unction for 9atural 9umbers sum up to n; Function 44u%$ou /n0 Di% nu%, su% su%AL For nu%A 3 to n ste! 3 su%A su%Snu% 4e8t %sgbo8 su% 7nd Function "-# Verify *eat)er t)e entere% "B %igit !alue is a numeric !alue or not; Di% a,8,y,',nu% nu%A"n!utbo8 /@7nter a Phone 4u%ber@0 d3A le#t /nu%,30 d3LARight /nu%,30 d5A%id /nu%, 5, len /300 d6A%id /nu%, 6, len /300 dKA%id /nu%, K, len /300 dMA%id /nu%, M, len /300 dZA%id /nu%, Z, len /300 d[A%id /nu%, [, len /300 dPA%id /nu%, P, len /300 dOA%id /nu%, O, len /300 "# isnu%eric /d30 A @True@ and isnu%eric /d50 A @True@ and isnu%eric /d60 A @True@ and isnu%eric /dK0 A @True@and isnu%eric /dM0 A @True@and isnu%eric /dZ0 A @True@and isnu%eric /d[0 A @True@and isnu%eric /dP0 A @True@and isnu%eric /dO0 A

@True@and isnu%eric /d3L0 A @True@ Then %sgbo8 @"t is a 4u%eric +alue@ else Msgbo8 @"t is 4OT 4u%eric@ 7nd "# "># Verify *eat)er t)e entere% !alue is a "B %igit !alue or not an% 9umeric !alue or not; 14sing multiple if con%itions# Di% a,8,y,',nu% nu%A"n!utbo8 /@7nter a Phone 4u%ber@0 d3A le#t /nu%,30 d3LARight /nu%,30 d5A%id /nu%, 5, len /300 d6A%id /nu%, 6, len /300 dKA%id /nu%, K, len /300 dMA%id /nu%, M, len /300 dZA%id /nu%, Z, len /300 d[A%id /nu%, [, len /300 dPA%id /nu%, P, len /300 dOA%id /nu%, O, len /300 "# len /nu%0 A3L Then "# isnu%eric /d30 A @True@ and isnu%eric /d50 A @True@ and isnu%eric /d60 A @True@ and isnu%eric /dK0 A @True@and isnu%eric /dM0 A @True@and isnu%eric /dZ0 A @True@and isnu%eric /d[0 A @True@and isnu%eric /dP0 A @True@and isnu%eric /dO0 A @True@and isnu%eric /d3L0 A @True@ Then %sgbo8 @"t is a 4u%eric +alue@ 7nd "# 7nd "# "# len /nu%0 G; 3L Then Msgbo8 @"t is 4OT valid 4u%ber @ 7nd "# "@# .enerate interest for " to , years 1for " year />C+ & years /@C+ ' years/AC+ ( years/"BC+ , years /""C# Di% a%ount, duration, intr a%ountAin!utbo8/@enter a%ount@0 "# a%ountG3LLLL Then %sgbo8 @low a%ount@

else For durationA3 to M "# durationA3 Then intrAa%ountH[:3LL %sgbo8 @3 year intrest is2 @ .intr else i# durationA5 Then intrAa%ountHP:3LL %sgbo8 @5 years intrest is2 @ .intr else i# durationA6 Then intrAa%ountHO:3LL %sgbo8 @6 years intrest is2 @.intr else i# durationAK Then intrAa%ountH3L:3LL %sgbo8 @K years intrest is2 @.intr else i# durationAM Then intrAa%ountH33:3LL %sgbo8 @M years intrest is2 @.intr else %sgbo8 @invalid data@ 7nd "# 7nd "# 7nd "# 7nd "# 7nd "# 4e8t 7nd "#

.B )cript General &,amples


:> Read a value and find si(e of t!e value #im valB valOInputbox<N!nter value for valB N= valXlengt" O7en<val= msgbox NSi%e of N6val6N is N6valXlengt"

=> Read a value and find w!et!er t!e value is numeric or notJ #im valB valOInputbox<N!nter value for valB N= valXtype OIs8umeric<val=

If valXtype O true T"en msgbox Nval is 8umericN else msgbox Nval is not 8umericN !nd If ?>LRead a value and find w!et!er t!e value is notJ #im valB valOInputbox<N!nter value for valB N= valXtype OIs#ate<val= If valXtype O true T"en msgbox Nval is #ate type dataN else msgbox Nval is not date typeN !nd If ate type data or

@>Read a value and .erify w!et!er t!e value is :;-digit num#er or not and started wit! F ;r E7 LT!en isplay it is a valid mo#ile num#er

#im val,valX7engt", valX8umeric, valXStart valOInputbox<N!nter value for valB N= valX7engt"O 7en<val= valX8umericOIs8umeric<val= valXStartO7eft<val,C= If valX7engt"OC; and valX8umeric and valXStartOJ or valXStartOH T"en msgbox val6N is a valid mobile number N !lse msgbox val6N is not a valid mobile number N !nd If A> LRead a mo#ile num#er and verify t!e series Lif it starts wit! F=@CE or F=@C: t!en display it is Tata%ndicom num#er Lif it starts wit! FE@F; or FE@E; t!en display it is Airtel num#er #im val, valX7engt",valX8umeric,valXSeries,valXStart valOInputbox<N!nter value for valB N= valX7engt"O 7en<val=

valX8umericOIs8umeric<val= valXStartO7eft<val,C= valXSeriesO7eft<val,D= If valX8umericOtrue T"en If valX7engt"OC; and valXStartOJ T"en If valXSeries O J:I>H or valXSeriesOJ:I>C T"en msgbox NIt is TataIndicom 8umberN !lseIf valXSeriesOJHIJ; or valXSeries O JHIH; t"en msgbox NIt is $irtel 8umberN !nd If !lse msgbox val6N is not a valid mobile number N !nd If !lse msgbox val6 N is Invalid dataN !nd If B> Read a .alue and .erify weat!er t!e value is started wit! Alfa #ytes or notJ D*irst letter s!ould #e Alfa #yte> #im val, valX$sc valOInputbox<Nenter a valueN= valX$scO$sc<val= )sgbox valX$sc If valX$scLOED and valX$scZOJ; or valX$scLOJ> and valX$scZOC::T"en msgbox val6N is an $lp"abetN !lse msgbox val6N is not an $lp"abetN !nd If C> Read a value and .erify weat!er t!e value is Alfa #ytes are notJ #im str, val$sc, flag,i #im strlen, counter,valsingle counterO; strOInputbox<Nenter a string valueN=

strlenO 7en<str= .or iOC to strlen step C valsingleO)id<str,i,C= val$scO$sc<valsingle= If val$scLOED and val$scZOJ; or val$scLOJ> and val$scZOC::T"en flagOC counterOcounterQC !lse flagO; !nd If 8ext msgbox N8o.of c"aracters N 6counter If counterOstrlen and flagOCT"en msgbox str6N is an $lp"abetic valueN !lse msgbox str6N is not an $lp"abetic valueN !nd If

S-ar putea să vă placă și