Vous êtes sur la page 1sur 82

Nagesh_rao46@yahoo.

com

Automation Testing

Jai Sri Ram

Jai Sai Ram

Nagesh Sir Class Notes AUTOMATION TESTING


MANUAL TESTING Testing an application with human interaction is called Manual Testing. Drawbacks of Manual Testing (i) Time consuming. (ii) More resources required. (iii) Human Errors (iv) Repetition of the Task is not much (v) Tiredness (vi) Simultaneous auctions are not possible (Parallel) Automation Testing Testing an application with 3rd Party Software help is called Automation Testing. (or) Testing an application with an Automation Tool is also called as Automation Testing. a) b) c) d) e) f) Benefits of Automation Testing: Fast Reliable Repeatable Reusable Comprehensive Programmable. a) Fast Automation tool runs tests significantly more faster than human users. b) Reliable Automation tool can perform the same operation each time, if you repeated multiple times, so that we can eliminate human errors. c) Repeatable We can check how application or website reacts after repeated the same operation with multiple times.

Nagesh_rao46@yahoo.com

Automation Testing

d) Reusable Automation scripts are reusable on different version of the application of websites even if the user interfaces changes. e) Comprehensive In automation testing we can build a suit of tests that covers every feature in the application or website. f) Programmable. We can program sophisticated Tests that bring out hidden information from the application. 1) 2) 3) 4) Drawbacks of Automation Testing It is expensive We cannot automate all areas. Lack of expertisation. It has some limitations (It cannot test every thing) Which Software Testing should be automated? Tests that need to be execute of every build of the application (Sanity Testing) Tests that use multiple data values (Retesting / Data Drives Testing) Tests that required data from application intimates (G.U.I. Attributes) Load and Stress Testing Which Software Testing should not be automated? Usability Testing One time testing Quick look Tests or A.S.A.P (As soon as possible) Testing Ad-hoc testing / Random Testing Customers requirement are frequently changing. Type of Tools Generally they are (4) Types of tools are available in the market. They are Functional Tools: QTP, WinRunner, Silktest, Rational Robot, TestPartner, etc., Performance Tools: LoadRunner, J-Meter etc., Test Management Tools: Quality Center (QC), Test Director. Version Control Tools VSS (Visual Safe Source), PVCS (Polytron Version Control System) etc.,

1) 2) 3) 4)

QUICK TEST PROFESSIONAL QTP is a Functionality Testing Tool developed by Mercury Interactive later merged with HP QTP has released in following Versions. 5.5 6.5 8.0 8.2 9.0 9.1 9.2 9.5 (Latest) License They are Two types of licenses (1) Seat License (Single User) and (2) Concurrent License (Multiple Users). Technologies QTP 9.2 Supports following Technologies .Net, VB, JAVA, ActiveX Controls, Web Servers, People Soft, SAP, Oracle, Terminal Emulators, HTML, DHTML, XML .. etc., QTP 9.5 Supports following Technologies Power Builder, Oracle Forms10, Apps 12, New Terminal Emulator Versions (Mainframe Application Technologies), .Net (3.5) Environments QTP 9.2 Support on following Environment Windows 2000 Server, 2000 Professional, 2003 Server, XP etc., QTP 9.5 Support on following Environment Windows Vista (64 Bit), Eclipse (3.2 & 3.3), Netscape 9.0, Firefox (3.0) Note QTP does not support on Linux / Unix Operating Systems. X-Runner supports on Linux / Unix Operating System. QTP can support client / Server, Web Applications. QTP Records the business operations in VB Script (It can also support JAVA Script) QTP can support Multimedia Applications such as Flash, Windows Media Player, Real Video etc.,

How to Launch QTP (9.2) Start Programs QuickTest Professional QuickTest Professional Select Specified Add-in Manager Ok

Apart from the 3 Options, QTP supports standard windows Environment (When we uncheck the above 3 Options)

QTP (9.2) TESTING PROCESS


Prepare to Record

Recording

Context Sensitive Mode / Standard Mode (Default) Analog Recording Mode Low Level Recording Mode Standard Checkpoint Bitmap Checkpoint Database Checkpoint Text Checkpoint Text Area Checkpoint Page Checkpoint Table Checkpoint Image Checkpoint Accessibility Checkpoint XML Checkpoint

Editing

Debugging Verify Mode (Default) Update Run Mode Debugging Mode

Running Analyze Results

Defect Report

Recording Modes In QTP, there are (3) Recording Modes such as 1) Context Sensitive Mode In this mode QTP Records the operations which are performed on the objects. Context Sensitive Mode is also called as Standard Recording Mode / Normal Recording Mode. Context Sensitive Mode is default Recording Mode in QTP. 2) Analog Recording Mode In this mode QTP records the Mouse and Keyboard Operations with respective to Window (or) Desktop co-ordinates. Syntax: If you take Desktop Coordinates Desktop Desktop.RunAnalog "<Track No.>" Window Window("Window_Name").RunAnalog "<Track No.>" Navigation Start Recording (F3) Automation Menu Analog Recording

Analog Recording Settings (Shift + Alt + F3) Click on Click on Start Analog Record Record your required Operation Stop Recording (F4)

Generally we are using Analog Recording Mode to compare Digital Signatures, Barcodes, Scientific Graphs etc., Note In Context Sensitive Mode, QTP Generate one statement for each operation. But in Analog Recording Mode, QTP Generates single statement for all the operations which you perform on the application. In Analog Recording Mode, if you take Desktop Co-ordinates, you can get wrong output, if application is moved from one place to another place at Run Time. If you take Window co-ordinates, we can get right output even if the application moved from one place to another place.

3)Low Level Recording Mode We can use this mode to records the operations which are not recognized by Tool. Navigation Start Recording (F3) Automation Menu Low Level Recording Mode (Crtl + Shift + F3) Record your required Operation Stop Recording (F4) Note: We are giving low priority to this recording mode. Important Note If you want to select Analog Recording Mode or Low Level Recording Mode you must be under Context Sensitive Mode. Running Modes There are (3) Running Modes such as (1) Verify Mode (2) Update Run Mode (3) Debugging 1) Verify Mode To compare expected value with Actual value and Return results. 2) Update Run Mode To update Test or Component. 3) Debugging Whether the script is smoothly executing or not without any interruptions. Note Verify Mode is the default Running Mode in QTP. Maintenance Run Mode is the extra Run Mode in QTP 9.5 than 9.2. Window / Object Main Window Sub Window Edit Box Combo Box Menu Radio Button Check Box Push Button Script Window(Window_Name) Dialog (Window_Name) WinEdit(EditBox Name) WinCombo(ComboBox Name) WinMenu (Menu) WinRadioButton(Radio Button Name) WinCheckBox(Check Box Name) WinButton(Push Button Name)

Note
Environment Visual Basic JAVA Web ActiveX .Net

Standard Window Operations Active Window .Activate Enter Text in Edit Box .Set "Text" Select Item from the Combo Box .Select "Item Name" Select item from the Menu .Select "Menu_Name;Item_Name" Check on or off the Radio Button .Set Check on or off the Check Box .Set On/Off Press on Push Button .Click Enter Password in Edit Box .SetSecure "Encrypted_Text" Windows Based In which window.on what object.what operation is done. Syntax: Window(Window_Name).Object(Object_Name).Operation/Method. Web Based In which browser.in which page.on what object.what operation is done. Syntax: Browser(Browser_Text_Name).Page(Page_Name).Object(Object_Name) .Operation/Method. Example-1: Expected: Activate Window. Enter Employee Name as Appa Rao. Enter Employee No. as E001 Enter Employee Salary as 10000 Click on Submit

Class Name VBButton JAVAButton WebButton ACXButton SWFButton (Shock Wave Flash) WinButton Script

Script Window("Employee").Activate Window("Employee").WinEdit("Employee Name:").Set "Appa Rao" Window("Employee").WinComboBox("Employee No:").Select "E001" Window("Employee").WinEdit("Employee Salary:").Set "10000" Window("Employee").WinButton("Submit").Click

Ex-2: Expected: Activate Window. Enter Agent Name as Apparao Enter Password as mercury Click on Ok

Script Dialog("Login").Activate Dialog("Login").WinEdit("Agent Name:").Set "Apparao"


Dialog("Login").WinEdit("Password:").SetSecure "492555ba0ee4f4f47004a1821cb87f8cc8ffe920"

Dialog("Login").WinButton("OK").Click Ex-3:

Expected Activate Window. Enter Patient Name as XYZ Select Ward No. as 101 Select Referral Doctor as Dr.John Cough Radio Button ON Bill Check Box ON Click Ok Enter X-Ray cost as 200 Enter Blood Test as 300 Enter Bed Bill as 500 Click Ok.

Automation Testing

Script Window("KeyClinic").Activate Window("KeyClinic").WinEdit("Patient Name:").Set "XYZ" Window("KeyClinic").WinComboBox("Ward No:").Select "101" Window("KeyClinic").WinComboBox("Referral Doctor:").Select "Dr.John" Window("KeyClinic").WinRadioButton("Cough").Set Window("KeyClinic").WinCheckBox("Bill").Set "ON" Window("KeyClinic").WinButton("Ok").Click Window("KeyClinic").Dialog("Bill").WinEdit("X-Ray:").Set "200" Window("KeyClinic").Dialog("Bill").WinEdit("Blood Test:").Set "300" Window("KeyClinic").Dialog("Bill").WinEdit("Bed Bill:").Set "500" Window("KeyClinic").Dialog("Bill").WinButton("Ok").Click Ex-4 Expected Click Ok Script Window("SAMPLE").Dialog("SAMPLE-1"). Dialog("SAMPLE-2").WinButton("Ok").Click

Ex-5 Expected Enter Branch Name as Ameerpet Enter Address as Ameerpet. Enter ZIP Code as 500016 Select Country as India Select State as Andhra Pradesh Select City as Hyderabad.

Script Browser("AXIN BANK").Page(AXIN BANK).WebEdit("Branch Name").Set "Ameerpet" Browser("AXIN BANK").Page(AXIN BANK).WebEdit("Address").Set "Ameerpet"
Automation Testing

Browser("AXIN BANK").Page(AXIN BANK).WebEdit("ZIP Code").Set "500016" Browser("AXIN BANK").Page(AXIN BANK).WebList("Country") .Select "India" Browser("AXIN BANK").Page(AXIN BANK).WebList("State").Select "Andhra Pradesh" Browser("AXIN BANK").Page(AXIN BANK).WebList("City").Select "Hyderabad" Browser("AXIN BANK").Page(AXIN BANK).WebButton("Submit"). Click Ex-6 Expected Enter Agent Name as John Enter Password as mercury Click on Login Script Browser("Rediff Shopping").Page(Rediff Shopping).WebEdit("Agent Name").Set John Browser("Rediff Shopping").Page(Rediff Shopping).WebEdit("Password").SetSecure49 2b7106207d6db37e2a339047b52e9d09b8ed48 Browser("Rediff Shopping").Page(Rediff Shopping).Image("Login").Click

