QAPlanet
QTP 10.0
M. Sreedhar Reddy
Quick Test Professional 10.0
by
M.Sreedhar Reddy (Test Architect)
www.qaplanet.in
1 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
What is “Automated Testing”? 1. “Automated Testing” is automating the manual testing process currently in use. 2. This requires that a formalized “Manual Testing process” currently exists in your company. Minimally, such a process includes: 1. Detailed test cases, including predictable “expected results”. 2. A standalone Test Environment, including a Test Database, such that the test cases are able to be repeated each time there are modifications made to the application. If your current testing process does not include the above points, you are never going to be able to make any Effective use of an automated test tool. The real use and purpose of automated test tools is to automate regression testing. This means that you must have or must develop a database of detailed test cases that are repeatable, and this suite of tests is run every time there is a change to the application to ensure that the change does not produce unintended consequences (errors). An “automated test script” is a program. Automated Script development, to be effective, must be subject to the same rules and standards that are applied to software development.
Benefits of Automation Testing: a) Fast b) Reliable c) Repeatable d) Reusable e) Comprehensive f) 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. www.qaplanet.in
2 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
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. Drawbacks of Automation Testing 1) It is expensive 2) We cannot automate all areas. 3) Lack of expertisation. 4) 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. Automated functional testing tools a. Open Source (FREE Tools) i. Badboy ii. Sahi iii. Selenium b. Commercial i. Test partner ii. Empirix eTest Suite iii. QTP
www.qaplanet.in
3 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Introduction to QTP 10.0 1. Mercury Interactive commercial Product. Now it’s take over by HP. 2. Functionality Testing Tool. 3. Used for Regression Testing. 4. Available in various versions like 6.5, 8.2, 9.0, 9.1, 9.2, 9.5, 10.0 and 11.0. 5. It supports Functional Testing of all popular environments, including Windows, Web, .Net, Visual Basic, ActiveX, Java, SAP, Siebel, Oracle Applications and PeopleSoft. 6. It supports 100% dynamic testing. 7. QTP Support for Both window and Web Application
8. QTP run only on windows. New features in QTP 9.0 vs. earlier versions From QTP 9.0 3. A new feature “Check Syntax” introduced under the “Tools” menu item (which is used for checking Syntax errors in the Script) 4. Function Definition Generator is directly introduced which is used for creating User Defined Functions easily. 5. A new menu item “Windows” is introduced in order to manage the windows. 6. New features are introduced for commenting and uncommenting a block of statements. 7. Window Themes are introduced that are used for changing the Look and Feel of QTP. 8. One can associate one or more Shared Repositories to an Action apart from its Local Repository. 9. New options like Object Repository Manager and Associate Repositories are introduced under “Resources” Menu item. (Object Repository Manager is used for creating and managing the Shared Repositories without having any connection to Test). 10.Some options related to Resources like Object Repository, Recovery Scenario Manager are moved from “Tools” menu item to new menu item “Resources”.
New features in QTP 9.2 vs. earlier versions From QTP 9.2
www.qaplanet.in
4 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
11.A new feature by name “Screen Recorder” is introduced which is used for recording the movie of the execution and can be played back during the Result Analyzer 12.From QTP 9.2 onwards, one can handle the Object Repositories dynamically with the help of a new utility object by name “RepositoriesCollection”. 13.Object Spy feature is enhanced in such a way that one can view continuously the different Objects information by keeping the Mouse pointer over that object. 14.QTP 9.2 is more compatible with the following Browsers Internet Explorer 7.0 Firefox 3.0
New features in QTP 10.0 vs. earlier versions From QTP 10.0
Centrally Manage and Share Testing Assets, Dependencies, and Versions in Quality Center 10.00 System Monitoring While Running Your Tests Improve Portability by Saving Copies of Tests Together with Their Resource Files Call Actions Dynamically During the Test Run Develop Your Own Bitmap Checkpoint Comparison Algorithm Centrally Manage Your Work Items and ToDo Tasks in the To Do Pane Improve Test Results Analysis with New Reporting Functionality Test Standard and Custom Delphi Objects Using the Delphi Add-in and Delphi Add-in Extensibility
Introduction to Quick Test Process Quick Test testing process consists of 7 main phases 1. Preparing to record
Test Environment
Test Conditions (Regression Test Case)
2. Recording a session on your application
Navigate according to Test Conditions
3. Enhancing your test
Adding logic and conditional statements
Parameterization
Inserting checkpoints
4. Debugging your test
Check that it operates smoothly and without interruption.
5. Run Test
www.qaplanet.in
5 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Check the behavior of your application
6. Analyzing the test results 7. Reporting defects
Add ins Default Add ins ActiveX Visual Basic Web Available Add ins Java .Net SAP
www.qaplanet.in
6 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Recording Modes Three Types of Recording Modes 1. Standard Recording (Default) 2. Analog Recording 3. Low level Recording 1).Standard Recording: Records the test in terms of GUI objects. Records the objects in your application and the operations performed on them. This mode is the default and takes full advantage of Quick Test’s test object model. 2).Analog Recording: Enables you to record the exact mouse and keyboard operations you perform in relation to either the screen or the application window.
Relative to Screen - VB Script Statement : Desktop.RunAnalog "Track1"
Relative to Window -
VB Script Statement :
Window ("Microsoft Internet").Run Analog "Track1" The track file called by the Run Analog method contains all your analog data and is stored with the action. Navigation Start Recording (F3)
Automation Menu
Analog Recording Settings (Shift + Alt + F3) Click on Click on Start Analog Record Operation Stop Recording (F4)
Analog Recording
Record your required
Generally we are using Analog Recording Mode to compare “Digital Signatures, Barcodes, Scientific Graphs etc., 3).Low level Recording: This mode records at the object level and records all run-time objects as Window. (For Generally Multimedia purpose) 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.
www.qaplanet.in
7 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Architecture of QTP Screen
5 1
2
6
3
5
1. 2. 3. 4. 5. 6.
Test Pane Active Screen Information pane Resources pane Data Table Debug Viewer
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.
www.qaplanet.in
8 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
2) Data Table Î 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.
www.qaplanet.in
9 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
QTP Layered Architecture Layer1
Logical name
Physical Description Layer2
Applicati on Layer3
www.qaplanet.in
10 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Object Oriented Programming Class a) A class is a blueprint or prototype from which objects are created. b) It’s an abstract idea of something. c) Class contains data members and member functions. Object: d) Object is an instance of a class. Example: Here person is a class which contains various attributes like Name, age, color, gender, height etc., each object contains their own values for above attributes. e) Objects are a representation of every item found in an application f) Objects (e.g. Button, Textbox) are elements within an application. Each object has the following elements Properties, Methods & Events g) Objects are referenced in code using dot notation objectName.Method() Properties These are characteristics of the object e.g. the text on a button. QTP uses this to recognize the object Methods These are built in functionality of the object. The VBScript code that we write (or record) actually makes calls to the methods of an object e.g. Reporter.ReportEvent() Here ReportEvent is the method of the Reporter object Events These are what can be done to an object. This is used by programmers to determine what an object does in response to an action you perform. It is however unused in QTP.
Object Identification How QTP learns objects in application? Stores Object as Test Object, Determining the class it fits. Mandatory properties h) Assistive properties i) Ordinal identifier j) Smart Identification
www.qaplanet.in
11 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Mandatory properties: While recording, for each test object class, QTP learns a list of mandatory properties to uniquely identify the object. Assistive properties: If not sufficient, QTP adds assistive properties until is has compiled a unique description Ordinal identifier: If no assistive properties are available or if not sufficient, QTP adds a special an ordinal identifier types as index, location and creation time of the objects are used to create a unique identification Smart Identification: A Smart Identification definition can help QuickTest identify an object, if it is present, even when the recorded description fails due to changes in one or more property values.
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 Ok Select Ordinal Identifier Click Ok Start Recording Record required Operation Stop Recording Run Analyze Results manually.
www.qaplanet.in
12 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Types of Objects 1. Test Object: It is an object that Quick test creates in test to represent the actual object in the application. It helps QTP to identify and check the object during the run session
2. Run-Time Objects: It is the actual object in your web site or application on which methods are performed during the run session
Object Repository a) Interface between QTP Script and the application b) Contains Logical Name and physical description of the objects c) The Object Repository window displays a tree of all objects in the current component or in the selected action. Navigation Go to Resources Menu > Click on Object Repository to open Object Repository Dialog box
Types of object repositories 1. Per action object repository: Stores objects that are associated with one specific component [Action], so that only that component can access the stored objects. 2. Shared object repository: Stores objects that can be accessed by multiple components
www.qaplanet.in
13 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Object Repository Manager a) You can open the Object Repository Manager by choosing Resources Menu and click on Object Repository Manager. b) The Object Repository Manager enables you to open multiple shared object repositories and modify them as needed. You can open shared object repositories both from the file system.
Operations performed by Object Repository Manager a) Creating New Object Repositories b) Opening Object Repositories c) Saving Object Repositories d) Closing Object Repositories e) Manipulating Objects in Shared Object Repositories
f) Managing Repository Parameters g) Modifying Test Object Details h) Locating Objects i) Performing Merge Operations j) Performing Import and Export Operations
www.qaplanet.in
14 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Object Repository Comparison Tool You open the Object Repository Comparison Tool by choosing Tools menu > click on Object Repository Comparison Tool in the Object Repository Manager.
Object Repository Merge Tool You open the Object Repository Merge Tool by choosing Tools menu > click on Object Repository Merge Tool in the Object Repository Manager.
Navigation - Merge and associate Repositories: www.qaplanet.in
15 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
1. Generate Script for IPS Add Agent and Observe objects are stored in Object Repository 2. Export and save the objects (OR1) of script1, using Object Repository (Go to Resources menu and click Object repository. In Object repository go to File menu and click on ‘Export Local objects’ and Save it into existing folder). 3. Generate Script for IPS Delete Agent and observe Objects are stored in Object Repository 4. Export and save the objects (OR2) of script2, using Object Repository 5. Go to QTP Resources menu Select Object repository manager 6. In ORM go to Tools menu click on Object repository Merge tool and Select Primary file as OR1 and Secondary File as OR2 and click on [Ok] 7. Save file as OR3 8. Associate OR3 into Script 1 and Script2, while navigating to Resources and click on associate repositories and add Repositories OR3 to Action1 and click on [Ok] 9. Run the scripts and observe results (Both scripts are used single repository-OR3)
Object Spy a) It is used to view object properties and Methods. b) Displays c) Object hierarchy tree d) Run-time object methods or Test object methods
www.qaplanet.in
16 of 110
QAPlanet
www.qaplanet.in
QTP 10.0
M. Sreedhar Reddy
17 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
CHECK POINTS 1) Standard Check Point We can use this check point to verify the property of an object. Ex: Verify Update Order Step Expected result Actual Status Step Name description 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 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] 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 (EnableTrue = 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 How to edit existing check point: Place the cursor on Check Point which you want to edit Right Click Point Properties Select property Change value or Rename Check Point Click Ok.
www.qaplanet.in
Check
18 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
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.
www.qaplanet.in
19 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
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 3
2 Actual Data 5 Expected Value = = Fail = ! Pass
Step 1: Step 2:
Connect to Database using DSN (Data Source Name) Execute Specified Select statement.
Step 3: Step 4: Step 5:
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
www.qaplanet.in
20 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
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) Text 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 Expected text fill in ‘constant’ Select Matching [(1) Match Case (2) Ignore Spaces (3) Exact Match (4) 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 Regular Expression. [A-Z] [a-z] [0-9]* [A-Z] [a-z] [ ] [A-Z] [a-z]* [A-Z] [a-z]* 5) Text Area Check Point We can use this Checkpoint to conduct test on Text present in the specified screen area. Navigation Start Recording
www.qaplanet.in
Insert Menu
Check Point
Click on Text Area Check
21 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
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 Ok Stop Recording Click run to analyze results manually. 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 Icon Click Select Web Table Click Ok Enter 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
www.qaplanet.in
22 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
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 Checkpoint Click Ok Stop Recording Run Analyze Results manually. Note Page Checkpoint, Table Checkpoint, Image Checkpoint, Accessibility Checkpoint, XML Checkpoint are applicable for Web Pages only.
Synchronization a) When you run tests, your application may not always respond with the same speed. For example, it might take a few seconds: a. For a progress bar to reach 100% b. For a button to become enabled. c. For a window or pop-up message to open. b) You can handle these anticipated timing problems by synchronizing your test to ensure that QuickTest waits until your application is ready before performing a certain step.
c) Options to synchronize the tests d) You can insert “Exist or Wait� statements that instruct QuickTest to wait until an object exists or to wait a specified amount of time before continuing the test.
e) Adding Exist and wait Statements f) You can use Exist and/or Wait statements in the expert view. g) Exist statement return a Boolean value indicating whether or not an object currently exists. h) Example: a. y=
browser
("WBMS
Home
Page").Dialog
("Microsoft
Explorer").Exist
www.qaplanet.in
23 of 110
Internet
QAPlanet
QTP 10.0
M. Sreedhar Reddy
i) Wait Statements instruct Quick Test to wait a specified amount of time before proceeding to the next. j) Example: Wait (10) Virtual object configuration: It is a process of making the QTP to treat the user-defined objects or nonrecognized areas as specific objects. for this QTP is provide two options 1. New Virtual object 2. Virtual object manager 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. 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", Activate Dialog("text:=Login").WinEdit("attached text:=Agent Name:"). Set "QA Planet" Dialog(""text:=Login”).WinEdit("attached text:=Password:"). SetSecure "4941cfd5b7a0bf66f6e9ded8bacb20164598f9ec" Dialog(""text:=Login").WinButton("text:=OK").Click
www.qaplanet.in
24 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
(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 TestingEx(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 ("attachedtext").value="Password:" Set but = description.Create but ("text").value = "OK" Dialog(dia).Activate Dialog(dia).WinEdit(uid).Set "QA Planet" 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 =
www.qaplanet.in
25 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
1016 Set but = description.Create but ("text").value = "OK" 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 Built in Methods (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)
(3)
Len We can use this function to find length of a string Syntax: len(String) Ex: x="sairam" msgbox len(x)
(4)
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)
(5)
LTrim We can use this function to remove spaces from the left side of a string. ltrim (String) Syntax:
www.qaplanet.in
26 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
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
1 Textual Comparison
Ex: x="SAIRAM"
www.qaplanet.in
27 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Y="sairam" 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)
www.qaplanet.in
28 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
(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) msgbox arr(1) msgbox arr(2) msgbox arr(3) msgbox arr(4)
India is a great countr y
(17) Join It is used to return a string created by joining a specified no. of substrings contained in an array. Syntax: Ex: join (list, delimiter) s="India is a great country" arr=split(s, " ")
msgbox msgbox msgbox msgbox
arr(0) arr(1) arr(2) arr(3)
msgbox arr(4)
India is a great countr y
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 www.qaplanet.in
29 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
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
www.qaplanet.in
Ex: a=10 b=20 If a>b Then msgbox "a is greater" else msgbox "b is greater" End If 30 of 110
QAPlanet
Else If Syntax If condition Then statement else if condition then statement else statement end if End If
QTP 10.0
M. Sreedhar Reddy
Ex: a=10 b=20 c=30
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 Ex: Select Case Variable x=inputbox("Enter alphabet") Case "value1", "value2", ……… Select Case x Statement Case "a", "e", "i", "o", "u" Case “Value” msgbox "It is Vowel" Statement Case else Case else msgbox "It is not Vowel" Statement End Select 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:
www.qaplanet.in
31 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
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:
www.qaplanet.in
32 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
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)
Functions This category specifies all general and mathematical operations such as left, right, len, time, cint, cdbl, cstr, ltrim, rtrim, trim etc., (ii) Test Object This category specifies the operations which are performed on the objects such as Set, Select, Activate, SetSecure, Click, www.qaplanet.in 33 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
GetVisibleText, GetROProperty, GetTOProperty, GetItem, GetItemCount, GetContent ‌. Etc., (iii) Utility Objects This category specifies all miscellaneous operations such as DataTableOperations, SystemUtil Operations, QCUtil Operations, Recovery Operations etc., 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
Data Driven Test 1. Parameterization 2. Data driven: Running the test with multiple set of data 3. Parameterization: 4. It is a variable that is assigned a value from various data sources or generator. 5. Parameter types: i. Data table ii. Random number iii. Environment variable 6. Create Data driven tests 7. QuickTest Pro enables you to create and run tests, which are driven by data stored in table. 8. When you test your application, you may want to check how it performs the same operations with multiple sets of data.
www.qaplanet.in
34 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
9. For example, 10.Suppose you want to check how your application responds to ten separate sets of data. You could record ten separate tests, each with its own set of data. 11.
Alternatively,
12.You could create a data-driven test with a loop that runs ten times.
13.
Parameterizing Tests - Steps for Parameterization a. Defining a Data Table Parameter b. Adding Parameter Values to a Data Table c. Modifying Steps Affected by Parameterization d. Running and Analyzing a Parameterized Test
14.
Results
15.After running a test, we can view a report of major events that occurred during the test run.
16.
If any iterations are failed/warning report it as a defect using Tack+ 3.3.
17.
Test Script
i. AUT
18. 19. 20. 21. 22.
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)
23. Dialog("Open rder").WinButton("OK").Click End with 24.x = Window("Flight Reservation").WinButton("Update Order").GetROProperty ("Enabled")
www.qaplanet.in
35 of 110
QAPlanet 25. 26. 27.
QTP 10.0
M. Sreedhar Reddy
If x="False" Then a. print "Update is disabled" else print "Test is fail" End If
28. Navigation 29. (1) 30. 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. 31. (2) 32. 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 Replace input values in the script with below statement. 33.Data Table a. Data table (“Parameter Name”, dtGlobalSheet / dtLocalSheet) (Data table column Name b. Or c. Data table (parameter Id, Sheet ID)
Difference between Design Time Data Table & Run Time Data Table Design time Data Table It is viewed in the QTP 1) Main Test. It is created prior to the 2) test execution. It represents data from 3) external sources.
Run Time Data Table It is viewed in the QTP 1) Test Results. It is created in Test Results 2) after test execution. It represents a live version 3) of design Time Data table.
Data Table Methods (1)Add Sheet: We can use this method to “add” one new sheet to the run time data table. Syntax: Ex: www.qaplanet.in
36 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
(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 (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
(6)
Value 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 www.qaplanet.in
37 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Note: Default property of Datatable is value Automation Testing (7)
43
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)
www.qaplanet.in
38 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
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\QAPlanet\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
reporter.ReportEvent micPass,"Update done", "Test is pass" Else End If
reporter.ReportEvent micFail, "Update fail", "Test is fail"
Next www.qaplanet.in
39 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
End With
Database Connection: Connectio (i) n 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; userID=Username(scott); password=xxx(tiger)”
Server=xxx;
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
www.qaplanet.in
40 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
(iii) Recordset We can use this class to execute specified select statement on Code 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\QAPlanet\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") www.qaplanet.in
41 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
conobj.open "PRovider=Microsoft.jet.oledb.4.0; data Source = C:\Documents and Settings\QAPlanet\Desktop\sample.mdb" Set comobj=createobject("ADODB.Command") comobj.activeconnection=conobj datatable.AddSheet ("data") datatable.ImportSheet "C:\Documents and Settings\QAP\Desktop\ testdata.xls",1,"data"
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\QAPlanet\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" www.qaplanet.in
42 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
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\QAPlanet\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 Window("Flight Window("Flight Window("Flight
Reservation").ActiveX("MaskEdBox").Type DOF Reservation").WinComboBox("Fly From:").Select FF Reservation").WinComboBox("Fly To:").Select FT 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 rs("Customer_Name")=P trim(rs("Tickets_Ordered"))=trim(NOTC If N and ) Then
reporter.ReportEvent micPass, "Data inserted", "Test is passed" else reporter.ReportEvent micFail, "Data is not incered", "Test is fail"
www.qaplanet.in
43 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
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\QAPlanet\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 www.qaplanet.in
44 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
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\QAPlanet\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 www.qaplanet.in
45 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
From:").GetItem(i) datatable.SetCurrentRow (i+1) datatable.Value ("From", "output") =x Next datatable.ExportSheet "C:\Documents and Settings\QAPlanet\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 Wait (Time in seconds) Ex: wait (10) Start Transaction & End Transaction It is used to calculate the time taken to execute a block of statements www.qaplanet.in 46 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
or to estimate the speed of processing. Syntax Services.StartTransaction <"Transaction Name"> ……………. Statements ……….. Services.EndTransaction <"Transaction Name"> 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).
www.qaplanet.in
47 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
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) www.qaplanet.in 48 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
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.coun t 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 Actions 1. Action is a set of one or more script statements to perform a specific task 2. It is a module which contains set of Script statements for a specific functionality of an Application and is integrated with Local Repository and Local DataSheet. 3. When we select new test in QTP, by default “Action1” will be available on QTP TestPane which is visible, but internally one more Action is maintained by QTP called “Action 0” in which the execution is started and ended [just like void main() in C Language].
4. We can insert maximum of 255 Actions in one single Test. 5. The Actions may be called in the Test individually (Independent Action) (or) one Action may be called from another Action (Nested Action).
www.qaplanet.in
49 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Benefits of Actions 1. It increases Readability i.e. instead of reading the total script; we can read Action by Action. 2. Debugging is very easy, i.e. we can find logical errors in the Script. 3. Makes code Reusable. 4. Scripts are easy to maintain. 5. Scripts are efficient. 6. Saves Development time 7. We can insert maximum of 255 Actions in one single Test. Types of Actions 1. Non-reusable action An action that can be used only in the test in which it was created, and only once.
2. Reusable action An action that can be called multiple times by the test in which it was created (the local Test) as well as by other tests. Insert > Call to New Action > Reusable Action 3. External action a) A reusable action called in another test. b) External actions are read-only in the calling test. They can be modified only in the test in which they were created. Creating New Actions a) Go to Insert menu > Click on call to New Action and observe Insert call to New Action dialog box b) Enter Action name and description and Select Reusable Action if you want to make the action reusable. c) Decide where to insert the action and select “At the end of the test” or “After the current step” and Click [OK] Inserting Actions You can insert an Existing Action in 2 ways 1. Insert call to Copy of Action 2. Insert call to Existing Action
1. Insert call to Copy of Action
www.qaplanet.in
50 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
a) Go to Insert menu and click on Copy of Action (or) right-click the action and select Insert Copy of Action and observe Select Action window b) Type a meaningful name for the action in the New action name box and give action description c) Specify where to insert the action: At the end of
the test (or) After the
current step and Click OK. d) The action is inserted into the test as an independent, non-reusable action. 2. Insert Call to Existing Action a) Go to Insert menu and click on ‘Call to Existing Action b) In the Select an action box, select the action you want to insert from the list c) Specify where to insert the action: At the end or after the current step and click on [OK] d) The action is inserted into the test as a call to the original action e) Pre Requisite: The Action that you need to insert should be a reusable action. Dividing the Test into Two Actions a) Select the step b) Go to Edit menu click on Action > Split Action, (or) right-click the step and choose Action > Split. c) Choose one of the following options: d) Independent of each other. Splits the action into two sibling actions. e) Nested (the second action is called by the first). Splits the selected action into a parent action whose last step calls the second, child action.
Action Template a) Whenever we are using Framework, the Script Template fields must be used by the Test Engineer for all Actions. b) To save the Time without writing Template fields for every Action manually, QTP provides a feature called “ACTION TEMPLATE”. c) If we define the Template fields in Action Template, here onwards, Template will be available by default for every new action. Navigation: a) Open Notepad and Define the Template fields b) Save the file as “ActionTemplate.mst”(mst=module script template) in QTP > “dat” folder. Note: 1. ActionTemplate.mst is the standard name.
www.qaplanet.in
51 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
2. Double Quotes are important, then only the Template can be seen for every action in QTP TestPane.
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 Defined” Add Environment Name with Value 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. www.qaplanet.in
52 of 110
QAPlanet
QTP 10.0
Open Notepad Prepare script like as below ‘.xml’ extension.
M. Sreedhar Reddy
Save the file with
<Environment> <Variable> <Name>uid</Name> <Value>QAPlanet</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) ………… …………
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. www.qaplanet.in 53 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
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”
www.qaplanet.in
54 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
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=inser t() msgbox res1 logout() Ex 2: How to associate all files during Runtime Option explicit Dim struid,strpwd,res,res1 executefile "C:\Documents and Settings\QAPlanet\Desktop\flightres.vbs" environment.LoadFromFile "C:\Documents and Settings\QAPlanet\Desktop\ QTP\environment.xml" repositoriescollection.Add "C:\Documents and Settings\QAPlanet\Desktop\ QTP\objectrepository.tsr" struid=environment.Value ("uid") strpwd=environment.Value ("pwd") res=login(struid,strpwd) msgbox res res1=insert() msgbox res1 logout()
www.qaplanet.in
55 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
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").Click 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 Function '********************************************************* ******* 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 EndFunction
'***************************************************** *********** Function logout() Window("Flight Reservation").Activate Window("Flight www.qaplanet.in
56 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
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 www.qaplanet.in
57 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
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 www.qaplanet.in
58 of 110
QAPlanet
QTP 10.0
ok, Click Cancel] take the script into function Click Run
M. Sreedhar Reddy Save the library file
(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
www.qaplanet.in
59 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Automation Framework a) Automation Frame work is nothing but an Automation planning for the project which is prepared by Test Lead. b) It helps to control the automation project in a better way. c) We are using our own framework which is prepared by my Test Lead. d) Automation Frame work contains: a. What functionalities to be automated b. What Approach to be followed c. What levels we have to use in order to develop the scripts (either it is Record and Playback or Actions or VB script etc.,) d. What naming conventions to be followed. e. Where to store the scripts f. Calling the scripts (using Batch runner, Actions etc,..) g. Directory structure of automation h. Where to store the Test results. Table of contents
1
What is Automation Framework?
2
Automation Testing objectives
3
Advantages of Automation Framework
4
Test Automation Life Cycle
5
Approach for Test Automation
6.
Guidelines followed for identification of Test Cases for automation
7.
Directory Structure
1) What is Automation FRAMEWORK? Automation Framework is a set of guidelines, a set of coding standards, a set of assumptions, concepts, and practices that provide support for automated software testing. It is like a plan for Automation Testing, in which it involves the identification of common functionality, defining coding standards and naming conventions, building Reusable Library Files, Identifying possible runtime exceptions and creating the Folder/Directory Structure before creating the actual scripts. www.qaplanet.in
60 of 110
QAPlanet
www.qaplanet.in
QTP 10.0
M. Sreedhar Reddy
61 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
2 Automation testing objectives Feature of automation a) Automation is particularly helpful for regression testing, as it allows regression testing of critical business with minimal effort. b) Consistent and repeatable test execution c) Ability to run tests unattended d) Automation testing can increase testing reliability, reusability and repeatability while decreasing the time and effort required completing a test cycle. e) Faster execution of individual tests which can: I. II.
Result in a shorter time frame for test execution, and Allow more thorough retesting of fixes.
a) Data Driven methodology provides the opportunity to significantly increase test coverage because more data input combinations and different data choices can be quickly executed b) Automated Testing provides increased test coverage through test execution repetition. Test scripts can be immediately reexecuted for system environment changes, such as: operating system upgrades, replacing old computer hardware, or checking for conflicts when other applications are added to the environment. c) Automated testing tools provide a central data repository for storing test step documentation which results in easier retrieval and reuse of existing test plans and test scripts d) The central data repository also stores the test execution results which provides easier retrieval and analysis of the test results
www.qaplanet.in
62 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
3 Advantages of Automation Framework The result of having a pre-defined Automation testing framework and reusable functions shall yield the following projected benefits. 1. Robust automation frameworks must be designed to reduce maintenance efforts 2. Market process improvement 3. Reduce automation effort in each automation testing engagement. 4. Project process improvement 5. Reduce automation effort during the design and development phases in automation testing life cycle. 6. Reduce the effort during the subsequent new functionalities
automation
4) Test Automation Life Cycle In traditional automation testing life cycle typically it would have the following phases Test Planning Generate the Basic Test
Functional Tool (QTP/WinRunner/SilkTool..)
Enhance the Test Test Execution Result Analysis
Test Management Tools Test Director/QC
www.qaplanet.in
Automation Life Cycle
63 of 110
of
QAPlanet 5
QTP 10.0
M. Sreedhar Reddy
Approach for Test Automation
Approach for Test Automation is used for building a strategy for automation starting from the Requirement phase till the deployment phase. Approach for automation begins by identifying the conditions and business rules given by the client and grouping similar conditions / business rules together as Test cases or Test Scenarios. Steps involved in Approach for Test Automation are as follows: • • • • • •
Requirement gathering from the users/stakeholders/business owner Understanding and Analyzing the Requirement Grouping the requirement into Test cases Develop Test Automation Framework. Develop automation test scripts, reusable library functions Verification / Validation of automation test scripts
For Quality deliverables, important things that should be followed are: • • • • • •
Following common coding structure for all the scripts Consistent coding conventions Use of Reusability for making code efficient and minimal Efficient use of Object Repository/Object identification techniques Incorporation of Error and Exception handling techniques Applying test data parameterization techniques using Data table/Environment variables etc…
www.qaplanet.in
64 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Guidelines followed for identification of Test Cases for automation • Tests that need to run once and those that need frequent human intervention are usually not worth the investment to automate and have not been considered for automation. •
Automated testing can be used to verify the performance of application paths that are used with a high degree of frequency when the software is running in full production e.g. creating customer records, Invoicing and other high volume activities where software failure would occur frequently.
•
Mission critical processes or core activities like sales order processing are prime candidates for automated testing and have been considered for automation.
•
Repetitive Testing
•
Applications with Long Life span – Longer the application in production greater the benefits from automation.
•
Avoid dynamic screens. Though possible to automate this increases the complexity of the script.
•
Avoid screens where objects are created dynamically
•
Avoid business scenarios where complex hardware is involved
•
Selecting a row in a table results is an additional challenge. Some automation tools provide the facility to read each row in a table and for focusing on a specific row. If the numbers of rows were very high the execution time of the script would be high. This leads to performance issues of the recorded script. Hence, it is better to improve the business scenario wherein tables with row selections figure by identifying a fixed row number. This scenario is faced very frequently in enterprise applications as in pricing tables leads to the complexity of the script and subsequently the effort.
•
Avoid scenarios that require high degree of coding while automating so that script’s complexity is reduced and high maintainability of the script is ensured.
www.qaplanet.in
65 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
1. Directory Structure The following diagram shows the directory structure to be followed in LiveTech automation Framework. Project Name Scripts
Library
Environment var Object Repository Test Data Exception handling Utilities
Name the root directory to represent Project_Name. Under the Project_Name folder, create the subdirectories Scripts, Library, Object repository, Exception handling, Test data and Utilities • •
•
Scripts folder usually the driver scripts. Divide reusable library files into different categories as per the requirement and usage as specified in the above section 7. This will be placed under the Library folder. Create reusable variable information as Environment variable.
•
The object repository files or similar files (For example GUI map files, object mapping files) shall be placed under the Object Repository folder.
•
Test data template and the related file shall be placed under Test Data folder. Keep all test data as specified in the test data path.
www.qaplanet.in
66 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
•
Recovery management scripts or the Exception/Error handling methods shall be placed under “Exception handling” folder
•
The files, documents and Utility scripts that would be used other than the above shall be placed in “Utility” folder Keyword driven Framework (Important)
EX:
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.
www.qaplanet.in
67 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
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 â&#x20AC;&#x153;+â&#x20AC;? to add www.qaplanet.in
68 of 110
QAPlanet
QTP 10.0
repository file Select action to be associated Action script as below.
M. Sreedhar Reddy click Ok
prepare driver
Example Frame Work Code: 'ProjectName:= 'ModuleName:= 'Tester Name:= 'Created date:= '************************************************************ **************************** Option explicit Dim Mcount,Tcount,Mexe,Moduleid,Moduleid1,Tcid,Tcid1,Tcexe,i,j,k,Tscount,Key word,Res Dim Strurl,Struid,Strpwd,StruidUser,StrpwdUser Datatable.AddSheet("Module") Datatable.AddSheet("Testcase") Datatable.AddSheet("Teststep") Datatable.ImportSheet "E:\IPS_Automation\Testdata\Keyword.xls",1,"Module" Datatable.ImportSheet "E:\IPS_Automation\Testdata\Keyword.xls",2,"Testcase" Datatable.ImportSheet "E:\IPS_Automation\Testdata\Keyword.xls",3,"Teststep" Mcount=datatable.GetSheet("Module").getrowcount For i=1 to Mcount step 1 datatable.SetCurrentRow(i) Mexe=datatable.Value(3,"Module") If Ucase(Mexe)="Y" Then Moduleid=datatable.Value(1,"Module") Tcount=datatable.GetSheet("Testcase").getrowcount For j=1 to Tcount step 1 datatable.SetCurrentRow(j) Tcexe=datatable.Value(3,"Testcase") Moduleid1=datatable.Value(4,"Testcase") If Moduleid=Moduleid1 and Ucase(Tcexe)="Y" Then Tcid=datatable.Value(1,"Testcase") Tscount=Datatable.GetSheet("Teststep").getrowcount For k=1 to Tscount step 1 datatable.SetCurrentRow(k) Tcid1=datatable.Value(6,"Teststep") If Tcid=Tcid1 Then Keyword=Datatable.Value(3,"Teststep") Select Case Keyword Case "OA" Strurl=Environment.Value("Strurl") Res=Openapp(Strurl) Datatable.Value(5,"Teststep")=Res www.qaplanet.in
69 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Case "LN" Struid=Environment.Value("Struid") Strpwd=Environment.Value("Strpwd") Res=Login_App(Struid,Strpwd) Datatable.Value(5,"Teststep")=Res Case "LO" Logout() Case "CA" Close_App() Case "AC" StruidUser=Environment.Value("StruidUser") StrpwdUser=Environment.Value("StrpwdUser") Res=Agent_creation(StruidUser,StrpwdUser) Datatable.Value(5,"Teststep")=Res Case "LU" StruidUser=Environment.Value("StruidUser") StrpwdUser=Environment.Value("StrpwdUser") Res=Login_User(StruidUser,StrpwdUser) Datatable.Value(5,"Teststep")=Res End Select End If Next End If Next End If Next Datatable.ExportSheet "E:\SIPS_Automation\Testlog\Result.xls","Teststep" (iv) Hybrid Framework It is a combination of 2 or more frameworks. VB Script methods used in QTP 9.2 InvokeApplication Method Description Invokes an executable application. Note: In most situations, you should use a SystemUtil.Run statement to run applications or to open files in their default application. For more information on the SystemUtil.Run statement, refer to the Standard Windows section of the QuickTest Professional Object Model Reference. The InvokeApplication statement is supported primarily for backward compatibility. Syntax www.qaplanet.in
70 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
InvokeApplication(Command [,StartIn]) Argument Type
Description
Command
String
The path and command line options of the application to invoke.
StartIn
String
Optional. The working folder to which the Command path refers.
Return Value Boolean. If the function fails to open the application, False is returned. Example The following example uses the InvokeApplication function to open Internet Explorer. InvokeApplication "E:\Program Files\Plus!\Microsoft Internet\IEXPLORE.EXE" Activate Method Description Activates (double-clicks) an item in the object's list. Syntax VbListView(description).Activate Item Argument Type Item
Description
The item to select from the list. The item value (with String quotes) or numeric index (without quotes) can denote the item. The first item in a list is numbered 0.
Example The following example double-clicks on the “MyFile“ item in the “Files“ list. VbWindow("frmMain").VbListView("Files").Activate "MyFile" or VbWindow("frmMain").VbListView("Files").Activate 2 Deselect Method Description Deselects an item in the object's list. Syntax VbListView(description).Deselect Item Argument Type Item
Description
The item to select from the list. The item value (with String quotes) or numeric index (without quotes) can denote the item. The first item in a list is numbered 0.
Example The following example deselects a selected item from the “Files“ list. VbWindow("frmMain").VbListView("Files").Deselect "MyFile" or VbWindow("frmMain").VbListView("Files").Deselect 3 www.qaplanet.in
71 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
GetItem Method Description Returns the value of the item specified by the index. Syntax VbListView(description).GetItem (Index) Argument Index
Type
Description
Number Numeric index of the item. Index values begin with 0.
Return Value String Example The following example returns the value of the second item in the list. itemVal = VbWindow("frmMain").VbListView("Files").GetItem (1) DropOnItem Method Description Ends the drag and drop operation by dropping the item onto a specified target item. Note: A DropOnItem statement must be preceded by a Drag or DragItem statement. Syntax VbListView(description).DropOnItem TargetItem [,Button] Argument
Type
TargetItem String
Button
Description The item on which to drop the dragged item. The logical name (with quotes) or numeric index (without quotes) can denote the item. The first item in a list is numbered 0.
Optional. The button used to click the object. 0=LEFT, 1=RIGHT, 2=MIDDLE. Default=0 (LEFT). Number Note: The same button must be used in both the DragItem and DropOnItem parts of the drag and drop operation.
Example The following example drags the item located at coordinates 55, 11 in the list and drops it onto item32 in the list. VbWindow("frmMain").VbListView("Files").Drag 55, 11 VbWindow("frmMain").VbListView("Files").DropOnItem "item32" EditLabel Method Description Activates the edit mode for an item in the objectâ&#x20AC;&#x2122;s list in preparation for changing its name. www.qaplanet.in
72 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Note: In order to rename the item, a Set statement must follow the EditLabel method. Syntax VbListView(description).EditLabel Item Argument Type Item
Description
The list item to edit. The item value (with quotes) or String numeric index (without quotes) can denote the item. The first item in a list is numbered 0.
Example The following example uses the EditLabel method to activate the edit mode for the third item in the list. The example then uses the Set method to change the name of the item to new name. VbWindow("Form1").VbListView("ListView1").Select "2" VbWindow("Form1").VbListView("ListView1").EditLabel "2" VbWindow("Form1").VbListView("ListView1").WinEdit("Edit").Set "new name" VbWindow("Form1").VbListView("ListView1").Select "3" VbWindow("Form1").VbListView("ListView1").Select "new name" ExtendSelect Method Description Selects an additional item from a multiple-selection list. Syntax VbListView(description).ExtendSelect Item Argument Type Item
Description
The item to select from the list. The item value (with String quotes) or numeric index (without quotes) can denote the item. The first item in a list is numbered 0.
Example The following example adds an item to a multiple-selection list in the “Files“ list. VbWindow("frmMain").VbListView("Files").ExtendSelect "MyFile" or VbWindow("frmMain").VbListView("Files").ExtendSelect 2 GetCheckMarks Method Description Retrieves the number and the value of items marked as checked. Note: You can use this method only for lists with 1000 or fewer items. Syntax VbListView(description).GetCheckMarks Return Value String
www.qaplanet.in
73 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Example In the following example, the string “checked“ gets values of checked items from “Files“. string 100,checked checked = VbWindow("frmMain").VbListView("Files").GetCheckMarks GetContent Method Description Returns all of the items in the object's list. Note: You can use this method only for lists with 1000 or fewer items. Syntax VbListView(description).GetContent Return Value String Example The following example returns the items in the “Files“ list. Contents=VbWindow("frmMain").VbListView("Files").GetContent GetSelection Description Returns all of the selected items in the object's list. Note: You can use this method only for lists with 1000 or fewer items. Syntax VbListView(description).GetSelection Return Value String Example The following example returns the selected items in the “Files“ list. VbWindow("frmMain").VbListView("Files").Select "bin" VbWindow("frmMain").VbListView("Files").ExtendSelect "dat" VbWindow("frmMain").VbListView("Files").ExtendSelect "encrypt" string 100, Selection Selection = VbWindow("frmMain").VbListView("Files").GetSelection ItemsCount Method Description Returns the number of items in the object's list. Syntax VbListView(description).ItemsCount Return Value Number Example The following example returns the number of items in the “Files“ list. NumberOfItems = VbWindow("frmMain").VbListView("Files").ItemsCount Select Method www.qaplanet.in
74 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Description Selects an item from the object's list. Syntax VbListView(description).Select Item [,Button, Offset] Argument
Type
Description
Item
String
The item to select from the list. The item value (with quotes) or numeric index (without quotes) can denote the item. The first item in a list is numbered 0.
Button
Integer
Optional. The button used to click the object. 0=LEFT, 1=RIGHT, 2=MIDDLE. Default=0 (LEFT).
Offset
Optional. The horizontal offset (in pixels) of the click location relative to the left margin of the item’s text. Number This argument can be used only if the button argument is defined.
Example The following example selects the item “22“ from the “Size“ list. VbWindow("frmMain").VbListView("Size").Select "22" or VbWindow("frmMain").VbListView("Size").Select 7 SelectRange Method Description Selects all list items between (and including) the two specified items. Note: This method is applicable only to lists that allow multiple selection. Syntax VbListView(description).SelectRange [Item1,] Item2 Argument Type
Description
Item1
Optional. The first item of the range. If the item1 argument is not specified, then the currently selected item is the first item of the range. String The item value (with quotes) or numeric index (without quotes) can denote the item. The first item in a list is numbered 0.
Item2
The last item of the range. The item value (with quotes) or numeric index (without String quotes) can denote the item. The first item in a list is numbered 0.
Example The following example selects all the items between (and including) “Red“ and “Blue“. VbWindow("frmMain").VbListView("Colors").SelectRange "Red", "Blue" www.qaplanet.in
75 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
The following example selects the items between the currently selected item and item number 7. VbWindow("frmMain").VbListView("Colors").SelectRange 7 SetItemState Method Description Sets the state of a check box icon of the specified item in a list view. Syntax VbListView(description).SetItemState Item, State Argument
Type
Description
Item
Variant
The item to select from the list. The item value (with quotes) or numeric index (without quotes) can denote the item. The first item in a list is numbered 0.
State
The object's state. The state can either be an index, or one of the following state constants: micChecked (1): Item is checked Number micUnchecked (0): Item is unchecked micClick (-1): Clicks the state icon micDblClick (-2): Double-clicks the state icon
Example The following example clears the check box icon of the “Child“ item in the list view. VbWindow("frmMain").VbListView("Files").SetItemState "Root1;Child", micUnchecked The following example sets the state icon of the “Child“ item in the list view, that has more than two states. VbWindow("frmMain").VbListView("Files").SetItemState "Root1;Child", 3 The following example double clicks the check box icon of the “Child” item in the list view. VbWindow("frmMain").VbListView("Files").SetItemState "Root1;Child", micDblClick Set Method Description Sets the radio button (as the selected radio button). Syntax VbRadioButton(description).Set Example The following example sets the “Business“ radio button. VbWindow("frmMain").VbRadioButton("Business").Set NextLine Method
www.qaplanet.in
76 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Description Moves the scroll bar downward, or to the right, the specified number of lines. Syntax VbScrollBar(description).NextLine [NumOfLines] Argument
Type
Description
Optional. The number of lines to move the scroll NumOfLines Number bar. Default = 1. Example The following example moves the scroll bar 7 lines down. VbWindow("frmMain").VbScrollBar("ScrollBar").NextLine 7
NextPage Method Description Moves the scroll bar downward, or to the right, the specified number of pages. Syntax VbScrollBar(description).NextPage [NumOfPages] Argument
Type
Description
Optional. The number of pages to move the scroll NumOfPages Number bar. Default = 1. Example The following example moves the scroll bar 7 pages down. VbWindow("frmMain").VbScrollBar("ScrollBar").NextPage 7 PrevLine Method Description Moves the scroll bar upward, or to the left, the specified number of lines. Syntax VbScrollBar(description).PrevLine [NumOfLines] Argument
Type
Description
Optional. The number of lines to move the scroll NumOfLines Number bar. Default = 1. Example The following example moves the scroll bar 5 lines up. VbWindow("frmMain").VbScrollBar("ScrollBar").PrevLine 5 PrevPage Method www.qaplanet.in
77 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Description Moves the scroll bar upward, or to the left, the specified number of pages. Syntax VbScrollBar(description).PrevPage [NumOfPages] Argument
Type
Description
Optional. The number of pages to move the scroll NumOfPages Number bar. Default = 1. Example The following example moves the scroll bar up 5 pages. VbWindow("frmMain").VbScrollBar("ScrollBar").PrevPage 5 Set Method Description Sets the scroll bar position. Syntax VbScrollBar(description).Set Value Argument Value
Type
Description
Number The scroll bar position to be set.
Example The following example sets the scroll bar to position 77. VbWindow("frmMain").VbScrollBar("ScrollBar").Set 77 CaptureBitmap Method Description Saves a screen capture of the object as a .png or .bmp image using the specified file name. The object is captured as it appears in the application when the method is performed. If only part of the object is visible, only the visible part is captured. Syntax VBObject(description).CaptureBitmap FileName Argument Type
FileName
Description
The full path of the .png or .bmp image to save. If you specify a relative path, the path is added to the test report path. Note: You cannot overwrite an existing .png or .bmp file String during a test run. Therefore, it is recommended to specify the file as a relative path so that the file will automatically be saved to a different folder in each test run.
www.qaplanet.in
78 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Example The following example uses the CaptureBitmap method to capture a screen shot of the txtName edit box after entering John Doe in the box. The file will automatically be saved to a different folder in each test run. VbWindow("frmMain").VbEdit("txtName").Set "John Doe" VbWindow("frmMain").VbEdit("txtName").CaptureBitmap "edit_JohnDoe.bmp" Check Method Description Executes a checkpoint. Note: You create checkpoints and define the property checks for the checkpoint using one of the Insert Checkpoint options. For more information, refer to the QuickTest Professional Userâ&#x20AC;&#x2122;s Guide. Syntax VBObject(description).Check CheckPoint(Name) Argument CheckPoint (Name)
Type
Description
The checkpoint object, which contains the expected Variant values to be compared and verified during the test run.
Note: If you want to retrieve the return value of a checkpoint, you must add parentheses around the name of the checkpoint in the statement. For example: a = browser("MyBrowser").page("MyPage").check (checkPoint("MyProperty")) Return Value Boolean Example The following example uses the Check method on the Name text. VbWindow("frmMain").VbLabel("Name").Check CheckPoint("Name")
ChildObjects Method Description Returns a list of all objects contained within the object (child objects). The method returns the child objects that fit the description specified (using the Description object). Syntax VisualBasicObject(description).ChildObjects(Description) Argument Type
Description
Description String The name of a defined Description object. Return Value Variant
www.qaplanet.in
79 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Example The following example uses the ChildObjects method to retrieve a set of child objects matching the description listed in the function call, and uses the method to display a message indicating how many objects are found with the specified description: none, one (unique), or several (not unique). Public Function CheckObjectDesription(parent, descr) Dim oDesc ' Create description object Set oDesc = Description.Create() arProps = Split(descr, ",") For i = 0 To UBound(arProps) arProp = Split(arProps(i), ":=") If UBound(arProp) = 1 Then PropName = Trim(arProp(0)) PropValue = arProp(1) oDesc(PropName).Value = PropValue End If Next ' Get all child objects with the given description Set children = parent.ChildObjects(oDesc) If children.count = 1 Then CheckObjectDesription = "Object Unique" ElseIf children.count = 0 Then CheckObjectDesription = "Object Not Found" Else CheckObjectDesription = "Object Not Unique" End If End Function MsgBox CheckObjectDesription(VbWindow("Form1"), "nativeclass:=ThunderRT6CommandButton", "text:=OK") MsgBox CheckObjectDesription(VbWindow("Form1"), "vbname:=cmdOK") MsgBox CheckObjectDesription(Desktop, "vbname:=Form1") Click Method Description Clicks on an object. Syntax VBObject(description).Click x, y [, Button] Argument
Type
Description
x
Number The x-coordinate of the click.
y
Number The y-coordinate of the click.
Button
Integer
www.qaplanet.in
Optional. The button used to click the object. 0=LEFT, 1=RIGHT, 2=MIDDLE. Default=0 (LEFT).
80 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Example The following example clicks a right mouse button at coordinates 47, 131 on the “OK“ button. VbWindow("frmLogin").VbButton("OK").Click 47, 131, 1 DblClick Method Description Double-clicks on an object. Syntax VBObject(description).DblClick x, y [, Button] Argument
Type
Description
x
Number The x-coordinate of the double-click.
y
Number The y-coordinate of the double-click.
Button
Integer
Optional. The button used to double-click the object. 0=LEFT, 1=RIGHT, 2=MIDDLE. Default=0 (LEFT).
Example The following example double-clicks a right mouse button at coordinates 73, 120 on “SysListView32“ object. VbWindow("frmMain").VbListView("SysListView32").DblClick 73, 120, 1 Drag Method Description Performs the “drag“ part of a drag and drop operation. Syntax VBObject(description).Drag x, y [, Button] Argument x, y
Button
Type
Description
Number
The coordinates within the object from which the object is dragged.
Integer
Optional. The button used to drag the object. 0=LEFT, 1=RIGHT, 2=MIDDLE. Default=0 (LEFT).
Example The following example drags and drops the InsertOrder frame. VbWindow("frmMain").VbFrame("Insert Order").Drag 10, 20 VbWindow("frmMain").VbFrame("Insert Order").Drop 30, 40 The following example drags the object from coordinates 10, 20 within the Test window and drops the object at coordinates 30, 40 within the OtherWindow window. VbWindow("Test").Drag 10, 20 VbWindow("OtherWindow").Drop 30, 40 or within the same window. VbWindow("Test").Drag 10, 20 www.qaplanet.in
81 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
VbWindow("Test").Drop 30, 40 Drop Method Description Performs the “drop“ part of a drag and drop operation. Syntax VBObject(description).Drop x, y [, Button] Argument x, y
Button
Type
Description
Number
The coordinates of the object onto which the object is dropped.
Integer
Optional. The button that is released to drop the object. 0=LEFT, 1=RIGHT, 2=MIDDLE. Default=0 (LEFT).
Example The following example drags and drops the InsertOrder frame. VbWindow("frmMain").VbFrame("Insert Order").Drag 10, 20 VbWindow("frmMain").VbFrame("Insert Order").Drop 30, 40 The following example drags the object from coordinates 10, 20 within the Test window and drops the object at coordinates 30, 40 within the OtherWindow. VbWindow("Test").Drag 10, 20 VbWindow("OtherWindow").Drop 30, 40 or within the same window. VbWindow("Test").Drag 10, 20 VbWindow("Test").Drop 30, 40 Exist Method Description Checks that an object exists. Syntax VBObject(description).Exist([Timeout]) Argument Timeout
Type Number
Description Optional. Specifies the length of time in seconds to search for the object.
Return Value Boolean Example The following example uses the Exist method to determine the existence of the “Business“ radio button. exists = VbWindow("frmMain").VbRadioButton("Business").Exist() GetROProperty Method
www.qaplanet.in
82 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Description Returns the current value of the property for the object in the application. Syntax VBObject(description).GetROProperty(Property [, in_PropData]) Argument
Type
Property
String Property to retrieve from the object.
in_PropData N/A
Description
Not in use.
Return Value Variant Example The following example uses the GetROProperty method to retrieve the state of a check box object. CheckState = VbWindow("frmMain").VbCheckBox("Insert Order").GetROProperty ("Value") ' CheckState contains "OFF" GetTextLocation Method Description Checks whether a specified text string is contained in a specified window area. If the text string is located, the location coordinates are also returned. Notes: This method is supported only in Windows NT, Windows 2000, and Windows XP. You can also check whether a specified text string is contained in a specified window area using the TextUtil object. For more information, see TextUtil Object. Syntax VBObject(description).GetTextLocation (TextToFind, Left, Top, Right, Bottom, MatchWholeWordOnly) Argument TextToFind
Type
Description
String
The text string you want to locate.
InOut, Number
These arguments define the search area within the window or screen. Set all coordinates to -1 to search for the text string within the objectâ&#x20AC;&#x2122;s entire window. The method returns the coordinates of the rectangle containing the first instance of the text into these variables if the text is found.
MatchWholeWordOnly Boolean
Optional. If true, the method searches for occurrences that are whole words only and not part of a larger word. If false, the method does not restrict the results to
Left, Top, Right, Bottom
www.qaplanet.in
83 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
occurrences that are whole words only. Default value = True Return Value Boolean Example The following example uses the GetTextLocation method to retrieve all of the text within the object. l = -1 t = -1 r = -1 b = -1 result = VbWindow("frmMain").VbEdit("txtName").GetTextLocation ("2002", l, t, r, b) if result then MsgBox "Text found. Coordinates:" & l & "," & t & "," & r & "," & b end if GetTOProperties Method Description Returns the collection of properties and values that QuickTest uses to identify the object (the test object description saved in the object repository). Syntax VBObject(description).GetTOProperties Return Value Variant Example The following example uses the GetTOProperties method to retrieve the list of properties and values used to identify the “cmbTo” combo box. Set obj = VbWindow("frmMain").VbComboBox("cmbTo").GetTOProperties The following example returns a Property collection containing the test object description (properties and values) for the Help VbButton object, and then displays the property name and value of each property in the returned collection. Set theTestObject = VbWindow("Login").VbButton("Help") Set Props = theTestObject.GetTOProperties PropsCount = Props.Count For i = 0 To PropsCount-1 PropName = Props(i).Name PropValue = Props(i).Value MsgBox PropName & " = " & PropValue Next GetTOProperty Method Description Returns the value of the property from the test object description. www.qaplanet.in
84 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Notes: GetTOProperty differs from the GetROProperty method. GetTOProperty returns the value from the test object's description. GetROProperty returns the current property value of the object in the application during the test run. You can use the GetTOProperty method to retrieve the values of only those properties that are included in the test object description. Specifying a property that is not included in the test objectâ&#x20AC;&#x2122;s description results in a warning status for the step and the test. For more information on adding properties to a test object description, refer to the QuickTest User's Guide. Syntax VBObject(description).GetTOProperty(Property) Argument Type Property
Description
String
Property whose value is retrieved from the object description.
Return Value Variant Example The following example uses the GetTOProperty method to retrieve the RegExpWndClass property from the Object Repository. Dim ObjectName RegExpWndClass = VbWindow("Test").GetTOProperty("RegExpWndClass") The following example uses the GetTOProperty method to retrieve the value of the VbLabel object's title property from the Object Repository. title = VbWindow("frmMain").VbLabel("Name").GetTOProperty("title") GetVisibleText Method Description Returns the text from the specified area. The area is defined by pairs of coordinates that designate two diagonally opposite corners of a rectangle. Notes: This method is supported only in Windows NT, Windows 2000, and Windows XP. You can also retrieve the text of a window handle. For more information, see TextUtil Object. Syntax VBObject(description).GetVisibleText ([Left, Top, Right, Bottom]) Argument
Left, Top, Right, Bottom
Type
Description
Optional. These arguments define the search area within the objectâ&#x20AC;&#x2122;s window. Number Note: If these arguments are not specified, the method returns all of the text within the visible part of the specified object.
Return Value String www.qaplanet.in
85 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Example The following example uses the GetVisibleText method to retrieve the text from the “Test” window. If the returned string contains the “login:” substring, the Type method is used to type the “guest” string in the window. TestText = VbWindow("Test").GetVisibleText if InStr(1 ,TestText, "login:", 1) > 0 then VbWindow("Test").Type "guest" End If The following example uses the GetVisibleText method to retrieve the text within the specified coordinates. If the returned string is not “Catalog”, the ReportEvent method is used to report a failed step. theText = VbWindow("frmMain").VbLabel("Name").GetVisibleText (16, 25, 56, 92) if theText <> "Catalog" then Reporter.ReportEvent micFail, "Traders", "Text check failed" end if MouseMove Method Description Moves the mouse pointer to the designated position inside the object. Syntax VBObject(description).MouseMove x, y Argument
x, y
Type
Description
The position of the mouse pointer, expressed as x and y (pixel) coordinates. Note that the specified Number coordinates are relative to the upper left corner of the object.
Example The following example moves the mouse pointer to the position (20, 30) inside the “Insert Order“ button. VbWindow("frmMain").VbButton("Insert Order").MouseMove 20, 30 Object Property Description Accesses the internal methods and properties of an ActiveX object. For more information, see The Object Property. Syntax VisualBasicObject(Description).Object.Method_to_activate( ) or Set myObj=VisualBasicObject(Description).Object myObj.Method_to_activate() Example In the following example, suppose the AboutButton method is supported for your Visual Basic object. To activate the AboutButton method, you would insert the following statement into your test script: Set value=VbWindow("frmLogin").VbButton("Submit").Object.AboutButton() Alternatively, you could insert the following: Set MyObj=VbWindow("frmLogin").VbButton("Submit").Object. www.qaplanet.in
86 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
MyObj.AboutButton() Output Method Description Inserts the value of an object into an output value column. Note: You insert output values in your test using one of the Insert Output Value options. For more information, refer to the QuickTest Professional User’s Guide. Syntax VBObject(description).Output CheckPoint(Name) Argument
Type
Checkpoint (Name)
Variant
Description The output object, which contains the name(s) of the column(s) to which to output the data.
Example The following example uses the Output method to place a text item into an output value column entitled Submit. VbWindow("frmLogin").VbButton("Submit").Output CheckPoint ("Submit") SetTOProperty Method Description Sets the value of a property in the test object description. Notes: SetTOProperty changes the property values used to identify an object during the test run. It has no effect on the Active Screen or the values saved in the Object Repository for the object. You can only set values of properties that are included in the test object description. For more information on adding properties to a test object description, refer to the QuickTest User's Guide. Syntax VBObject(description).SetTOProperty Property, Value Argument
Type
Description
Property
String
Test object property to set.
Value
Variant The value to assign to the listed property.
Example The following example uses the SetTOProperty method to set the index of a window’s description. VbWindow("Test").SetTOProperty "Index", 2 Type Method Description Types the specified string in the object.
www.qaplanet.in
87 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Note: Although the Type method is supported for most objects, if you enter a Type statement for an object in which a user cannot enter text, the method has no visual effect. Syntax VBObject(description).Type String Argument Type String
Description
The text string and/or constants representing nonString alphanumeric keys. For a list of constants, see Type Constants.
Example The following example presses the “OK” button by pressing the “Enter” key VbWindow("frmLogin").VbButton("OK").Type micReturn WaitProperty Method Description Waits until the specified object property achieves the specified value or exceeds the timeout before continuing to the next step. Returns TRUE if the property achieves the value, and FALSE if the timeout is reached before the property achieves the value. Note: A FALSE return value does not indicate a failed step. Syntax VBObject(description).WaitProperty(PropertyName, PropertyValue[,Timeout]) Argument
Type
Description
PropertyName String
The name of the property whose value is checked.
PropertyValue
Variant
The value to be achieved before continuing to the next step.
Timeout
Optional. The time, in milliseconds, after which QuickTest continues to the next step if the specified value is not achieved. If no value is Number specified, QuickTest uses the time set in the Object Synchronization Timeout option in the Run tab of the Test Settings dialog box.
Return Value Boolean Example In the following example, the program waits until the “No“ button is enabled or 3 seconds (3000 milliseconds) pass. y= VbWindow("frmLogin").VbButton("&No").WaitProperty("enabled",True,3000) VbButton Test Object Properties The table below contains the pre-defined properties for the VbButton object. You can also view a complete list of properties for a specific object using the www.qaplanet.in
88 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Object Spy. For more information on test objects, descriptive programming, and the Object Spy, refer to the QuickTest Userâ&#x20AC;&#x2122;s Guide. Tip: In addition to using the test object properties described in the table below, you can also access an objectâ&#x20AC;&#x2122;s internal properties using the Object property. For a list of the object's internal properties and methods see: http://msdn.microsoft.com/library/default.asp?url=/library/enus/cmctl198/html/vbobjButton.asp Property Name
Description
abs_x
The object's absolute x-coordinate (left) relative to the screen (in pixels).
abs_y
The object's absolute y-coordinate (top) relative to the screen (in pixels).
BackColor
The background color of an object.
cancel
Indicates whether the button object is the Cancel button on a form. Possible values: True: The button object is the Cancel button. The Cancel property gives the user the option of canceling uncommitted changes and returning the form to its previous state. False: (Default) The button object is not the Cancel button.
caption
The text displayed in or next to the object.
default
Indicates whether the button object is the default button on a form. Possible values: True: The button object is the default button. The user can choose the button object (invoking its Click event) by pressing ENTER. Any other control with the focus does not receive a keyboard event (KeyDown, KeyPress, or KeyUp) for the ENTER key unless the user has moved the focus to another button object on the same form. In this case, pressing ENTER chooses the command button that has the focus instead of the default command button. False: (Default) The button object is not the default button.
enabled
Indicates whether the object is enabled. Possible values: True False
focused
Indicates whether the object has the focus. Possible values: True
www.qaplanet.in
89 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
False
FontBold
Indicates whether the font style is bold. Possible values: True False (Default)
FontItalic
Indicates whether the font style is italic. Possible values: True False (Default)
FontName
The font used to display text in the control.
FontSize
The size (in points) of the font used for text displayed in the control.
FontStrikethru
Indicates whether the font style is strikethrough. Possible values: True False (Default)
FontUnderline
Indicates whether the font style is underlined. Possible values: True False (Default)
height
The object's height (in pixels).
hWnd
The (Microsoft Windows) handle of the run-time object's window. For more information, see hWnd Property.
index
The ordinal identifier that QuickTest assigns to the object to indicate the order in which the object appears in the code relative to other objects with an otherwise identical description. This property cannot be used with GetROProperty. This property is an optional property. Values begin with 0. For more information, see “The Index Property”.
left
The distance between the internal left edge of an object and the left edge of its container.
location
The ordinal identifier that QuickTest assigns to the object to indicate where the object appears within the window, frame, or dialog box. Values are assigned from top to bottom, and left to right. This property cannot be used with GetROProperty. This property is an optional property. Values begin with 0. For more information, see “The Location Property”.
name
The object’s name.
www.qaplanet.in
90 of 110
QAPlanet NativeClass
QTP 10.0
M. Sreedhar Reddy
The object's window class name.
RegExpWndClass The permanent part of the MFC window class. RegExpWndTitle
The constant part of the window title.
style
Indicates the appearance and behavior of the button in a toolbar control. Possible values: 0 (tbrDefault): (Default) Button. 1 (tbrCheck): Check. 2 (tbrButtonGroup): Button group. 3 (tbrSeparator): Separator. 4 (tbrPlaceholder): Placeholder. 5 (tbrDropDown): MenuButton drop down list.
TabIndex
The tab order of the object within its parent form.
TabStop
Indicates whether a user can use the TAB key to give the focus to the object. Possible values: True (Default) False
tag
An expression that stores any extra data needed for your program. This property is generally used to identify objects.
text
The text associated with the object.
ToolTipText
The text displayed when the mouse pauses over the control.
top
The distance between the internal top edge of an object and the top edge of its container.
value
Indicates whether the object is chosen. Possible values: True False (Default)
visible
Indicates whether the object is visible. Possible values: True False
width
The object's width (in pixels).
window id x www.qaplanet.in
The object's window identifier. The object's x-coordinate (left) relative to the parent window (in pixels). 91 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
The object's y-coordinate (top) relative to the parent window (in pixels).
y
hWnd Property Description Returns a handle to a run-time object's window. Note: This property is useful when you need to call Win32 API functions. Syntax VbButton(description).GetROProperty("hWnd") Example The following example uses the hWnd property to change the title of the dialog. 'Declare WinAPI SetWindowText function Extern.Declare micLong, "SetWindowText", "user32.dll", "SetWindowTextA", micHwnd, micString 'Get handle of the "Internet Options" dialog hDlg = Browser("Untitled").Dialog("Internet Options").GetROProperty("hWnd") 'Call SetWindowText function to change the dialog title Extern.SetWindowText hDlg, "Some other title" GetContent Method Description Returns all of the items in the object's list. Syntax VbComboBox(description).GetContent Return Value String Example The following example returns the items in the “cmbTo“ combo box. Contents=VbWindow("frmMain").VbComboBox("cmbTo").GetContent GetItem Method Description Returns the value of the item specified by the index. Syntax VbComboBox(description).GetItem (Index) C
Type
Description
Index Number Numeric index of the item. Index values begin with 0. Return Value String Example The following example returns the value of the second item in the list. itemVal = VbWindow("frmMain").VbComboBox("cmbTo").GetItem (1) Set Method www.qaplanet.in
92 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Description Sets the value of a Visual Basic check box. Syntax VbCheckBox(description).Set Value Argument Type Value
Description
The value to be assigned to the check box. The value String can be: ON , OFF , or DIMMED (for three-state check boxes).
Example The following example sets the “Insert Order“ check box to ON. VbWindow("frmMain").VbCheckBox("Insert Order").Set "ON" GetSelection Method Description Returns all of the selected items in the object's list. Syntax VbComboBox(description).GetSelection Return Value String Example The following example returns the selected items in the “cmbTo“ combo box. string 100, Selection Selection = VbWindow("frmMain").VbComboBox("cmbTo").GetSelection ItemsCount Method Description Returns the number of items in the object's list. Syntax VbComboBox(description).ItemsCount Return Value Number Example The following example returns the number of items in the “cmbTo“ combo box. NumberOfItems = VbWindow("frmMain").VbComboBox("cmbTo").ItemsCount Select Method Description Selects an item from the object's list. Syntax VbComboBox(description).Select Item www.qaplanet.in
93 of 110
QAPlanet
QTP 10.0
Argument Type Item
M. Sreedhar Reddy Description
The item to select from the list. The item value (with String quotes) or numeric index (without quotes) can denote the item. The first item in a list is numbered 0.
Example The following example selects the item New York from the cmbFrom combo box. VbWindow("frmMain").VbComboBox("cmbFrom").Select "New York" or VbWindow("frmMain").VbComboBox("cmbFrom").Select 7 Set Method Description Sets the value of an edit box. Syntax VbEdit(description).Set Text Argument Type Text
Description
String The text to be entered in the edit box.
Example The following example sets the value of the “txtName“ edit box to “John Doe“. VbWindow("frmMain").VbEdit("txtName").Set "John Doe" SetCaretPos Method Description Places the cursor at the specified point in an edit object. Syntax VbEdit(description).SetCaretPos Col Argument Col
Type
Description
Number
The zero-based column position at which the insertion point is placed.
Example The following example places the cursor at the sixth character position in the Form1 window, and then types the word very. VbWindow("Form1").VbEdit("Text1").SetSelection 0,5 VbWindow("Form1").VbEdit("Text1").Type "I am happy" VbWindow("Form1").VbEdit("Text1").SetCaretPos 5 VbWindow("Form1").VbEdit("Text1").Type "very " SetSecure Method Description Sets the encrypted value of an edit box. www.qaplanet.in
94 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Note: The SetSecure method is recorded when a password or other secure text is entered. The text is encrypted while recording, and decrypted during the test run. Syntax VbEdit(description).SetSecure SecureText Argument Type
Description
SecureText String The encrypted text to be entered in the edit box. Example The following example sets a password in the “txtPassword“ edit box. VbWindow("frmLogin").VbEdit("txtPassword").SetSecure "3d2be9118e95d2bf1ed7d2" SetSelection Method Description Selects text in an edit object. Syntax VbEdit(description).SetSelection StartCol, EndCol Argument
Type
Description
StartCol
Number The column at which the selection starts.
EndCol
Number The column at which the selection ends.
Example The following example selects the first six characters in the Form1 window and then types the words I am happy instead. VbWindow("Form1").VbEdit("Text1").SetSelection 0,5 VbWindow("Form1").VbEdit("Text1").Type "I am happy" SetCaretPos Method Description Places the cursor at the specified point in a multi-line edit object. Syntax VbEditor(description).SetCaretPos Line, Col Argument
Type
Description
Line
Number
The zero-based row position at which the insertion point is placed.
Col
Number
The zero-based column position at which the insertion point is placed.
Example The following example types a sentence at the beginning of the third line of the “txtName” editor. VbWindow("frmMain").VbEditor("txtName").SetCaretPos 3, 0 VbWindow("frmMain").VbEditor("txtName").Type "This text will be inserted at the beginning of the line 3" www.qaplanet.in
95 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
SetSelection Method Description Selects text in a multi-line edit object. Syntax VbEditor(description).SetSelection StartLine, StartCol, EndLine, EndCol Argument
Type
Description
StartLine
Number The row at which the selection starts.
StartCol
Number The column at which the selection starts.
EndLine
Number The row at which the selection ends.
EndCol
Number The column at which the selection ends.
Example The following example selects text from the beginning of line 3 through column 16 or line four, and then presses the “Delete” key to delete the selected text. VbWindow("frmMain").VbEditor("txtName").SetSelection 3, 0, 4, 16 VbWindow("frmMain").VbEditor("txtName").Type micDel Activate Method Description Activates (double-clicks) an item in the object's list. Syntax VbList(description).Activate Item Argument Type Item
Description
The item to select from the list. The item value (with String quotes) or numeric index (without quotes) can denote the item. The first item in a list is numbered 0.
Example The following example double-clicks on the “C345” item in the “1stFilghts“ list. VbWindow("frmMain").VbWindow("dlgFlights").VbList("lstFlights").Activate "C345" or VbWindow("frmMain").VbWindow("dlgFlights").VbList("lstFlights").Activate 2 Deselect Method Description Deselects an item in the object's list. Syntax VbList(description).Deselect Item Argument Type
www.qaplanet.in
Description
96 of 110
QAPlanet
Item
QTP 10.0
M. Sreedhar Reddy
The item to select from the list. The item value (with String quotes) or numeric index (without quotes) can denote the item. The first item in a list is numbered 0.
Example The following example deselects a selected item from the “1stFlights“ List. VbWindow("frmMain").VbWindow("dlgFlights").VbList("lstFlights").Deselect "C451" or VbWindow("frmMain").VbWindow("dlgFlights").VbList("lstFlights").Deselect 3 ExtendSelect Method Description Selects an additional item from a multi-selection list. Syntax VbList(description).ExtendSelect Item Argument Type Item
Description
The item to select from the list. The item value (with String quotes) or numeric index (without quotes) can denote the item. The first item in a list is numbered 0.
Example The following example adds an item to a multiple-selection list in the “1stFlights“ list. VbWindow("frmMain").VbWindow("dlgFlights").VbList("lstFlights").ExtendSel ect "C345" or VbWindow("frmMain").VbWindow("dlgFlights").VbList("lstFlights").ExtendSel ect 2 GetContent Method Description Returns all of the items in the object's list. Syntax VbList(description).GetContent Return Value String Example The following example returns the items in the “1stFlights“ list. Contents=VbWindow("frmMain").VbWindow("dlgFlights").VbList("lstFlights"). GetContent GetItem Method Description Returns the value of the item specified by the index.
www.qaplanet.in
97 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Syntax VbList(description).GetItem (Index) Argument Index
Type
Description
Number Numeric index of the item. Index values begin with 0.
Return Value String Example The following example returns the value of the second item in the list. itemVal = VbWindow("frmMain").VbWindow("dlgFlights").VbList("lstFlights").GetItem (1) GetItemProperty Method Description Returns the current value of a property for an item in the list. Syntax VbList(description).GetItemProperty(Item, Property) Argument Type
Description
Item
Name of the item in the list or its numeric index. To String specify the index of the item to select, use â&#x20AC;&#x153;<Item #>â&#x20AC;&#x153;. Index values begin with 1.
Property
String
Property to retrieve from the list item. See the table below for a list of supported properties.
The following properties are supported: Property Name
Description
checked
Indicates whether the list item check box is selected (available only for list items with check boxes). Possible values: True False
focused
Indicates whether the list item has the focus in a multiple selection list box. Possible values: True False
height
The list item's height (in pixels).
IsAnchor
Indicates whether the list item is an anchor item (the item from which a multiple selection span starts). Possible values: True
www.qaplanet.in
98 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
False
selected
Indicates whether the list item is selected. Possible values: True False
text
The text of the list item, or “” if the list item does not contain any text.
Return Value String Example The following example selects different options in the RowList Sample window, and then retrieves specific properties for each item in the list. VbWindow("RowList Sample").VbList("ColorList").Select "Green" VbWindow("RowList Sample").VbList("ColorList").SelectRange "Blue" cItems = VbWindow("RowList Sample").VbList("ColorList").ItemsCount sReport = "VbList Item Properties" & vbCr For iItem = 0 To cItems-1 sReport = sReport & "Item " & iItem & vbTab sReport = sReport & "Selected " & sReport = sReport & "Focused " & VbWindow("RowList Sample").VbList("ColorList").GetItemProperty(iItem,"Focused") & vbTab sReport = sReport & "Checked " & VbWindow("RowList Sample").VbList("ColorList").GetItemProperty(iItem,"Checked") & vbTab sReport = sReport & "Selected " & VbWindow("RowList Sample").VbList("ColorList").GetItemProperty(iItem,"Selected") & vbTab sReport = sReport & vbCr Next Reporter.ReportEvent EVENTSTATUS_GENERAL,"VbList Item Properties",sReport GetSelection Method Description Returns all of the selected items in the object's list. Syntax VbList(description).GetSelection Return Value String Example The following example returns the selected items in the “1stFlights“ list. VbWindow("frmMain").VbWindow("dlgFlights").VbList("lstFlights").Select "bin" VbWindow("frmMain").VbWindow("dlgFlights").VbList("lstFlights").ExtendSel ect "dat" VbWindow("frmMain").VbWindow("dlgFlights").VbList("lstFlights").ExtendSel ect "encrypt" string 100, Selection www.qaplanet.in
99 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Selection = VbWindow("frmMain").VbWindow("dlgFlights").VbList("lstFlights").GetSelecti on ItemsCount Method Description Returns the number of items in the object's list. Syntax VbList(description).ItemsCount Return Value Number Example The following example returns the number of items in the “1stFlights“ list. NumberOfItems = VbWindow("frmMain").VbWindow("dlgFlights").VbList("lstFlights").ItemsCou nt Select Method Description Selects an item from the object's list. Syntax VbList(description).Select Item [,Button, Offset] Argument
Type
Description
Item
String
The item to select from the list. The item value (with quotes) or numeric index (without quotes) can denote the item. The first item in a list is numbered 0.
Button
Integer
Optional. The button used to click the object. 0=LEFT, 1=RIGHT, 2=MIDDLE. Default=0 (LEFT).
Offset
Optional. The horizontal offset (in pixels) of the click location relative to the left margin of the item’s text. Number This argument can be used only if the button argument is defined.
Example The following example selects the item “New York“ from the “Insert Order“ list. VbWindow("frmMain").VbList("Insert Order").Select "New York" or VbWindow("frmMain").VbList("Insert Order").Select 7 SelectRange Method Description Selects all list items between (and including) the two specified items. www.qaplanet.in
100 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Note: This method is applicable only to lists that allow multiple selection. Syntax VbList(description).SelectRange [Item1,] Item2 Argument Type
Description
Item1
Optional. The first item of the range. If the item1 argument is not specified, then the currently selected item is the first item of the range. String The item value (with quotes) or numeric index (without quotes) can denote the item. The first item in a list is numbered 0.
Item2
The last item of the range. The item value (with quotes) or numeric index (without String quotes) can denote the item. The first item in a list is numbered 0.
Example The following example selects all the items between (and including) “Red“ and “Blue“. VbWindow("frmMain").VbList("Colors").SelectRange "Red", "Blue" The following example selects the items between the currently selected item and item number 7. VbWindow("frmMain").VbList("Colors").SelectRange 7 SetItemState Method Description Sets the state of a check box icon of the specified item in a list. Syntax VbList(description).SetItemState Item, State Argument
Type
Description
Item
Variant
The item to select from the list. The item value (with quotes) or numeric index (without quotes) can denote the item. The first item in a list is numbered 0.
State
The object's state. The state can either be an index, or one of the following state constants: micChecked (1): Item is checked Number micUnchecked (0): Item is unchecked micClick (-1): Clicks the state icon micDblClick (-2): Double-clicks the state icon
Example The following example clears the check box icon of the “Child“ item in the list. VbWindow("frmMain").VbList("Files").SetItemState "Root1;Child", micUnchecked The following example sets the state icon of the “Child“ item in the list that has more than two states. www.qaplanet.in
101 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
VbWindow("frmMain").VbList("Files").SetItemState "Root1;Child", 3 The following example double clicks the check box icon of the â&#x20AC;&#x153;Childâ&#x20AC;? item in the list. VbWindow("frmMain").VbList("Files").SetItemState "Root1;Child", micDblClick VbButton Object Description A Visual Basic button object. Associated Methods and Properties You can use the test object methods and properties associated with the VbButton object to test button objects. The methods listed below are associated with the VbButton object. Many of these are common to all Visual Basic test objects. Syntax and examples for common methods are described in Common Methods and Properties. Syntax and examples for VbButton-specific methods are described in this section. For a list of pre-defined properties associated with the VbButton test object, see VbButton Test Object Properties. 2. CaptureBitmap Method 3. Check Method 4. ChildObjects Method 5. Click Method 6. DblClick Method 7. Drag Method 8. Drop Method 9. Exist Method GetROProperty Method 10. 11. GetTextLocation Method GetTOProperties Method 12. 13. GetTOProperty Method 14. GetVisibleText Method MouseMove Method 15. 16. Object Property Output Method 17. 18. SetTOProperty Method 19. Type Method 20. WaitProperty Method VbCheckBox Object Description A Visual Basic check box object. Associated Methods and Properties You can use the test object methods and properties associated with the VbCheckBox object to test check box objects. The methods listed below are associated with the VbCheckBox object. Many of these are common to all Visual Basic test objects. Syntax and examples for common methods are described in Common Methods and Properties. Syntax and examples for VbCheckBox-specific methods are described in this section.
www.qaplanet.in
102 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
For a list of pre-defined properties associated with the VbCheckBox test object, see VbCheckBox Test Object Properties. 1. CaptureBitmap Method 2. Check Method 3. ChildObjects Method 4. Click Method 5. DblClick Method 6. Drag Method 7. Drop Method 8. Exist Method 9. GetROProperty Method 10. GetTextLocation Method 11. GetTOProperties Method 12. GetTOProperty Method 13. GetVisibleText Method MouseMove Method 14. Object Property 15. 16. Output Method Set Method 17. 18. SetTOProperty Method 19. Type Method 20. WaitProperty Method VbComboBox Object Description A Visual Basic combo box object. Associated Methods and Properties You can use the test object methods and properties associated with the VbComboBox object to test combo box objects. The methods listed below are associated with the VbComboBox object. Many of these are common to all Visual Basic test objects. Syntax and examples for common methods are described in Common Methods and Properties. Syntax and examples for VbComboBox-specific methods are described in this section. For a list of pre-defined properties associated with the VbComboBox test object, see VbComboBox Test Object Properties. a. CaptureBitmap Method b. Check Method c. ChildObjects Method d. Click Method e. DblClick Method f. Drag Method g. Drop Method h. Exist Method i. GetContent Method j. GetItem Method k. GetROProperty Method l. GetSelection Method m. GetTextLocation Method n. GetTOProperties Method www.qaplanet.in
103 of 110
QAPlanet
QTP 10.0 o. p. q. r. s. t. u. v. w. x.
M. Sreedhar Reddy
GetTOProperty Method GetVisibleText Method ItemsCount Method MouseMove Method Object Property Output Method Select Method SetTOProperty Method Type Method WaitProperty Method
VbEdit Object Description A Visual Basic edit object. Associated Methods and Properties You can use the test object methods and properties associated with the VbEdit object to test edit box objects. The methods listed below are associated with the VbEdit object. Many of these are common to all Visual Basic test objects. Syntax and examples for common methods are described in Common Methods and Properties. Syntax and examples for VbEdit-specific methods are described in this section. For a list of pre-defined properties associated with the VbEdit test object, see VbEdit Test Object Properties. a. CaptureBitmap Method b. Check Method c. ChildObjects Method d. Click Method e. DblClick Method f. Drag Method g. Drop Method h. Exist Method i. GetROProperty Method j. GetTextLocation Method k. GetTOProperties Method l. GetTOProperty Method m. GetVisibleText Method n. MouseMove Method o. Object Property p. Output Method q. Set Method r. SetCaretPos Method s. SetSecure Method 2. SetSelection Method a. SetTOProperty Method b. Type Method c. WaitProperty Method VbEditor Object
www.qaplanet.in
104 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
Description A Visual Basic multi-line edit object. Associated Methods and Properties You can use the test object methods and properties associated with the VbEditor object to test multi-line editor objects. The methods listed below are associated with the VbEditor object. Many of these are common to all Visual Basic test objects. Syntax and examples for common methods are described in Common Methods and Properties. Syntax and examples for VbEditor-specific methods are described in this section. For a list of pre-defined properties associated with the VbEditor test object, see VbEditor Test Object Properties. 1. CaptureBitmap Method 2. Check Method 3. ChildObjects Method 4. Click Method 5. DblClick Method 6. Drag Method 7. Drop Method 8. Exist Method 9. GetROProperty Method 10. GetTextLocation Method 11. GetTOProperties Method 12. GetTOProperty Method GetVisibleText Method 13. 14. MouseMove Method Object Property 15. 16. Output Method SetCaretPos Method 17. 18. SetSelection Method 19. SetTOProperty Method Type Method 20. 21. WaitProperty Method VbFrame Object Description A Visual Basic frame object. Associated Methods and Properties You can use the test object methods and properties associated with the VbFrame object to test frame objects. The methods listed below are associated with the VbFrame object. Many of these are common to all Visual Basic test objects. Syntax and examples for common methods are described in Common Methods and Properties. Syntax and examples for VbFrame-specific methods are described in this section. For a list of pre-defined properties associated with the VbFrame test object, see VbFrame Test Object Properties. 1. CaptureBitmap Method 2. Check Method 3. ChildObjects Method 4. Click Method www.qaplanet.in
105 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
5. DblClick Method 6. Drag Method 7. Drop Method 8. Exist Method 9. GetROProperty Method 10. GetTextLocation Method 11. GetTOProperties Method 12. GetTOProperty Method GetVisibleText Method 13. 14. MouseMove Method 15. Object Property 16. Output Method 17. SetTOProperty Method 18. Type Method 19. WaitProperty Method VbLabel Object Description A static text object. Associated Methods and Properties You can use the test object methods and properties associated with the VbLabel object to test static text objects. The methods listed below are associated with the VbLabel object and are common to all Visual Basic test objects. Syntax and examples for common methods are described in Common Methods and Properties. For a list of pre-defined properties associated with the VbLabel test object, see VbLabel Test Object Properties. a. CaptureBitmap Method b. Check Method c. ChildObjects Method d. Exist Method e. GetROProperty Method f. GetTOProperties Method g. GetTOProperty Method h. MouseMove Method i. Object Property j. Output Method k. SetTOProperty Method l. WaitProperty Method VbList Object Description A Visual Basic list object. Associated Methods and Properties You can use the test object methods and properties associated with the VbList object to test list objects. The methods listed below are associated with the VbList object. Many of these are common to all Visual Basic test objects. Syntax and examples for
www.qaplanet.in
106 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
common methods are described in Common Methods and Properties. Syntax and examples for VbList-specific methods are described in this section. For a list of pre-defined properties associated with the VbList test object, see VbList Test Object Properties. a. Activate Method b. CaptureBitmap Method c. Check Method d. ChildObjects Method e. Click Method f. DblClick Method g. Deselect Method h. Drag Method i. Drop Method j. Exist Method k. ExtendSelect Method l. GetContent Method m. GetItem Method n. GetItemProperty Method o. GetROProperty Method p. GetSelection Method q. GetTextLocation Method r. GetTOProperties Method s. GetTOProperty Method t. GetVisibleText Method u. ItemsCount Method v. MouseMove Method w. Object Property x. Output Method y. Select Method z. SelectRange Method aa. SetItemState Method SetTOProperty Method bb. cc. Type Method dd. WaitProperty Method VbListView Object Description A Visual Basic ListView object. Associated Methods and Properties You can use the test object methods and properties associated with the VbListView object to test ListView objects. The methods listed below are associated with the VbListView object. Many of these are common to all Visual Basic test objects. Syntax and examples for common methods are described in Common Methods and Properties. Syntax and examples for VbListView-specific methods are described in this section. For a list of pre-defined properties associated with the VbListView test object, see VbListView Test Object Properties. a. Activate Method www.qaplanet.in
107 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
b. c. d. e. f. g. h. i. j.
CaptureBitmap Method Check Method ChildObjects Method Click Method DblClick Method Deselect Method Drag Method GetItem Method Drop Method 2. DropOnItem Method a. EditLabel Method b. Exist Method c. ExtendSelect Method d. GetCheckMarks Method e. GetContent Method f. GetItem Method g. GetROProperty Method h. GetSelection Method i. GetTextLocation Method j. GetTOProperties Method k. GetTOProperty Method l. GetVisibleText Method m. ItemsCount Method n. MouseMove Method o. Object Property p. Output Method q. Select Method r. SelectRange Method s. SetItemState Method t. SetTOProperty Method u. Type Method v. WaitProperty Method VbRadioButton Object Description A Visual Basic radio button object. Associated Methods and Properties You can use the test object methods and properties associated with the VbRadioButton object to test radio button objects. The methods listed below are associated with the VbRadioButton object. Many of these are common to all Visual Basic test objects. Syntax and examples for common methods are described in Common Methods and Properties. Syntax and examples for VbRadioButton-specific methods are described in this section. For a list of pre-defined properties associated with the VbRadioButton test object, see VbRadioButton Test Object Properties. 1. CaptureBitmap Method 2. Check Method 3. ChildObjects Method 4. Click Method www.qaplanet.in
108 of 110
QAPlanet
QTP 10.0
M. Sreedhar Reddy
5. DblClick Method 6. Drag Method 7. Drop Method 8. Exist Method 9. GetROProperty Method 10. GetTextLocation Method 11. GetTOProperties Method 12. GetTOProperty Method GetVisibleText Method 13. 14. MouseMove Method 15. Object Property 16. Output Method 17. Set Method 18. SetTOProperty Method 19. Type Method WaitProperty Method 20. VbScrollBar Object Description A Visual Basic scroll bar object. Associated Methods and Properties You can use the test object methods and properties associated with the VbScrollBar object to test scroll bar objects. The methods listed below are associated with the VbScrollBar object. Many of these are common to all Visual Basic test objects. Syntax and examples for common methods are described in Common Methods and Properties. Syntax and examples for VbScrollBar-specific methods are described in this section. For a list of pre-defined properties associated with the VbScrollBar test object, see VbScrollBar Test Object Properties. 1. CaptureBitmap Method 2. Check Method 3. ChildObjects Method 4. Click Method 5. DblClick Method 6. Drag Method 7. Drop Method 8. Exist Method 9. GetROProperty Method 10. GetTextLocation Method 11. GetTOProperties Method 12. GetTOProperty Method GetVisibleText Method 13. 14. MouseMove Method 15. NextLine Method 16. NextPage Method 17. Object Property 18. Output Method 19. PrevLine Method 20. PrevPage Method www.qaplanet.in
109 of 110
QAPlanet
QTP 10.0 21. 22. 23. 24.
www.qaplanet.in
M. Sreedhar Reddy
Set Method SetTOProperty Method Type Method WaitProperty Method
110 of 110