10

Automation Testing

Architecture of QTP Screen

Data Table

Test Pane

Active Screen Information Pane


Missing Resources Pane

Deb View

1) Test Pane In this QTP displays the Test Script which you record on the application. To view the Test scripts, there are two modes such as (i) Keyword View (ii) Expert View. (i) Keyword View In this mode QTP displays the test script in object hierarchy way and it provides documentation for every operation. There are (4) Parts (i) Item (ii) Operation (iii) Value (iv)Documentation likes as below.

(ii)

Expert View In this mode QTP displays the Test script in VB Script. Data Table

2)

It is used to store the data and parameterize that data to the test script There are (2) Sheets by default. They are (1) Global (2) Action1 In one data table we will have 256 Sheets. Out of 256 sheets, one sheet is Global and remaining 255 sheets are Action Sheets Global Sheet related to all the tests. Action Sheet related to corresponding Action only. 3) Active Screen In this QTP captures window snapshots for every object operations and displays those images in Active Screen Area. Advantages i) Easy to insert Check Points ii) Easy to insert Output values. iii)Easy to add objects to all object repository. iv) Easy to insert steps. v) Easy to understand script by observing images in active screen area Disadvantages It occupies lot of space to store the snapshots. To disable Active Screen Tools Options Active Screen Tab Custom Level under Windows applications Select None under Web select Disable Active Screen capture Ok Ok 4) Debug Viewer It is used for viewing, modifying or setting the current values of variables or objects during Test execution break with the help of 3 Options, such as (i) Watch (ii) Variables (iii) Command. 5) Information Pane It displays the syntax of related information during Check Syntax Syntax Check (Ctrl + F7) 6) Missing Resources Pane Whenever we open a test, the files which are associated with that test are missed / moved, then Missing Resources Pane will be opened automatically and displays the information about that missed file.

CHECK POINTS 1) Standard Check Point We can use this check point to verify the property of an object. Ex: Verify Update Order Step Name Step description Expected result Actual Status Activate Window Disable Step-1 Open Record Disable Step-2 Perform change Enable Step-3 Navigation Start Recording Click on Ok Activate Window (Flight 4a.exe) File Menu Click on Open Order Select Order No. Enter No. Click on Ok Perform any changeClick Update OrderStop RecordingKeep theapplication (Flight4a.exe) in base state Identify positions in the Test Script to insert Check Points [After Activate window; after open order; after perform change] Start Recording {Insert Menu Check Points Click on Standard Check Point} {or F12} show object [ ] with Click Ok Enter Name of the Check Point Select Property with expected value (Enable-True = Enable; Enable-False = Disable) Click Ok Stop Recording after insertion of all Check points at relevant places Click Run Analyze results manually. Ex:1
Window("Flight Reservation").Activate Window("Flight Reservation").WinButton("Update Order").Check CheckPoint("CP_1") Window("Flight Reservation").WinMenu("Menu").Select "File;Open Order..." Window("Flight Reservation").WinButton("Update Order").Check CheckPoint("CP_2") Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON" Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set "30" Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click Window("Flight Reservation").WinRadioButton("Economy").Set Window("Flight Reservation").WinButton("Update Order").Check CheckPoint("CP_3") Window("Flight Reservation").WinButton("Update Order").Click wait (10) If Window("Flight Reservation").ActiveX("Threed Panel Control").GetROProperty("text") ="Update Done..." Then msgbox ("Test is pass") else msgbox ("Test is fail") End If

Run in Update Run Mode

How to edit existing check point: Place the cursor on Check Point which you want to edit Right Click Check Point Properties Select property Change value or Rename Check Point Click Ok. How to insert check point through Active Screen Start Recording Record Required Operation like as below [Click on Ok Activate Window (Flight 4a.exe) File Menu Click on Open Order Select Order No. Enter No. Click on Ok Perform any change Click Update Order] Stop Recording Keep the application (Flight4a.exe) in base state Identify positions in the Test Script to insert Check Points [After Activate window; after open order; after perform change] place the cursor on specified statement Click on Active Window Right Click on object Click on Insert Standard Check Point Click Ok Enter Check Point Name Select Property with expected value (Enable-True = Enable; Enable-False =Disable) Select option to insert statement (Before current Step / After current Step) Click Ok Click Run after insertion of all Check points at relevant places Analyze results manually.

2) Bit Map Check Point We can use this Check Point to conduct test on Bitmaps. Navigation Start Recording Help Menu Click on about Insert Menu (QTP) Check Point Click Bit Map Check Point Show Bitmap with hand icon Click Ok Enter Name of the Check Point Click on select area if you want to check a specific area with in the Bit Map Select save only selected area Click on Ok Stop Recording Close current application (Flight 4a) Open another application (Flight 4b) Click run to analyze results manually. How to insert check point through Active Screen Start Recording Help Menu Click on about Click on Bit Map Stop Recording Click on Active Screen Icon Right click on Bit Map which you want to check Click on Insert Bitmap Check Point Click Ok Enter Name of the Check Point Select area which area to be checked Select

option to insert statement (Before current Step / After Current Step) Click on Ok Close current application (Flight 4a) Open another application (Flight 4b) Click run to analyze results manually.

3) Database Check Point To automate backend testing we are using Database Check Point. During this testing we are validating backend table in terms of Data validation and data integrity. Data validation means that the correctness of storing values into backend table. Data integrity means that the impact of stored values on existing data table content. In this we will be concentrate on primary keys, foreign keys, unique keys, . etc., To automate backend testing we can follow below approach. 4 1 5 Actua l Data 3

Expected Value = = Fail = ! Pass

Step 1: Step 2: Step 3: Step 4: Step 5:

Connect to Database using DSN (Data Source Name) Execute Specified Select statement. Retrieve the result of SQL Statement Perform any db Operation. Compare expected data with actual data to verify the impact of frontend operation on backend table content.

Navigation Insert Menu Check Point Database Check Point Select Specify SQL Statement Manually Next Create Machine Data source (Select Data source) Select DSN (QT_FLIGHT32) Click Ok SQL Statement (Enter your specified SQL Statement Ex:. select * from orders) Finish Change the Check Point Name Click Ok Open Frontend (perform any db operation like insert, delete, update) Click Run Analyze results manually. To Create New DSN *) First of all you create One database in MS Access with specified table. Navigation Insert Menu Check Point Click on Database Check Point Select Specify SQL Statement Manually Next Create Machine Data source (Select Data source) New Select type of data source (User [Single user] / System Data Source [multiple users]) Next Select a Driver (Microsoft Access Driver) Select database Click Ok Enter Data Source Name with description Click Ok Click Ok Take your specified statement (Table) Ex:. select * from orders) Finish Click Ok. Note Database Check Point insertion is not possible through Active Screen. 4) Test Check Point We can use this checkpoint to conduct test on text present on the object.

Navigation Start Recording Insert Menu Check Point Click on Text Check Point Select object with hand icon Click Ok Enter Name of the Check Point Enter your expected Text in Constant Select Matching [(1) Match Case (2) Ignore Spaces (3) Exact Match (4) Text Not displayed] Click on Ok Stop Recording Click run to analyze results manually.

How to insert check point through Active Screen Start Recording Activate Window Stop Recording Click on Active Screen Icon Right click on object, which object text you want to check Select insert Text Check Point Click Ok Enter Checkpoint Name Regular Expression. Expected text fill in constant [A-Z] [a-z] [0-9]* Select Matching [(1) Match Case (2) [A-Z] [a-z] [ ] [A-Z] [a-z]* Ignore Spaces (3) Exact Match (4) [A-Z] [a-z]* Text Not displayed] Select Insert Statement (Before / After Current step) Click Ok Click run to analyze results manually. Regular Expressions:
Whenever the object text is changing dynamically at run time, we can use

regular expressions. Ex Expected Srnagar1 John Smith Suresh


5) Test Area Check Point We can use this Checkpoint to conduct test on Text present in the specified screen area.

Navigation Start Recording Insert Menu Check Point Click on Text Area Check Point Select the area specified to check Click Ok Enter Name of the Check Point Enter your expected Text in Constant or click on to give Regular expression Select type of Matching [(1) Match Case (2) Ignore Spaces (3) Exact Match (4) Text Not displayed] Click on OkStop RecordingClick run to analyze resultsmanually. Note: Text Area Checkpoint is not possible through Active Screen. 6) Page Check Point (For Web Pages only)

We can use this Checkpoint to verify the properties of a web page. Navigation Start Recording Insert Menu Check Point Select Standard Checkpoint Show Image / Link with Hand Icon Select Page Click Ok Enter Name of the Checkpoint Select Property [give your expected value (Load time, No. of Images, No of links)] Click Ok Stop Recording Click Run Analyze Results manually. 7) Table Checkpoint We can use this checkpoint to verify the content of a Web Table. Navigation Start Recording Insert Menu Check point Select Standard Checkpoint Select Image with Hand IconClickSelect Web TableClick OkEnter name of the Checkpoint Select Cell Enter your expected data in constant Click Ok Stop Recording Run Analyze Results manually. Note: For Web Table Browser(Browser Text Object Name).Page(Page Name).WebTable(Table Name).Check CheckPoint(Check Point Name) For Page Check Point Browser(Browser Text Object CheckPoint(Check Point Name) Name).Page(Page Name).Check

8) Image Check Point To verify the properties of an Image, we can use Image Checkpoint. Browser(Browser Text Object Name).Page(Page Name).Image(Image Name).Check CheckPoint(Check Point Name) Navigation Start Recording Insert Menu Check point Select Standard Checkpoint Select Image with Hand Icon Click Click Ok Enter name of the Checkpoint Select Property (Alt) [give your expected value to that property] Click Ok Stop Recording Run Analyze Results manually. How can we check Tool Tips Alt Property. 9) XML Check Point To verify the content of an XML file we can use this check point. Navigation Insert Menu Check point XML Check Point (From File) Browse your XML File path Click Ok Enter name of the Checkpoint Select Element Name Specify your expected value Click Ok Run Analyze Results

manually. 10) Accessibility Check Point We can use this checkpoint to verify whether the specified Web Page meets W3C (WWWC) Standards or not (World Wide Web Consortium Standards)

Navigation Tools Menu Options Web Tab Advanced Select / Check in the check point [ActiveX Check, Alt Property Check, Applet Check, Frame Titles Check, Multimedia Links check, Server-side Image Check, Tables Check] Ok Ok Start recording Insert Menu Check Point Click on Accessibility Check Point Show Web Page with Hand Icon Click Ok Enter Name of the CheckpointClick OkStop RecordingRunAnalyze Results manually. Note Page Checkpoint, Table Checkpoint, Image Checkpoint, Accessibility Checkpoint, XML Checkpoint are applicable for Web Pages only. OBJECT REPOSITORY It is an interface between Tool and Application Build. Object Repository consists of Recorded Objects description. 1 AUT

5 4 2

Automation Testing

19

(1)Start Recording

(2)Learn Object (Storing the object in Object Repository) (3)Script Generation (4)Catch Entry in Object Repository (Object Properties in Object Repository ) (match the properties in AUT) (5)Identify Object in AUT AUT means Application Under Test. To open Object Repository Resources Menu Object Repository (or) Ctrl+R

During Recording During Run

There are (2) Types of Objects such as (1) Run Run Time Object is the object which is present in the Time Object (2) AUT (Application under Test) Test

Test object is a reference of Run Time Objects which is created by QTP in Object Repository. Object. Run Time Object: Test Object: How to Add objects in Object Repository. Navigation Open Object Repository Click on Add Object Icon Show Object with Hand Icon Click Ok Select Option [Select Object Only, Default Object Types, All Object Types, Selected Object Types] Click Ok. TYPES OF OBJECT REPOSITORY 1) Local Repository (Pre-Action Repository [Related to corresponding Action] 2) Shared Repository [Specific to multiple actions] How to create Shared Repository? Open Object Repository File Menu Click Export Local Objects Enter File Name Click Save (It will save as *.tsr) What is the extension of the Shared Repository? .tsr (Test Shared Repository) How to associate Shared Repository?

Resources Menu Associate Repository Click on Add elect / S Location of Repository file path Click Open Associate with Action Click Ok.

How to associate Repository file during Runtime repositoriescollection.Add Repository file path Ex: repositoriescollection.Add F:\loginrep.tsr

Note: In QTP every action will have one local repository, apart from that local repository one can associate more than one shared repository to the action.

*.tsr

*.tsr

*.tsr

Module Test Script (*.mts)

Some people are calling it as mercury test script ,mercury test repository

Module Test Repository (*.mtr)

How to edit Shared Repository? Navigation Resources Menu Object Repository Manager File Menu Open Select the Shared Repository File to be edit Open File Menu Enable Editing then select which object to be edited Save.

Automation Testing

21

Object Repository Comparison Tool: We can use this tool to compare two shared object repository files. Navigation: Resources Menu Object Repository Manager Tools Menu Object Repository Comparison Tool Select the (2) Shared Object Repository Files you want to compare Ok Analyze statics. Object Repository Merge Tool We can use this tool to merge Two shared object Repository files. Ex: *.tsr Insert Cancel Reset + *.tsr Update Cancel Reset = *.tsr Insert Cancel Reset Update

Navigation Resources Menu Object Repository Manager Tools Menu Object Repository Merge Tool Select the (2) Shared Object Repository Files you want to Merge Click Ok Save Object Spy We can use this option to know the properties and methods of specified object. Navigation Tools Menu Object Spy Click on Show your specified object with ClickAnalyze properties and methods. OBJECT IDENTIFYING: Object Identification Mechanism is based on FOUR Types of properties and Ordinal Identifier. Mandatory Assistive Properties Properties Normal Identification Mechanism Native Class: Enable: Matching Mechanism Text: Focused: Base Filter Optional Filter Properties Properties Smart Identification Mechanism Abs-X: Window ID: Filtering Mechanism Abs-Y: X: Y:

22

Automation Testing

Ordinal Identifier Location Index Creation Time QTP Will Follow below process to learn the object during Recording Time. First of all QTP will learn all the mandatory properties and verify whether these properties are sufficient or not to identify the object uniquely. If it feels these properties are sufficient to identify the object uniquely, then it will stop learning, otherwise it will learn first Assistive Property and verify whether these properties are sufficient or not to identify the object uniquely. If it feels these properties are also not sufficient to identify object uniquely, then it will learn 2nd Assistive Property and verify whether these properties are sufficient or not to identify object uniquely. If it feels these properties are also not sufficient to identify object uniquely, then it will learn 3rd Assistive Property and verify whether these properties are sufficient or not to identify the object uniquely, like this the process continuous till the QTP satisfy to identify the object uniquely or until completion of all the properties learning present in the Assistive Property list. After completion of all Assistive Properties learning present in the Assistive Property list, still QTP not satisfy to identify the object uniquely, then finally it will learn Ordinal Identifier and stop learning. SMART IDENTIFICATION If you select Smart Identification QTP follows below process during Recording. First of all it will learn all the Mandatory Properties along with Base Filter Properties and Optional Filter Properties at a time. But Mandatory Properties will be stored in Object Repository, where Base Filter Properties and Optional Filter Properties will be stored in a secrete location. Apart from this the process of learning remains same as above. QTP Will follow below process to identify the object during Run Time First of all QTP will take all the properties present in the Object Repository except Ordinal Identifier and try to identify the object. If it fails to identify the object, then it will forget / leave the Object Repository and take the alternative description (Base Filter Properties and Optional Filter Properties). In this first of all, it will take all the base filter properties and try to identify the object. If it fails to identify the object then it will take first Optional filter Property and try to identify the object. If it fails to identify the object then it will take 2nd Optional Filter Property and try to identify the object. If it fails
Automation Testing

23

to identify the object with that property also, then it will take 3 rd Optional Filter Property and try to identify the object, like this the process continue till the QTP identify the object uniquely or until completion of all the properties present in the optional filter properties list. After completion of all the properties present in the Optional Filter Properties list still QTP not able to identify the object uniquely, then it will come back to Object Repository and search for Ordinal Identifier, if it is available, using that QTP roughly identify the object. ORDINAL IDENTIFIER (a) Location If you select Location as Ordinal Identifier, then QTP generates sequence of numbers like 0, 1, 2, 3 . based on the location (Place) of the object in a screen. (b)Index If you select Index as Ordinal Identifier then QTP generates sequence of numbers like 0, 1, 2, 3 based on the sequence of the programs of the object. (c) Creation Time (For Browsers only) If you select Creation Time as Ordinal Identifier then QTP generates sequence of numbers like 0, 1, 2, 3 based on loading of a page in browser time. Navigation Tools Menu Object Identification Select (Standard Window) as Environment Select Test Object Class which you want to configure Take required mandatory properties / Assistive Properties by clicking Add / Remove Button Select Enable Smart Identification Properties Click Configure Take Base Filter / Optional filter Properties by clicking Add / Remove Button Click OkSelect Ordinal IdentifierClick OkStart RecordingRecord required Operation Stop Recording Run Analyze Results manually. Virtual Objects It is used to recognize specified screen area as standard object. Navigation Tools Menu Virtual Objects New Virtual Object Next Select Standard Class under Select Combo Box click Next Mark object Select the Object Next Next Finish. Drawbacks of Object Repository It takes lot of time for identifying the object, when the object is changing dynamically during Run time.
24
Automation Testing

DESCRIPTIVE PROGRAMMING (VB SCRIPTING) If we specify the description of the object in the program it self that can be called as Descriptive Programming. Using Descriptive Programming we can execute test script without objects in Object Repository / we can execute the test script without Object Repository. Advantages of Descriptive Programming i) Fast execution. ii) Easy to identify the objects, when the objects are dynamic in nature. iii) We can prepare Script without having build. Disadvantages of Descriptive Programming i) It takes lot of time to design test design (Time consuming for test script design) To design Descriptive Programming, there are (2) ways such as (1) Specifying the properties and its values directly in the statement (script) (2) Description Object. Syntax / Code window(P1:=Value, P2=Value, .).Object(P1:=Value, P2=Value, .).Operation / Method. Ex(1): Prepare descriptive Programming for Login Operation in Flight Reservation Dialog(""text:=Login", width:=320").Activate Dialog("text:=Login", width:=320).WinEdit("attached text:=Agent Name:"). Set "suresh" Dialog(""text:=Login", width:=320").WinEdit("attached text:=Password:"). SetSecure "4941cfd5b7a0bf66f6e9ded8bacb20164598f9ec" Dialog(""text:=Login", width:=320").WinButton("text:=OK").Click (2) Description Object. To create Description Object we can follow below syntax. Syntax / Code Set Object Name = Description.Create Object Name (Property Name).Value = Property Value
Automation Testing

25

Ex(2): Prepare descriptive Programming for Login Operation in Flight Reservation Set dia = description.Create dia ("text").value="Login" dia ("width").value = 320 Set uid = description.Create uid ("attached text").value="Agent Name:" Set pwd = description.Create pwd ("attached text").value="Password:" Set but = description.Create but ("text").value = "OK" Dialog(dia).Activate Dialog(dia).WinEdit(uid).Set "suresh" Dialog(dia).WinEdit(pwd).SetSecure "4941d5a45019d0ff89dabd026735808c9030b1f0" Dialog(dia).WinButton(but).Click Ex(3): Prepare descriptive Programming for Open a Record in Flight Reservation Set win = description.Create win ("text").value="Flight Reservation"
Set menuobj = description.Create menuobj ("menuobjtype").value=2

Set dia = description.Create dia ("text").value="Open Order" Set cbox = description.Create cbox ("text").value = "&Order No." Set editobj = description.Create editobj ("window id").value = 1016 Set but = description.Create but ("text").value = "OK"
26
Automation Testing

Window(win).Activate Window(win).WinMenu(menuobj).Select "File;Open Order..." Window(win).Dialog(dia).WinCheckBox(cbox).Set "ON" Window(win).Dialog(dia).WinEdit(editobj).Set "15" Window(win).Dialog(dia).WinButton(but).Click VB Script Statements (1) Left We can use this function to get a specified number of characters from the left side of a string. Syntax: left (String, number) Ex: x="sairam" msgbox left(x,3) (2) Right We can use this function to get a specified number of characters from the right side of a string. Syntax: right (String, number) Ex: x="sairam" msgbox right(x,3) Len We can use this function to find length of a string Syntax: len (String) Ex: x="sairam" msgbox len(x) Mid We can use this function to get a specified number of characters from the given string. Syntax: mid (String, Start Position, length) Ex: x="$1245" msgbox mid(x,2,len(x)-1)
Ex: x="Rs.14258/-" msgbox mid(x,4,len(x)-5)

(3)

(4)

(5)

LTrim We can use this function to remove spaces from the left side of a string. Syntax: ltrim (String) Ex: x=" Sai" msgbox ltrim(x)

(6)

RTrim We can use this function to remove spaces from the right side of a string. Syntax: rtrim (String) Ex: x="Sai msgbox rtrim(x) "

(7)

Trim We can use this function to remove spaces from both the sides of a string. Syntax: trim (String) Ex: x=" Sai msgbox trim(x)
"

(8)

UCase We can use this function to convert Lower Case into Upper Case Syntax: ucase (String) Ex: x="sairam" msgbox ucase(x)

(9)

LCase We can use this function to convert Upper Case into Lower Case Syntax: lcase (String) Ex: x="SAIRAM" msgbox lcase(x)

(10)

Strreverse We can use this function to reverse the string. Syntax: strreverse (String) Ex: x="SAIRAM" msgbox strreverse(x) (11) Strcomp We can use this function to compare two strings Syntax: strcomp (String1, String2, Compare) 0 Binary Comparison Ex: x="SAIRAM" Y="sairam" 1 Textual Comparison

If strcomp(x,y,0)=0 then msgbox "Both are Equal" else msgbox "Both are not Equal" end if (12) Cint We can use this function to convert given value into Integer. Syntax: cint (expression)
Ex: x="10.54" msgbox cint(x)

(13) Cdbl We can use this function to convert the given value into double. Syntax: cdbl (expression) (14) Cstr We can use this function to convert given value into String. Syntax: cstr (expression) (15) Round We can use this function to rounding the value. Syntax: round (expression, No. of decimal places)
Ex: x="10.123456789" msgbox round(x,3)

(16)

Split It is used to return 0 Zero Based one dimensional array containing a specified no. of substrings. Syntax: Split (expression, delimiter) Ex: s="India is a great country" arr=split(s, " ") msgbox arr(0) India is msgbox arr(1) msgbox arr(2) a msgbox arr(3) great country msgbox arr(4) (17) Join

It is used to return a string created by joining a specified no. of substrings contained in an array. Syntax: join (list, delimiter) Ex: s="India is a great country" arr=split(s, " ") India msgbox arr(0) msgbox arr(1) is a msgbox arr(2) msgbox arr(3) great msgbox arr(4) country msgbox join(arr, " ") Note How to add two variables values. a="Sai" b="Ram" msgbox a&space(10)&b (18) Space It is used to create a specific No of spaces Syntax: space (Number)
(19)

Rem It is used to insert comment. Syntax rem statement Note Ctrl + M Comment Block Ctrl +Shift + M Uncomment Block

(20) Date It is used to return current system date. Syntax: msgbox date (21) Time It is used to return current system time. Syntax msgbox time

(22)

Now Syntax msgbox now

(23) Weekdayname Syntax msgbox weekdayname(weekday(date))

Note The default variable type in VB Script is Variant For Loop Syntax For i=1 to n step1 ......................... ......................... statement ......................... ......................... Next While Loop Syntax While condition ......................... statement ......................... Wend If Condition Syntax If condition Then statement else statement End If Ex: a=10 b=20 If a>b Then msgbox "a is greater" else msgbox "b is greater" End If Ex: a=10 b=20 c=30

Else If Syntax If condition Then statement else if condition then

statement else statement end if End If

If a>b and a>c Then msgbox "a is greater" else if b>c then msgbox "b is greater" else msgbox "c is greater" End If End If

Select Case It is similar to Switch Statement Syntax Select Case Variable Case "value1", "value2", Statement Case Value Statement Case else Statement End Select

Ex: x=inputbox("Enter alphabet") Select Case x Case "a", "e", "i", "o", "u" msgbox "It is Vowel" Case else msgbox "It is not Vowel" End Select

How to declare variables in VB Script? To declare variables in VB Script we are using one script. (i) Option Explicit To forcibly declare variables (This statement display error message for undeclared variables) (ii)Dim Variable1, Variable2, Variable3, .. Variables (To declare variables) METHODS GetVisibleText We can use this method to capture visible text. Code: Variable=Window("Window Name").Object("Object Name").GetVisibleText() Ex:

x = Dialog("Login").WinEdit("Agent Name:").GetVisibleText() msgbox x Output

GetROProperty We can use this method to capture run time property value into variables. Or We can use this method to capture object property from the application Code Variable = Window("Window Name").Object("Object Name").GetROProperty ("Property Name") Ex:

Dialog("Login").Activate x = Dialog("Login").WinButton("OK").GetROProperty("Enabled") msgbox x Output

GetTOProperty We can use this method to capture text object value into variable. Or We can use this method to capture object property value from the object Repository. Code

Variable = Window("Window Name").Object("Object Name").GetTOProperty ("Property Name") Ex:

Dialog("Login").Activate x = Dialog("Login").WinButton("OK").GetTOProperty("Enabled") msgbox x Output

Report Event: We can use this method to report an event to the Test Result Window. Syntax: reporter.ReportEvent EventStatus, ReportStepName, Details
micPass (0) micFail (1) micDone (2) micWarning (3)

Print It is used to display your specified message in Quick Test Print log. Syntax: Print Message Ex: a=10 b=20 If b=a+10 Then msgbox "b is equal to a" print "b is equal to a" reporter.ReportEvent micPass, "b is equal to a", "Test is Pass" else msgbox "b is not eqaul to a" print "b is not equal to a" reporter.ReportEvent micFail, "b is not equal to a", "Test is fail" End If

Step Generator (F7) It is used to generate steps in the Test pane without click on start Recording. Step Generator consists of statements in three categories such as (i) Functions (ii) Utility objects (iii) Test Objects. (i) (ii) Functions This category specifies all general and mathematical operations such as left, right, len, time, cint, cdbl, cstr, ltrim, rtrim, trim etc., Test Object This category specifies the operations which are performed on the objects such as Set, Select, Activate, SetSecure, Click, GetVisibleText, GetROProperty, GetTOProperty, GetItem, GetItemCount, GetContent . Etc., Utility Objects This category specifies all miscellaneous operations such as DataTableOperations, SystemUtil Operations, QCUtil Operations, Recovery Operations etc.,

(iii)

Ex Prepare script for calculation Test in Application Flight Reservation Option explicit Dim x,y,tot,i For i = 1 to 5 step 1 Window("Flight Reservation").Activate Window("Flight Reservation").WinMenu("Menu").Select "File;Open Order..." Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON" Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set i Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click x = Window("Flight Reservation").WinEdit("Tickets:").GetVisibleText() y = Window("Flight Reservation").WinEdit("Price:").GetVisibleText() y=mid(y,2, len(y)-1) tot = Window("Flight Reservation").WinEdit("Total:").GetVisibleText() tot=mid(tot,2, len(tot)-1) If cdbl(tot)=cdbl(x) * cdbl(y) Then reporter.ReportEvent micPass, "Calculation is correct", "Test is Pass" else reporter.ReportEvent micFail, "Calculation is not correct", "Test is fail" End If Next

Expected Activate Window Enter User Name and Password Click Ok If Next is enabled, User is authorized. If next is disabled, User is unauthorized.

Prepare Test Script for above expected. Option Explicit Dim x Dialog(Login).Activate Dialog(Login).WinEdit(User Name).Set suresh Dialog(Login).WinEdit(User Name).SetSecure xxxxxx Dialog(Login).WinButton(Ok).Click X= Dialog(Login).WinButton(Next).GetROProperty("Enabled") If x = True Then reporter.ReportEvent micPass, "Next is Disabled", "Test is Pass" else reporter.ReportEvent micFail, "Next is Enabled", "Test is fail" End If (I have prepared the same in VB and tested on the same) Option explicit Dim x, y VbWindow("frmLogin1").VbEdit("txtUserName").Set "suresh" VbWindow("frmLogin1").VbEdit("txtPassword").SetSecure "49422cd7dcd270949c6d92cc9fbcc1fcb1d0795d6e15" x = VbWindow("frmLogin1").VbButton("Next").GetROProperty("Enabled") If x = "False" Then reporter.ReportEvent micPass, "Next is Disabled", "Test is Pass" else reporter.ReportEvent micFail, "Next is Enabled", "Test is fail" End If VbWindow("frmLogin1").VbButton("OK").Click y = VbWindow("frmLogin1").VbButton("Next").GetROProperty("Enabled") If y = "True" Then reporter.ReportEvent micPass, "Next is Enabled", "Test is Pass" else reporter.ReportEvent micFail, "Next is Disabled", "Test is fail" End If

Automation Testing

37

Ex: Expected Activate Window Enter Name as Suresh Click Display Check Output Display the results in Quick Test Print Log Script Option explicit Dim x, Myarray VbWindow("Sample").VbEdit("Test1").Set "Suresh" VbWindow("Sample").VbButton("Display").Click x = VbWindow("Sample").VbEdit("Output").GetVisibleText() Myarray = split(x, " ") If Myarray (3) = "Suresh" Then print "Test is Pass" else print "Test is fail" End If Output

Data Driven Testing The repetition of the same test for more than one time with multiple test data is called Data Driven Testing. It is also known as Re-testing or iteration testingTesting. There are different ways. 1) Dynamic Test Data Submission (Key Board) 2) Through Data Table (Excel Sheet / Data Base) 3) Through Flat File (Notepad) 1) Dynamic Test Data Submission Some times we are conducting data driven test depending on multiple test data through Key Board. Key Board .. Test Script .. AUT (Application Under Test)

38

Automation Testing

Ex If you open record in Flight Reservation Application, Update Button is Disabled Option explicit Dim i, x, y For i=1 to 3 Step 1 y=inputbox ("Enter Order No.") With Window("Flight Reservation") .WinMenu("Menu").Select "File;Open Order..." .Dialog("Open Order").WinCheckBox("Order No.").Set "ON" .Dialog("Open Order").WinEdit("Edit").Set y .Dialog("Open Order").WinButton("OK").Click End with x = Window("Flight Reservation").WinButton("Update Order").GetROProperty ("Enabled") If x="False" Then reporter.ReportEvent micPass, "Update is disabled", "Test is Pass" else reporter.ReportEvent micFail, "Update is enabled", "Test is fail"
End If Next

Ex: Expected 1) Input 1 & Input 2 Values 2) Click OK 3) Check Results 4) Display Results in Quick Test Print ID 5) 10 Times Script Option explicit Dim i, x, y, z For i=1 to 10 step 1 x=inputbox ("Enter Input1") y=inputbox ("Enter Input2") VbWindow("Multiply").VbEdit("Input1").Set x VbWindow("Multiply").VbEdit("Input2").Set y VbWindow("Multiply").VbButton("OK").Click z = VbWindow("Multiply").VbEdit("Result").GetVisibleText() If cint(z) = cint(x) * cint (y) Then print "Test is pass" else
Automation Testing

39

print "Test is fail" End If Next

(i)

2) Through Data Table Some times we are conducting Data Driven Test depending on multiple Test data through data Table. They are (2) ways such as (i) Tester Test Own Data (ii)Import Data from database or other files. Tester Test Own Data Test Script

AUT

Script With Window("Flight Reservation") .WinMenu("Menu").Select "File;Open Order..." .Dialog("Open Order").WinCheckBox("Order No.").Set "ON" .Dialog("Open Order").WinEdit("Edit").Set datatable("test_data", dtGlobalSheet) .Dialog("Open Order").WinButton("OK").Click End with

x = Window("Flight Reservation").WinButton("Update Order").GetROProperty ("Enabled") If x="False" Then print "Update is disabled" else print "Test is fail" End If Navigation (1) Start recording Record required operation (Open Record) Enhance test script like as shown in above program Open data table Double Click on Data table Column Name Enter Column Name Click Ok Enter value in the data table Tools menu Click on Data Driver Select value which you want to parameterize Click Parameterize Select option [(i) Step by step parameterization (ii) Parameterize all] Click Next Click on Parameter Option Select Data table column Name click Ok Click Finish Click Ok Click Run Analyze results manually. (2) Record required operation Enhance Test Script like as shown in the above program Open Data Table Double Click on Data table Column Name enter Column Name click Ok Enter values in Data Table Replace input values in the script with below statement. Data table (Parameter Name, dtGlobalSheet / dtLocalSheet) (Data table column Name Or Data table (parameter Id, Sheet ID) (ii) Import Data from database or other files. (Before execution)

Design Time Data table 2 Run the script

Navigation Record required Operation Open Data table

Right Click on Data table

heetImportFrom dbSelect specific SQL Statement S ManuallySelect Maximum number of rows if required Next Click on Create to Select DSN Machine data Source Select DSN Ok In SQL Statement (Your specific statement Ex.: select * from Orders) Finish Replace Input value in the script with below statement Run Analyze Results manually.

Datatable(Parameter ID, Sheet ID) Difference between Design Time Data Table & Run Time Data Table Design time Data Table Run Time Data Table 1) It is viewed in the QTP Main 1) It is viewed in the QTP Test Test. Results. 2) It is created prior to the test 2) It is created in Test Results after execution. test execution. 3) It represents data from external 3) It represents a live version of sources. design Time Data table. Data Table Methods (1)Add Sheet:
We can use this method to add one new sheet to the run time

datatable.AddSheet (Sheet_Name) datatable.AddSheet (input)

data table. Syntax: Ex:

(2)Delete Sheet: We can use this method to delete one specified sheet from the Run Time Data table. Syntax: datatable.DeleteSheet (Sheet_ID) Ex: datatable.DeleteSheet (3) (3)GetSheetCount We can use this method to count number of sheets in the run time data table. Syntax: datatable.GetSheetCount Ex: msgbox datatable.GetSheetCount

42

Automation Testing

(4)

GetRowCount We can use this method to count number of rows in the 1st sheet (longest column) of the Run time data table.

Output Syntax: datatable.GetRowCount Ex: msgbox datatable.GetRowCount (5) GetSheet We can use this method to return a specified sheet from the Run Time data table. Syntax: datatable.GetSheet(SheetID) Ex: msgbox datatable. GetSheet(1).GetRowCount Value

(6)

We can use this method to set or get value of cell in the specified parameter and the current row of the Rum time data table. To set data Syntax: datatable.Value(Parameter_Name, Sheet_Name) = Value / variable Or datatable(Parameter_Name, Sheet_Name) = Value / variable To get data Syntax: Variable = datatable.Value(Parameter_Name, Sheet_Name) Or Variable = datatable(Parameter_Name, Sheet_Name) Ex: Option explicit Dim a, b, c a=datatable.Value (1,1) b=datatable.Value (2,1) c=cint(a)+cint(b) datatable.Value (3,1) = c Note: Default property of Datatable is value

Automation Testing

43

(7)

SetCurrentRow We can use this method to take a specified row as current row in the Run Time Datatable (By default it is 1st Row of 1st Sheet)

Syntax: datatable.SetCurrentRow(Row_Number) Ex: s="sairam" datatable.SetCurrentRow (3) datatable.Value (1,1) = s (8) SetNextRow We can use this method to take the row after the current Row as New Current Row in the Run time data table. Syntax: datatable.SetNextRow Ex: s="sairam" datatable.SetCurrentRow (3) datatable.SetNextRow datatable.Value (1,1) = s (9) SetPrevRow We can use this method to take the row before the current Row as New Current Row in the Run time data table. Syntax: datatable.SetPrevRow Ex: s="sairam" datatable.SetCurrentRow (3) datatable.SetPrevRow datatable.Value (1,1) = s (10) Import We can use this method to import Microsoft Excel File to the Runtime Data Table (Including all sheets) Syntax: datatable.Import Path of File Ex: datatable.Import F:\Inputdata.xls a. ImportSheet We can use this method to import a specified sheet of Microsoft Excel Sheet to the Runtime Data table. Syntax: datatable.ImportSheet Path of File, Source Sheet, Destination Sheet Ex: datatable.ImportSheet F:\Inputdata.xls,3,1

(11) Export We can use this method to export a copy of Run Time Data table to another location (Including all sheets) Syntax: datatable.Export Path of File Ex: datatable.Export F:\Outputdata.xls a. ExportSheet We can use this method to export a copy specified sheet of Run Time Data table to the existing or new Excel File. Syntax: datatable.ExportSheet Path of File, Sheet Name / Source Sheet Ex: datatable.ExportSheet F:\Outputdata.xls, 2 Ex: Prepare script for Update operation in Flight Reservation Application by taking data from Excel file during Runtime. Option explicit Dim rowcount, i, ordnum, strname, x,y datatable.AddSheet ("data") datatable.ImportSheet "C:\Documents and Settings\Sai Sarvani\Desktop\QTP\sample.xls", 1, "data" rowcount = datatable.GetSheet ("data").GetRowCount With Window("Flight Reservation").Dialog("Open Order") For i=1 to rowcount step 1 datatable.SetCurrentRow (i) ordnum=datatable.Value (1, "data") strname = datatable.Value (2, "data") Window("Flight Reservation").WinMenu("Menu").Select "File;Open Order..." .WinCheckBox("Order No.").Set "ON" .WinEdit("Edit").Set ordnum .WinButton("OK").Click Window("Flight Reservation").WinEdit("Name:").Set strname Window("Flight Reservation").WinButton("Update Order").Click wait (10) x = Window("Flight Reservation").ActiveX("Threed Panel Control"). GetVisibleText() y="Update Done..." If strcomp(x,y,1) = 0 Then
Automation Testing

45

End If

reporter.ReportEvent micPass,"Update done", "Test is pass" else reporter.ReportEvent micFail, "Update fail", "Test is fail"

Next End With

Database Connection: (i) Connection We can use this class to establish a connection to the specified database during Runtime Syntax: Set ConnectionObject = CreateObject (ADODB.Connection) conobj.open Provider=Provider Name Ex: MS Access conobj.open Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Path of Database SQL Server conobj.open Provider=sqloledb.1; Server=IP Address; uid=Username; pwd=xxx; database=Path of database Oracle conobj.open Provider=oraoledb.1; password=xxx(tiger) Server=xxx; userID=Username(scott);

Note: To get provider Name Open Notepad Save empty file with .udl Open that udl File Provider Tab Select Provider Next Select Database Test Connection Click Ok Click Ok Open the same file in Notepad (ii) Command We can use this class to execute specified DML Statements (Insert, Update, Delete) on connected database. Code: Set comobj=createObject (ADODB.Command) Comobj.ActiveConnection = conobj Comobj.CommandText = SQL Statement Comobj.Execute

(iii)
Code:

Recordset We can use this class to execute specified select statement on connected database and retrieve the results.

Set rsobj = createObject (ADODB.recordset) Rsobj.open SQL Statement, conobj

Ex Option explicit Dim comobj, conobj Set conobj=createobject("ADODB.Connection") conobj.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Sai Sarvani\Desktop\sample.mdb" Set comobj=createobject ("ADODB.Command") comobj.activeconnection = conobj comobj.commandtext = "Insert into emp values ('Appa Rao', 101, 10000)" comobj.execute conobj.close Set comobj = nothing Set conobj = nothing (iv) Nothing Noting is a keyword in VB Script, which is used to disassociate an object variable from the actual object.

Code Set objectname = nothing Ex: How to set multiple records into database table by taking the data from Excel file

Option explicit Dim comobj,conobj,rcount,i,ename,eno,esal

Set conobj=createobject("ADODB.Connection") conobj.open "PRovider=Microsoft.jet.oledb.4.0; data Source = C:\Documents and Settings\Sai Sarvani\Desktop\sample.mdb" Set comobj=createobject("ADODB.Command") comobj.activeconnection=conobj datatable.AddSheet ("data") datatable.ImportSheet "C:\Documents and Settings\Sai Sarvani\Desktop\ testdata.xls",1,"data"
47

rcount=datatable.GetSheet("data").getrowcount For i=1 to rcount step 1 datatable.SetCurrentRow (i) ename=datatable.Value (1, "data") eno=datatable.Value (2, "data") esal=datatable.Value (3, "data") comobj.commandtext = "insert into emp values ('"&ename&"', "&eno&", "&esal&")" comobj.execute Next conobj.close Set conobj = nothing Set comobj=nothing Ex: How to get data from database table?
Option explicit Dim conobj,rsobj,username,password Set conobj=createobject("ADODB.connection") conobj.open "PRovider=Microsoft.jet.oledb.4.0; data Source = C:\Documents and Settings\Sai Sarvani\Desktop\sample.mdb" Set rsobj=Createobject("ADODB.recordset") rsobj.open "select * from login", conobj rsobj.movefirst While not rsobj.eof username=rsobj("uid") password=rsobj("pwd") SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe" Dialog("Login").WinEdit("Agent Name:").Set username Dialog("Login").WinEdit("Password:").SetSecure crypt.Encrypt (password) Dialog("Login").WinButton("OK").Click

If window("Flight Reservation").Exist Then

reporter.ReportEvent micPass, "Login success", "Test is Pass" Window("Flight Reservation").WinMenu("Menu").Select "File;Exit" else reporter.ReportEvent micFail, "Login Fail", "Test is fail" Dialog("Login").Dialog("Flight Reservations").WinButton("OK").Click Dialog("Login").WinButton("Cancel").Click End If rsobj.movenext Wend rsobj.close conobj.close Set rsobj=nothing Set conobj=nothing Ex: Database Testing Option explicit Dim con, con1, rs, rs1, DOF, FF, FT, PN, NOTC,TOF,x Set con=createobject("ADODB.connection") con.open "DSN=QT_Flight32" Set rs=createobject("ADODB.recordset") Set con1=createobject("ADODB.connection") con1.open "Provider=microsoft.jet.oledb.4.0; data source=C:\Documents and Settings\Sai Sarvani\Desktop\sample.mdb" Set rs1=createobject("ADODB.recordset") rs1.open "select * from data",con1 rs1.movefirst While not rs1.eof DOF=rs1("dof") FF=rs1("flyfrom") FT=rs1("flyto") PN=rs1("pname") NOTC=rs1("not") TOF=rs1("tof") Window("Flight Reservation").WinMenu("Menu").Select "File;New Order" Window("Flight Reservation").ActiveX("MaskEdBox").Type DOF Window("Flight Reservation").WinComboBox("Fly From:").Select FF Window("Flight Reservation").WinComboBox("Fly To:").Select FT Window("Flight Reservation").WinButton("FLIGHT").Click Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select TOF Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click Window("Flight Reservation").WinEdit("Name:").Set PN Window("Flight Reservation").WinEdit("Tickets:").Set NOTC Window("Flight

Reservation").WinButton("Insert Order").Click wait(10) x = Window("Flight Reservation").WinEdit("Order No:").GetVisibleText() rs.open"select * from orders where Order_Number="&x,con If rs("Customer_Name")=PN and trim(rs("Tickets_Ordered"))=trim(NOTC) Then

reporter.ReportEvent micPass, "Data inserted", "Test is passed" else reporter.ReportEvent micFail, "Data is not incered", "Test is fail" End If rs1.movenext rs.close wend rs1.close con1.close con.close Set rs1=nothing Set rs=nothing Set con1=nothing Set con=nothing 3) Through Flat File Some times we are conducting data driven testing depending on multiple test data from Text files. To manipulate flat file content for testing we can prepare script like as below. Set fso = createobject(Scrpiting.filesystemobject) Set f=fso.opentextfile (Path of text file, mode[Read-1, Write-2, Append-8]) while f.atendoflile = false s=f.readline .. . .. .set s Wend f.close Ex Option explicit Dim fso,f,s,x

Set fso=createobject("Scripting.filesystemobject") Set f=fso.opentextfile ("C:\Documents and Settings\Sai Sarvani\Desktop\ input.txt",1) f.skipline With Window("Flight Reservation").Dialog("Open Order") While f.atendofline = false s=f.readline Window("Flight Reservation").WinMenu("Menu").Select "File;Open Order..." .WinCheckBox("Order No.").Set "ON" .WinEdit("Edit").Set s .WinButton("OK").Click x = Window("Flight Reservation").WinButton("Update Order").GetROProperty ("Enabled") If x="False" Then reporter.ReportEvent micPass, "Update is disabled", "Test is Pass" else reporter.ReportEvent micFail, "Update is enabled", "Test is fail" End If Wend End With f.close GetItemsCount We can use this method to count number of items in the combo box. Code Variable = Window("Window Name").WinComboBox("Combo Box Name"). GetItemsCount() Ex:
s = Window("Flight Reservation").WinComboBox("Fly From:").GetItemsCount() msgbox s

GetItem We can use this method to get a specified item from the Combo Box Code variable = Window("Window Name").WinComboBox("Combo Box Name"). GetItem(Item Number) Ex: s = Window("Flight Reservation").WinComboBox("Fly From:").GetItem(4) msgbox s GetContent We can use this method to get content of the Combo Box. Code

variable = Window("Window Name").WinComboBox("Combo Box Name"). GetContent() Ex s = Window("Flight Reservation").WinComboBox("Fly From:").GetContent() msgbox s Ex: How to count number of items in the Fly From Combo Box and how to display their name one by one. s = Window("Flight Reservation").WinComboBox("Fly From:"). GetItemsCount() msgbox s For i=0 to n-1 step 1 y = Window("Flight Reservation").WinComboBox("Fly From:").GetItem(i) msgbox y Next How to display FlyFrom Combo Box items one by one into Notepad Option explicit Dim fso,s,x,n Set fso=createobject("Scripting.filesystemobject") Set s=fso.opentextfile ("C:\Documents and Settings\Sai Sarvani\Desktop\ sample.txt",2) x = Window("Flight Reservation").WinComboBox("Fly From:"). GetItemsCount() For i=0 to n-1 step 1 n = Window("Flight Reservation").WinComboBox("Fly From:").GetItem(i) s.writeline n next s.close How to display Flyfrom Combo box items one by one into Runtime Data table and the same data table export to Excel Sheet datatable.AddSheet ("output").Addparameter "From", " "
n = Window("Flight Reservation").WinComboBox("Fly From:").GetItemsCount()

For i=0 to n-1 step 1 x = Window("Flight Reservation").WinComboBox("Fly From:").GetItem(i) datatable.SetCurrentRow (i+1) datatable.Value ("From", "output") =x Next datatable.ExportSheet "C:\Documents and Settings\Sai Sarvani\Desktop\ output1.xls", "output"

If you select one item from Fly From Combo Box, that item should be disappeared in Fly To Combo Box
n = Window("Flight Reservation").WinComboBox("Fly From:").GetItemsCount()

For i=0 to n-1 step 1 x = Window("Flight Reservation").WinComboBox("Fly From:").GetItem(i) Window("Flight Reservation").WinComboBox("Fly From:").Select x
m = Window("Flight Reservation").WinComboBox("Fly To:").GetItemsCount()

For j=0 to m-1 step 1 y = Window("Flight Reservation").WinComboBox("Fly To:").GetItem(j) If strcomp(x,y,0)<>0 Then reporter.ReportEvent micPass,"Items are not same", "test is Pass" else reporter.ReportEvent micFail,"Items are same", "Test is fail" End If Next Next How to count number of subfolders and files in a specified folder and how to display their names one by one? Prepare script for above expected? Option explicit Dim fso,f,sf,n,g,ft,m,k Set fso=createobject("Scripting.filesystemobject") Set f=fso.folder ("F:\XP") Set sf=f.subfolders n=sf.count msgbox n For each g in sf msgbox g.name Next Set ft=f.files m=ft.count msgbox m For each k in ft msgbox k.name Next

Synchronization Point The time map between tool and application build. To give waiting time to the tool there are (3) ways such as (i) Synchronization Point (ii) Wait (iii) Increase timeout (i) Synchronization Point

We can use this option to give waiting time to the tool based on specific object property value. Code Window("Window Name").Object("Object Name").WaitProperty "Property Name", Property Value, Timeout in Milliseconds. Navigation Place the cursor in your required place of test script Click on Start recording Insert MenuSynchronization PointShow object with Hand IconClick click Ok Select property Name (Enable) Enter Property Value (True) Set timeout in Milliseconds Click Ok Stop Recording. Note 1 Second = 1000 Milliseconds (ii) Wait We can use this statement to give fixed waiting time to the tool. Code Wait (Time in seconds) Ex: wait (10) (iii) Increase timeout QTP maintain 20 Seconds as default object synchronization Time out. That time out is not sufficient, then we will increase Timeout in settings. Navigation File Menu Settings Run Tab Change Object Synchronization time out click Ok. Start Transaction & End Transaction It is used to calculate the time taken to execute a block of statements or to estimate the speed of processing. Syntax Services.StartTransaction <"Transaction Name"> . Statements .. Services.EndTransaction <"Transaction Name">
54
Automation Testing

Navigation Place the cursor in the required position Insert Menu Start Transaction Enter Transaction Name Click Ok place the cursor at end position (or) where you want to stop transaction Insert Menu End Transaction Click Ok click run Analyze results manually. With We can use this statement to decrease the length of the program. Navigation Record required Operation Edit Menu Advanced Apply with to script (or) Ctrl + W (To remove with statement Ctrl + Shift + W) Ex: Window("Flight Reservation").WinMenu("Menu").Select "File;Open Order..." With Window("Flight Reservation").Dialog("Open Order") .WinCheckBox("Order No.").Set "ON" .WinEdit("Edit").Set s .WinButton("OK").Click End with Invoke Application It invokes an executable application only. Syntax invokeapplication "Path of application" SystemUtil We can use this object to control applications and processors during Run session. Syntax SystemUtil.BlockInput (Prevents keyboard & Mouse Input events from reaching the application) CloseDescendentProcesses Closes all processes opened by QuickTest CloseProcessByHwnd Closes a process that is the owner of a window with the specified handle. CloseProcessById Closes a process according to its Process ID (PID).

CloseProcessByName Closes a process according to its name. CloseProcessByWndTitle Closes all processes that are owners of windows with the specified title. Run Runs a file or application. UnblockInput Re-enables keyboard and mouse input events after a BlockInput statement was used to block them. How to close a specified file Ex: x = Window("Solitaire").GetROProperty("Hwnd") systemutil.CloseProcessByHwnd (x) Note After every object . After every variable How to invoke specific webpage through specific browser? Set ie=createobject("Internetexplorer.application") ie.visible = true ie.navigate "www.google.com" How to close all the browsers at a time Navigation Tools Menu Options Web Tab Advanced Select Browser cleanup under Run Time settings Ok Ok Put any script Run How to close Popups during Run Time a=10 b=20 Set obj=createobject("wscript.shell") If b=a+10 Then obj.popup "b is equal to a", 2 (Time in Seconds) else obj.popup "b is not equal to a", 5 End If

How to count number of links in a specific webpage and how to display their names one by one. Set x=description.Create x("micClass").value = "Links" 'set l = Browser("AXIN BANK").ChildObjects(x) Set l = Browser("AXIN BANK").Page("AXIN BANK").).ChildObjects(x) n=x.count For i=0 to n-1 step 1 y=x(i).getroproperty("text") msgbox y Next Spell Checks Set mw=createobject("Word.application") mw.visible = true Set wl=description.Create wl("micClass").value="Link" m = Browser("AXIN BANK").Page("AXIN BANK").ChildObject(wl) y=m.count For i=0 to y-1 step 1 op=m(i).GetROProperty("Text") mw.wordbasic.filenew mw.wordbasic.insert str s=mw.activedocument.spellingerrors.count If s=0 Then reporter.ReportEvent micPass,"No Mistakes were found","test is pass" else reporter.ReportEvent micFail,"Mistakes in"&str, "Test is fail" End If mw.documents.close(false) Next mw.quit

Automation Object Model To pre-configure QTP Test settings, we can use Automation Object Model Open Notepad prepare the script like as below and save the file with *.vbs extension set qtp = Createobject("QuickTest.Application") qtp.visible = true qtp.launch qtp.activateview "expertview" qtp.showpanescreen "datatable", false qtp.showpanescreen "debugviewer", True qtp.showpanescreen "activescreen", True
qtp.open "C:\Program Files\Mercury Interactive\QuickTest Professional\Tests\test7" qtp.test.run

qtp.quit Actions Action means a group of meaningful statements or a set of meaningful operations. They are (3) Types, such as (i) Non-reusable Action An action can be called by the test with which it is stored and it can be called only once. (ii) Reusable Action An action can be called multiple times by the test with which it is stored and by other tests. (iii) External Action A reusable action becomes External Action when we call that action from one test to another test. Call to New Action We can use this option to call a new action. Navigation Insert Menu Call to New Action Enter Action Name [Optional] Check Reusable Action or Uncheck Reusable Action Click Ok. How to Delete Action To delete action we can follow below navigation. Navigation: Open Action which you want to delete Edit Menu Action Delete Action Click Ok

How to rename Action Navigation Open Action which you want to rename Edit Menu Action Rename Action (Shift + F2) Enter name of the Action Click Ok. Call to Copy of Action We can use this option to call a copy of action from the current test or from any other test. Code: RunAction Copy of Action Name, oneiteration Navigation Insert Menu Click on Call to Copy Action Select Test Select Action Click Ok Note: If you call action using Call to Copy of Action option you can get action with Read and Write permission. Call to Existing Action We can use this option to call Reusable Action from the current test or from another test. Note: If we call Reusable Action using Call to Existing Action option we can get action with Read Only permission. Navigation Insert Menu Click on Call to Existing Action Select test Select Action Click on Ok. Syntax RunAction Action Name[Test Name], oneiteration Call to Win Runner We can use this option to call Win Runner Test or function to QTP Main Test. Navigation Insert Menu Call to Win Runner Action Browse Win Runner Test Path Click Ok. Split Action We can use this option to divide one action into 2 Actions. Navigation Open Action which you want to divide into 2 Actions Place the cursor at required position Edit Menu Action Split Action Enter meaningful Action Names with description Select Option [Independent or each other or Nested] Click Ok.
Automation Testing

59

Case Study (Frame Work) Test 1 Login

Test 2 Insert Log in to App Insert Order Logout

Test 3 Update
Log in to App Open Record Update Record Logout

Log in to App Logout

Navigation Record your required operations (Login; Open Record; Logout) Save the Reusable Actions in Specified location Take New test Prepare the script for above scenarios using those reusable actions Start Menu Programs QTP Test Batch Runner Batch Menu Add [Ins] Specify your required Tests Click Run (F5). Action Template To create Action Template we can follow Navigation. Open Notepad Enter your required information like as below. Project Name: Module Name: Created By: Created On: *************************************************************** Save the file in dat Folder with file name as actiontemplate.mst Take New test (when ever you are using new test the above information will be added in the top of the test as shown below.

Action Parameters There are two types of Parameters (i) Input Parameter (ii) Output Parameter Case 1: How to pass data to the external action. Test 1 RunAction Action1[Test2].oneiteration Nagesh,mercury

Test 2 .setparameter (uid) .setsecure crypt.encrypt (Parameter(pwd)) Navigation Record Required operation Replace constant values in Parameter Edit Menu Action Action Properties Parameters Tab Add Parameter [Enter Input Parameter Name same as in script] Ok Save Action New Test Call that reusable Action using calling to existing action option Pass values like as shown in the diagram.
Case 2: How to pass data from one action to another action. Action 1

Parameter (a) = 10

Action 2 .set parameter (a) Navigation Take Two Actions like as shown in the diagram in a same Test Open 1st Action Edit Menu Actions Action Properties Parameters Tab Add Output Parameter Name with Type (a, Any) Click Ok Open 2nd Action Edit Menu Actions Action Properties Parameters Tab Add Input Parameter Name with type (a, Any) Click Ok Keyword View st Right Click on 1 Action (Output) Action Call Properties Parameter Values Tab Enter variable in Store In field Click Ok Right Click on 2nd Action (Input) Action Call properties Parameter Values Tab Enter variable in Store in field in input parameter Click Ok Expert View Run Analyze Results manually

Environment Variables Environment Parameters especially useful for localization testing (If you want to test the application when the user interface strings are changing depending on selection of different languages) Environment parameters can be used for testing the same application on different browsers. Environment Variables are (2) Types such as (1) Built-in-variable (2) User defined variable. (1)Built-in-variable It represents the information about the Test and the system in which the test is running. Ex: Environment.Value ("OS") It will display Operating System Environment.Value ("OSVersion") It will display operating system version Environment.Value ("LocalHostName") It will display Local Host Name Environment.Value ("Test Name") It will display Test Name (2)User defined variable There are (2) Types such as (i) Internal Variables Internal Variables can be created in the Test and can be used in any Action of the same test. Ex: struid=environment.Value ("uid") strpwd=environment.Value ("pwd") SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\ samples\flight\app\flight4a.exe" With Dialog("Login") .Activate .WinEdit("Agent Name:").Set struid .WinEdit("Password:").SetSecure crypt.Encrypt (strpwd) .WinButton("OK").Click End With Navigation Records your required operation File Menu Settings Environment Tab Select variable type as User DefinedAdd Environment Name withValue Click Ok Click Ok Replace constant values in the script with environment variables likes as shown in the above script Click Run Analyze results manually

(ii)

External Variables External Variables will be present in the .xml file and we can associate this xml file to the test to use those variables in any action of that test. To create xml file with required variables we can prepare script likes as below. Open Notepad Prepare script like as below Save the file with .xml extension. <Environment> <Variable> <Name>uid</Name> <Value>suresh</Value> </Variable> <Variable> <Name>pwd</Name> <Value>mercury</Value> </Variable> </Environment>

How to load variables and values from external file before execution Navigation File Menu Settings Environment Tab Select Variable type as User defined Select load variables and values from external file Browse the file path Click Ok. How to load variables and values from external file during Runtime Code Environment.LoadFromFile Path of file Note: Built in variables are Read Only variables. Random Number We can use this option to pass Random Data. Syntax .set RandomNumber (1,10)
Automation Testing

63

Functions User defined Functions Like as programming language VB Script is also allows you to create User Defined Functions for repeatable operations. To create User Defined Functions we can follow below syntax. Public / Private Function Function_Name (Arguments) Statements End Function Ex Public function addition (x,y) z=x+y addition = z End Function '**************************************** a=10 b=20 c=addition (a,b) msgbox c How to create Library File Navigation Create required function for the required repeatable operations Select the script Copy the Script Paste the script in Notepad Save the file with .vbs extension How to associate library file to Test before execution Navigation File Menu Settings Resources Tab Add Associated function library Browse file path Click Ok. How to associate library file during Runtime Syntax executefile Path of file

64

Automation Testing

Case Study Navigation Record required operation as per scenario Create functions for them Take the script into Notepad Save the file with .vbs / .qfl extension Resources Menu Object Repository File Menu Export local objects Save the file in specified location Save Take required Environment variable in .xml file New test Associate all files like library file, environment variable file [File Menu Settings Resources Tab Click on Add file Browse that library file Environment Tab Select User Defined as variable type Select load variables and values from external file Browse File path Click Ok] Repository file [Resources Menu Associate Repositories Click on Add file Browse the Repository file path Associate with action] prepare the script using functions like as below. Ex: How to associate all files before execution struid=environment.Value ("uid") strpwd=environment.Value ("pwd") res=login(struid,strpwd) msgbox res res1=insert() msgbox res1 logout() Ex 2: How to associate all files during Runtime Option explicit Dim struid,strpwd,res,res1 executefile "C:\Documents and Settings\Sai Sarvani\Desktop\flightres.vbs" environment.LoadFromFile "C:\Documents and Settings\Sai Sarvani\Desktop\ QTP\environment.xml" repositoriescollection.Add "C:\Documents and Settings\Sai Sarvani\Desktop\ QTP\objectrepository.tsr" struid=environment.Value ("uid") strpwd=environment.Value ("pwd") res=login(struid,strpwd) msgbox res res1=insert() msgbox res1 logout()

Automation Testing

65

flightres.vbs
Function login (struid,strpwd) SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\ samples\flight\app\flight4a.exe" With Dialog("Login") .WinEdit("Agent Name:").Set struid .WinEdit("Password:").SetSecure crypt.Encrypt(strpwd) . WinButton("OK").Clic k End With If Window("Flight Reservation").Exist Then reporter.ReportEvent micPass,"Login Successful","Test is Pass" login = "Pass" else reporter.ReportEvent micFail,"Login Unsucessful","Test is fail" login=fail End If End Funct ion '************************************************************** ** Function insert() With Window("Flight Reservation") .Activate .WinMenu("Menu").Select "File;New Order" .ActiveX("MaskEdBox").Type "090909" .WinComboBox("Fly From:").Select "Denver" .WinComboBox("Fly To:").Select "Frankfurt" .WinButton("FLIGHT").Click .Dialog("Flights Table").WinList("From").Select 3 .Dialog("Flights Table").WinButton("OK").Click .WinEdit("Name:").Set "Suresh" .WinEdit("Tickets:").Set "3" .WinButton("Insert Order").Click End with wait (10)
x = Window("Flight Reservation").ActiveX("Threed Panel Control").GetVisibleText() y="Insert Done..."

If strcomp(x,y,1)=0 Then reporter.ReportEvent micPass,"Data inserted sucessfully","Test is Pass" insert=Pass else reporter.ReportEvent micFail,"Data not inserted","Test is fail" insert=fail End If EndF uncti on '************************************************************** ** Function logout() Window("Flight Reservation").Activate Window("Flight Reservation").WinMenu("Menu").Select "File;Exit" End Function Debug i) Pause ii) Step Into(F11) iii) Step Over (F10) iv) Step Out (Shift + F11) v) Run to Step (Ctrl + F10) vi) Debug from Step vii) Add to Watch (Ctrl + T) viii) Insert / Remove Breakpoint (F9) ix) Enable / Disable Breakpoint (Ctrl + F9) x) Clear all Breakpoint (Ctrl + Shift + F9) xi) Enable / Disable all Breakpoints

i)

Step InTo (F11) We can use this option to execute one line of statement, if the statement is function call or action call, then it will step into Function or Action.

ii)

Step Out (Shift + F11) We can use this option to execute remaining statements in the function of Action from the position of pointer [ ]

Recovery Scenario Manager To recover from unexpected events and errors that are occurred in the test environment during run session, we can use Recovery Scenario Manager. For good recovery, error must be known the occurrence is unknown. There are (4) Types of events such as (i) Application Crash An open application fails during Test Run. Navigation Resources Menu Recovery Scenario Manager Click New Click Next Select Application Crash as Trigger event Next Select selected executable application Next Select Recovery Operation [Keyboard, Mouse Operation, Close Application Process, function Call, Restart, Microsoft Windows] Next If

you want to check Add another operation else uncheck Next Next Enter Scenario Name Next Select Option Finish Close Save the scenario in specified location with .qrs qrs stands for QuickTest Recovery Scenario. (ii) Popup Window. To handle unwanted popups. Navigation Resources Menu Recovery Scenario Manager New Next Select Popup Window as Trigger event Next Click on Hand Icon Show unwanted window with Hand icon Next Next Select function call as Recovery Operation Next [Open Notepad Save empty file with .vbs extension] Browse the .vbs fie path Next Uncheck Add another Recovery Operation Next Select Post-Recovery Test Run Option [Repeat current step and continue, Proceed to Next step, Proceed to Next Action, Proceed to next test iteration, Restart current test run, Stop the Test Run] Next Enter Scenario Name Next Select Option Finish Save the scenario with .qrs Record required Recovery Operation [Click ok, Click Cancel] take the script into function Save the library file Click Run (iii) Test Run Error. A step in your test does not run successfully then Test Run Error can be raised. Navigation : Resources Menu Recovery Scenario Manager New Next Select Testrunerror Window as Trigger event Next select any error o Next Next Select function call as Recovery Operation Next [Open Notepad Save empty file with .vbs extension] Browse the .vbs fie path Next Uncheck Add another Recovery Operation Next Select Post-Recovery Test Run Option [Repeat current step and continue, Proceed to

Next step, Proceed to Next Action, Proceed to next test iteration, Restart current test run, Stop the Test Run] Next Enter Scenario Name Next Select Option Finish Save the scenario with .qrs Record required Recovery Operation [Click ok, Click Cancel] take the script into function Save the library file Click Run

(iv) Object State. The property values of an object in your application match specified values. You can specify property values for each object in the hierarchy. Resources Menu Recovery Scenario Manager New Next Select Object state Window as Trigger event Next Click on Hand Icon Show object with hand icon Next Next->select object property with value (enabled ,false)->click next Select function call as Recovery Operation Next [Open Notepad Save empty file with .vbs extension] Browse the .vbs fie path Next Uncheck Add another Recovery Operation Next Select Post-Recovery Test Run Option [Repeat current step and continue, Proceed to Next step, Proceed to Next Action, Proceed to next test iteration, Restart current test run, Stop the Test Run] Next Enter Scenario Name Next Select Option Finish Save the scenario with .qrs Record required Recovery Operation [Click ok, Click Cancel] take the script into function Save the library file Click Run Exception handling or Error Handling: On error resume next With Dialog("Login") .Activate If err.number<>0 Then

reporter.ReportEvent micWarning,err.description, "Test is fail" End If .WinEdit("Agent Name:").Set "suresh" If err.number<>0 Then reporter.ReportEvent micWarning,err.description, "Test is fail" End If .WinEdit("Password:").SetSecure "4944761a08cd30679de0bf816fd529bc" If err.number<>0 Then reporter.ReportEvent micWarning,err.description, "Test is fail" End If .WinButton("OK").Click End With AUTOMATION FRAMEWORK Framework means a set of concepts, assumptions and practices support fro Automated Software testing. There are (4) Types of frameworks, such as (i) Liner Framework (ii) Modular Framework (iii) Keyword driven Framework (iv) Hybrid Framework

(i) Liner Framework In this Framework we are preparing script for scenarios using Record and Playback method Navigation Record required operation nhance Test Script as per Scenario E Save test take the help of Test Batch Runner Tool to execute group of tests sequentially (ii) Modular Framework In this framework we are preparing script for scenarios using Reusable components / Reusable Actions.

Navigation Record required repeatable operations Save them in a specific location as reusable action Prepare script for scenarios using those reusable actions Save them Take the help of Test Batch Runner Tool to execute group of tests sequentially. (iii) Keyword driven Framework (Important) In this framework we are preparing script for scenario using functions and driven the script with keywords.

Navigation Record required operation Create functions for them Take the script into Notepad Save the file in corresponding location with (.vbs) extension Open Object Repository File Menu Export Local Objects Save the file in corresponding location File Menu Settings Environment Tab Select variable type as User-defined Take required variable with values Export Save the file in corresponding location Take required recovery scenarios Save the file in corresponding Location Open Excel File Enter Data in Excel File like as below.

Save the Excel File in specified location Open New Test Associate all files [.vbs, .xml, .qrs, .tsr] [File Menu Settings Environment Tab Variable type as User Defined] Select load variables and values from external file Browse the file path Resources Tab Add Resources file Browse library file path Recovery Tab Add Recovery File Browse Recovery File path Add Scenario Click Ok Resources Menu Associate Repositories Click on + to add repository file Select action to be associated Action click Ok prepare driver script as below. Ex: Datatable.addsheet(module) datatable.AddSheet ("testcase") datatable.AddSheet ("teststeps") datatable.ImportSheet "C:\Documents and Settings\Sai Sarvani\Desktop\Keyword FW\data.xls",1,"module" datatable.ImportSheet "C:\Documents and Settings\Sai Sarvani\Desktop\Keyword FW\data.xls",2,"testcase" datatable.ImportSheet "C:\Documents and Settings\Sai Sarvani\Desktop\Keyword FW\data.xls",3,"teststeps" mcount=datatable.GetSheet ("module").GetRowCount For i=1 to mcount step 1

datatable.SetCurrentRow (i) If mexe="Y" Then moduleid=datatable.Value (1,"module") tcount=datatable.GetSheet ("testcase").getrowcount For j=1 to tcount step 1 datatable.SetCurrentRow (j) moduleid1=datatable.Value (4,"testcase") tcexe=datatable.Value (3,"testcase") If moduleid=moduleid1 and tcexe="Y" Then tcid=datatable.Value (1,"testcase") tscount=datatable.GetSheet ("teststeps").getrowcount For k=1 to tscount step 1 datatable.SetCurrentRow (k) tcid1=datatable.Value (6,"teststeps") If tcid=tcid1 Then keyword=datatable.Value (3,"teststeps") Select Case keyword Case "li" struid=environment.Value ("uid") strpwd=environment.Value ("pwd") res=login(struid,strpwd) datatable.Value (5,"teststeps") = res Case "lo" res=logout() Case "ins" res=insert() datatable.Value (5,"teststeps")=res Case "or" order=environment.Value ("Order") res=openrec(order) datatable.Value (5,"teststeps") = res Case "up" strname=environment.Value ("name") res=update(strname) datatable.Value (5,"teststeps") = res End Select End If Next End If Next End If Next datatable.ExportSheet "C:\Documents and Settings\Sai Sarvani\Desktop\Keyword FW\result.xls","teststeps" (iv) Hybrid Framework

It is a combination of 2 or more frameworks.

Whats New In QTP 9.5


Maintenance Run Mode : Whenever object properties are changed after a new build then run the script in maitenance run mode to update object repository according to changes during run time

Process Guidance :
This is little more than more accessible help files. Maybe this is good for when you are first learning to record a test, but it doesnt seem to add much utility. Flow Pane

Available Keywords Pane


All Test Objects and functions in one handy location.Rapid test development with drag & drop.Object repository now also supports drag & drop

Resources Pane :
All resources associated with the test. You can see all your library file in this pane

Missing Resources Pane Relative Path Helper Improved Bitmap Checkpoint Web Extensibility :

1.Anyone can add support for new web controls 2.Rapid development in JavaScript 3.Solid infrastructure supplied by the Web add-in 4.Extensibility objects are first class citizens 5.Built-in toolkit: ASPAjax Tabbed browsing : Tabs identified as separate browsers.Same test compatible with tabbed and non tabbed browsers. New Technologies :

1.PowerBuilder 2. Oracle Forms 10 Apps 12 3.StingRay Objective Grid 10, 114. PeopleSoft 9.0 4.New Terminal Emulator versions 5.NET 3.5 (beta) New environments : 1.Windows Vista 64 bit 2. Eclipse 3.2, 3.3 3.Record on SWT 4. Firefox 3.0 5.Netscape 9

Script for practice if u interested Remove Attachment from QC Through QTP


The following function will Remove the specified attachment from the current test of QC when the file name provided Function RemoveQCAttachements(NameOfTheFile) var_count= QCUtil.CurrentTest.Attachments.NewList(").count For i= 1 to var_count If QCUtil.CurrentTest.Attachments.NewList(").Item(2).Name =NameOfTheFile Then AttachmentID = QCUtil.CurrentTest.Attachments.NewList(").Item(1).ID QCUtil.CurrentTest.Attachments.RemoveItem(AttachmentID) Else Reporter.ReportEvent micFail,Please provide the valid filename with extention,Please provide the valid filename with extention End If

Next End Function NameOfTheFile=abc.vbs Provide the file name with extension call RemoveQCAttachements(NameOfTheFile)

Copy an excel sheet to another excel


Following is the code to copy the conntents of a sheet in one excel to another excel sheet Set objExcel = CreateObject(Excel.Application) objExcel.Visible = True Set objWorkbook1= objExcel.Workbooks.Open(C:\Documents and Settings\mohan.kakarla\Desktop\1.xls) Set objWorkbook2= objExcel.Workbooks.Open(C:\Documents and Settings\mohan.kakarla\Desktop\2.xls) objWorkbook1.Worksheets(Sheet1).UsedRange.Copy objWorkbook2.Worksheets(Sheet1).Range(A1).PasteSpecial Paste =xlValues objWorkbook1.save objWorkbook2.save objWorkbook1.close objWorkbook2.close set objExcel=nothing Function UpLoadAttachmentToQC(FilePath) Set ObjCurrentTest = QCUtil.CurrentTest.Attachments Set ObjAttch = ObjCurrentTest.AddItem(Null) ObjAttch.FileName = FilePath ObjAttch.Type = 1 ObjAttch.Post ObjAttch.Refresh End Function FilePath=C:\abc.vbs Call UpLoadAttachmentToQC(FilePath)

Search for a particular value in Excel


Set appExcel = CreateObject(Excel.Application) appExcel.visible=true Set objWorkBook = appExcel.Workbooks.Open (filepath)opens the sheet Set objSheet = appExcel.Sheets(Sheet1) To select particular sheet With objSheet.UsedRange select the used range in particular sheet

Set c = .Find (nn) data to find For each c in objSheet.UsedRange Loop through the used range If c=nn then compare with the expected data c.Interior.ColorIndex = 40 make the gary color if it finds the data End If Set c = .FindNext(c) next search next End With objWorkBook.save objWorkBook.close set appExcel=nothing

PREPARED BY SURESH BUGATA Is there any spelling mistakes please ignore?