Thursday, July 17, 2008
Checking Links with QTP 9.2
Checking all links on a website isn't that easy as it might look. The scripts demonstrates on how to do it for a normal website. What it does is that it counts the links on the homepage and then one by one click on the links and close the popup window in case it's opened in a new window.
Features:
* Closing the popup when clicking a link opens ones
* Workaround for determining if a popup is present or not. QTP provides "Exist" function for checking if a object exists or not. For checking a popup browser we can use Browser("CreationTime:=1").Exist and use Browser("CreationTime:=1").Close the popup window. But the problem is that sometimes QTP returns true even when the browser does not exists and using close function closes the main browser window which leads to the failure of the script. The script uses a workaround by comparing the hwnd of the main browser and the popup browser and closing the popup only if the handles don't match.
* Checks for normal 404 or page cannot be displayed messages in the source code of the browser.
Limitation:
* More than 1 popup: Opening a website or a link which leads to other popup will make the script fail as it closes on 1 popup. But with small enhancement it can be easily changed to support these websites also.
* Ignoring a link: Clicking on links like "Logout" is not excluded and hence may fail the script.
* Changing website: If clicking of a link changes the home page of a website then the script will fail. Consider the case of www.google.com, now if you run the script on this page it will fail becuase when the script clicks on one of the languages link, the home page of website will change and even the no. of links might change. This can be correct by two ways, one is to close all the browsers every time and delete all cookies and then go for the next link and other ways would be to delete the session cookies of the browser. For deleting session cookies there is no software available except the one that I created and is present on this website
QTP 9.2 - Functionality Tool
What is QTP 9.2?
* HP Quick Test Pro 9.2 is a functional automation and regression testing tool
* QTP provides record and playback of events
* Uses VBScript as the scripting Language
* Provides keyword view and expert view to view test cases.
* Latest versions of QTP is 9.5 (launched in mid Jan 2008)
* Previous version of QTP: 6.5, 8.0, 8.1, 8.2, 9.0, 9.1
* QTP was previously owned by Mercury Interactive®
With introduction of QTP 9.5, Trial version of QTP 9.2 is not available. QTP 9.5 does not have any huge enhancement and hence most of the features discussed in this article will still hold
When you launch QTP for the first time, Add-in manager window is displayed
What is Add-in?
* QTP requires Add-in for recognizing object of a specific environment
* By default QTP 9.2 comes with 3 Add-ins: Web, ActiveX and VB
* Some of the Add-ins available for QTP 9.2 are
1. Terminal Emulator (TE)
2. .NET
3. Java
4. SAP
5. Siebel
6. Stingray
7. VisualAge
8. Web Services
* QTP does not require any Add-in to work on Standard windows application
* Add-ins can only be loaded when starting QTP
Once the selected Add-ins are loaded, QTP window will show up
Hit the record button to start recording. If you are recording for the first time, the Record and Run Settings dialog box opens as shown below
What all tabs are shown in above dialog would depend on Add-ins that is loaded. Using above dialog we can set on what all application should QTP record on.
Note: If QTP does not record anything on your application then make sure you have the correct settings specified in Record and Run Settings…
Keyword view
The Keyword View enables you to create and view the steps of your test in a keyword-driven, modular, table format. This is the only view where complete Test flow can be viewed.
Expert View
In Expert View, QTP displays each operation performed on the application in the form of a script, comprised of VBScript statements. Complete test flow is not available/visible in this view.
Test and Run-time Object
* QTP works on objects in Application Under Test (AUT) by storing object description
* This object description is known as a Test Object
* Each Test Object supports predefined sets of Methods and properties
* The actual object in the AUT which is identified for a Test Object is called the Run-time object.
* A Test Object can always be present without the AUT
* Run-time object can only be present when AUT is up and running
Object Spy
Object Spy is a tool that can be used to spy Test and run time object for looking at properties and methods supported by object being spied
Test Object Properties Run-time Object Properties
Object Identification
* QTP uses three types of properties when identifying a object
1. Mandatory – Always learn these properties for the object
2. Assistive – Learn in case Mandatory properties are not enough to identify the object uniquely
3. Ordinal identifiers – Learn in case both mandatory and assistive properties are not able to recognize the objects correctly
* Ordinal identifiers are of three types
1. Index – index of object (0, 1, 2 …)
2. Location – Location of the object on the screen (0, 1, 2 …)
3. CreationTime – Used only for Browser. Launchtime of browser (0, 1, 2 …)
Object Identification Settings
Launch from menu Tools->Object Identification…
Here we can Add/Remove properties from/to Mandatory and Assistive properties. Objects in application represent certain special characteristics which allow QTP to map them QTP Test object. For window objects this characteristic is mostly define by ”regexpwndclass“. In case application developers don’t use standard class names while creating object QTP won’t be able to identify the object correctly. Below is a checkbox in Search window recognized by QTP as WinObject
By clicking on the ”User Defined…“ button on Object identification settings window, we can add such objects and map. Once added QTP will now be able to recognize the object correctly
Object Hierarchy
* QTP uses object hierarchy to identify object inside a AUT
* Consider the object spy image shown below. The Web Edit ”q“ is a child of WebTable ”Advanced Search“
* QTP only adds those objects from hierarchy which are necessary for it to identify the object later.
* In this case QTP will add
Browser(”Google“).Page(”Google“).WebEdit(”q“).Set ”test“ (WebTable object ignored)
* QTP cannot be configured to record such objects automatically.
Object Repository (OR)
* QTP works on object in application by storing information about the object in Object repository
* All objects on which user takes an action while recording are automatically added to object repository
* ”Browser“, ”Google“, ”q“ are three different objects that would be present in OR for the below generated statement
Browser("Browser").Page("Google").WebEdit("q").set ”Test“
* Copying and pasting code from one script to another script does not work in QTP as the OR does not get copied to the new script
* There are two types of Object Repositories in QTP
1. Shared OR: Can be used by multiple scripts. A central location to store all objects
2. Per-Action OR: Every action has its individual object repository
Per-Action Object Repository
* Default repository
* Specific to actions (Will be used only for a particular action)
* Preferable when application is not dynamic with respect to time
* Cannot be reused
Shared Action repository
* Can be updated by all actions accessing it
* Preferable when application is dynamic with respect to time
* Used in most automation projects
* Needs maintenance and administration
Action
* Provides way of grouping code into business logic
* Are pretty similar to Functions in VBScript
* Have their own Data Table and Object Repository (in case of per-action object repository)
* Supports input and output parameters
* Actions are of two types: normal and re-usable
* Re-usable actions can be called in other Test.
* QTP does not allow calling another test within a test
* TestFlow represent the top level action. Complete test flow can only be viewed in Keyword views
Inserting Actions
* There are three ways to insert a Action in a test
1. Insert Call to New…
2. Insert Call to Copy…
3. Insert Call to Existing…
* Insert Call to New… - Creates a new action and adds a call to the same
* Adds below line to the code
RunAction "Cancel Ticket", oneIteration
Actions - Insert Call to Existing…
* Insert Call to Existing – User to insert call to a re-usable action located within the same test or some other test
* This inserts the call to the existing action. In case the action in present in some other test case then a read only copy of action is inserted
Actions – Insert Call to Copy…
* Insert Call to Copy - Inserts call to an existing re-usable action and creates an editable copy of that action
* Actions cannot be deleted from a Test from Expert view. To delete a action one must go to the keyword view and delete the action
* An action call cannot be inserted directly by writing code in Expert View, it has to be added through the GUI first.
Action Iterations
An action can be run for 1 or more rows from its Local Data Table.
* QTP supports there types of iteration modes
1. Run one iteration only
2. Run on all rows
3. Run from Row
* Similar to Action, a test can also be run for multiple iterations from Global Data Table
Why Parameterization?
* Parameterization allows us to pick different values at run time.
* Reduces Time and Effort.
* Usage of data drivers allows us to use the same data for various input boxes.
* Parameterization can also be done for checkpoints.
Data Table
* Data Table is excel like spreadsheet which can be user for parameterizing a test case
* DataTable are of two types
1. Global Data Table – Data table for Test flow
2. Local data table – Data table for every action
* In below scenario only Global Data table would be used
1. Login User
2. Book one ticket
3. Logout User
* In below scenario both Global and Local data tables would be used
1. Login User (Pick data from Global Data Table)
2. Book multiple tickets (Pick data from Local data table)
3. Logout
Local Data Table
Global Data Table
* Data table value can be accessed using the below methods
1. DataTable(”
2. DataTable(”
3. DataTable(”
Run-time Data table
* Any changes made to Data table during run-time is stored in run-time data table.
* Run-time data table is available in the test results summary of a test
* DataTable values can be changed at run-time by using below
DataTable(”OrderConf“, dtGlobalSheet) = ”ABCD1234“
Environment Variables
* Environment variables are global variables available to all Actions
* They can be used to run a test case on different environment
* To add a new Environment variable go to Test -> Settings…->Environment (Tab)
* Environment variables are of two types
1. Built-in
2. User-Defined
* Built in environment variables give information about the system and the current test
* User-defined Environment variables added in the Environment tab of Test Settings are Read-only during the test run
* Environment variables can be added during runtime also using code
Environment.Value(”OrderNumber“) = ”ABCDEF“
* Environment variables can be loaded at run-time from a XML file using the below code
Environment.LoadFromFile ”C:\TestEnvironment.xml“
* The Environment XML file has to be in below format
Parameters
* Parameters provide another way of parameterizing the test cases
* There are two types of parameters
1. Test parameters
2. Action parameters
* Test parameters can be set in Test->Settings…->Parameters (Tab)
* Test parameters value can be provided when replaying the test
* Test arguments can be accessed in the test using TestArgs(”
Action Parameters
* Used to pass parameters to Action
* Output parameters can only be used when Action is being called for a single iteration
* Ex – RunAction "Login", oneIteration, "TestUser", "TestPass", out
* A parameter can be accessed using
Parameter(”
Resources
* Scripts written in VBScript language can be add as a Resource to the test
* All code written in the script is available across all Actions
* A VBScript can also be loaded in an Action by using ExecuteFile function. Ex –
ExecuteFile ”C:\Init.vbs“
* In case of multiple files QTP combines all the files into a single one and executes the code. The files are combine in bottom to top order
Checkpoints
* Checkpoints are verification points in a test
* Test without checkpoint would never have a pass status
* Checkpoints can be of types
– Built-in checkpoints
– Custom checkpoints
* Types of Built-in checkpoints available are
1. Standard checkpoints: Verify properties of an object
2. Text checkpoints: Verify text presence between two strings
3. Text Area checkpoint
4. Bitmap checkpoint
5. Accessibility checkpoint
6. Database checkpoint
7. XML Checkpoint
* Only Database and XML checkpoints can be inserted in idle mode.
* Rest all checkpoints can only be added during Recording or through Active screens.
* Checkpoint code
Browser("Google").Page("Google").WebEdit("q").Check CheckPoint("Verify TextBox_Standard")
Custom Checkpoints
* Custom checkpoints can be created using Code
loginExist = Browser().Page().Link(”text:=Login“).Exist(0)
If loginExist then
Reporter.ReportEvent micPass, ”Check Login“, ”Login link exists“
Else
Reporter.ReportEvent micFail, ”Check Login“, ”Login link does not exists“
End if
* Custom checkpoint can be made flexible based on implementation and are preferred over Built-in checkpoints
Test Results
Test results provide a execution summary of the complete test case
* There are different types of status in test results summary:
1. Passed
2. Failed
3. Done
4. Warning
5. Information
Descriptive Programming
* Alternate way of writing test cases without having objects in object repository
* Descriptive programming can be done in two ways
1. Using object description
2. Using string description
* In DP objects are identified by describing all the identification properties
* String description DP
Browser(”title:=Google“).Page(”title:=Google“).WebButton(”name:=Search“).Click
* Object Based DP
Set btnSearch = Description.Create : btnSearch(”name“).Value = ”Search“
Set brwGoogle = Description.Create : brwGoogle(”title“).value = ”Google“
Set pgGoogle = Description.Create : pgGoogle(”title“).value = ”Google“
Browser(brwGoogle).Page(pgGoogle).WebButton(btnSearch).Click
* Description objects can also be used to get all child objects matching a criterion. Ex –
Set oDesc = Description.Create
oDesc(”name”).Value = ”txt_.*“
oDesc(”name”).RegularExpression = True
Set allMatchingObjects = Browser().Page().ChildObjects(oDesc)
Msgbox allMatchingObjects.Count
Msgbox allMatchingObjects(0).GetROProperty(”name“)
* By default all property values are considered as regular expression patterns
* When using string description all regular expression must be used with escape character for literal meaning. Ex - …Link(”text:=Logout \(Tarun\)“).Click
* DP based Object repository can be created in any file
* Code can be copied from one script to another without copying the object repository
* Custom implementation of object is easier. Ex –
objStrDesc = ”Browser(”“title:=Test““).Page(”“title:=Test““).Link(”“text:=Login““)“
Execute ”Set obj = ” & objStrDesc
obj.Click
QTP Misc information
* QTP and the AUT has to be on the same machine
* QTP can be controlled remotely from another machine
* QTP scripts cannot be run without QTP
Saturday, July 12, 2008
QTP Quiz
1. The toolbar enables you to view the details of an individual action or the entire test flow is
1. Testing toolbar
2. None of the above
3. Action toolbar
4. Test Pane
C
2. The key that is used to Start/End analog recording mode?
1. F3
2. SHIFT+ALT+F3
3. CTRL+SHIFT+F3
4. F10
B
3. To use a specific property to identify your object, but that property is not listed in the properties list. Then how do you identify that object?
1. Add the specific property to the list
2. Use the Default property
3. Use some other property to identify your object
A
4. The list of test objects and their properties and values are stored in the
1. Object Repository
2. Object Identification
A
5. To retrieve the current property value of the objects in your application during the run session.
1. GetVisibleText
2. GetROProperty
3. SetROProperty
4. GetTOProperty
B
6. Bitmap checkpoint is supported in VB environment.
1. True
2. False
A
7. What is the shortcut key that is used for a Standard Checkpoint?
1. F12
2. F2
3. F10
4. F7
A
8. To compares the values of the specified property during a run session with the values stored for the same test object property within the test.
1. Checkpoint
2. All the above
3. Output Value
4. Compare the object property
A
9. You will use the recording mode for an object not recognized by QuickTest.
1. Low-Level Recording Mode
2. Normal recording Mode
3. Analog Mode
A
10. The statement that calls the recorded analog file is
1. RunAnalog
2. CallAnalog
3. ExecuteAnalog
A
11. An action can be called by other tests or actions is
1. Call Action
2. Split Action
3. Reusable Action
C
12. You can replace the page in your Active Screen tab
1. False
2. True
B
13. QuickTest adds a checkpoint statement in the Expert View as
1. Check Checkpoint
2. Checkpoint
A
14. A Checkpoint checks that a text string is displayed within a defined area in a Windows application is
1. Accessibility
2. Text Area
3. Standard
4. Text
B
15. In ActiveX environment an “Accessibility checkpoint” is supported.
1. No
2. Yes
A
16. Can we get the execution time for an action in a Test.
1. Yes
2. No
A
17. The command used to retrieve data from excel sheet is
1. Set ab = Connection("srcfilepath ") , Set ws = ab.getdata(sheetid)
2. Set ab = CreateObject("srcfilepath ") , Set ws = ab.getsheet(sheetid)
3. Set ab = GetObject("srcfilepath") , Set ws = ab.worksheets(sheetid)
B
18. The method used to get data from HTML Table is
1. GetData(Row,Col)
2. GetRowValue(Rowid,Colname)
3. GetCellData (Row,Col)
C
19.The Command used to insert the transactions in test is,
1. StartTransaction(“Name”), EndTransaction(“Name”)
2. Services.StartTransaction "Name", Services.EndTransaction "Name"
3. StartTransaction.services "Name”, EndTransaction.services "Name”
B
20. A step in which one or more values are captured at a specific point in your test and stored for the duration of the run session is
1. Output Value
2. Checkpoints
3. Active Screen
A
21. QuickTest can detects an application crash and activate a defined recovery scenario to continue the run session.
1. True
2. false
A
22. In Batch Test process, the test list are saved in file format as,
1. *.mtb
2. *.mts
3. *.mbt
4. *.mtr
A
23. The command used to invoke other application from QTP,
1. InvokeApplication
2. SystemUtil.Run
3. Run
4. Both b & c
5. Both a & b
E
24. Can we add external library files in QTP?
1. No
2. Yes
B
25. The method that explicitly activates the recovery scenario mechanism is,
1. recovery.activate
2. enable
3. recovery.enable
4. activate
A
26. The method used for sending information to the test results.
1. Reporter.log()
2. Reporter.reportevent()
3. Reporter.msgbox()
4. Reporter.report()
B
27. To terminate an application that is not responding we use,
1. SystemUtil.terminate
2. SystemUtil.Stop
3. SystemUtil.CloseProcessByName
C
28. The recovery mechanism does not handle triggers that occur in the last step of a test
1. false
2. True
B
29. We can add Test object methods, function calls into the Test using
1. Function generator
2. Step generator
3. Object repository
A
30. The method that adds to the test while implementing Synchronization is
1. Synchronize
2. Wait
3. WaitProperty
4. Pause
C
31. The mechanism used to identify objects during run session is
1. Recovery scenario
2. Smart identification
3. Handling object
B
32. Post-recovery test run options specifies
1. how to continue the run session after QTP identify the event
2. errors while running
3. recovery scenario during a run session
A
33. The action that can be called multiple times by the test as well as by other tests is called
1. non-reusable action
2. Reusable action
3. External action
B
34. QuickTest supports virtual object for anolog or low-level recording.
1. False
2. True
A
35. The command used to connect with Database is
1. Createobject(“connectivity name”)
2. dbconnect(“connectivity name”)
3. open(“connectivity name”)
4. None of the above
A
36. The method used to retrieve the folders is
1. FileSystemObject.Getfolder()
2. FileSystemObject.selectfolder()
3. FileSystemObject.retrievefolder()
A
37. The method used to compare 2 XML files is:
1. XMLfile1.compare(XMLfile2)
2. XMLcompare(file1,file2)
3. compare(XMLfile1,XMLfile2)
C
38. Can we change name of checkpoint?
1. No
2. Yes
A
39. The QTP script files are stored in the extension of
1. *.mts
2. *.usr
3. *.mtr
4. *.vbs
A
40. The method used to register the user-defined function with test object is
1. setFunc()
2. RegisterUserFunc()
3. RegisterFunc()
B
41. The method used to open the specified URL in a browser is
1. openURL()
2. navigateURL()
3. navigate()
C
42. The 3 Parameter types available in data driver is
1. DataTable,Environment,Random number
2. DataTable,random number,unique
3. environment,string,numeric
A
43. The method added to the test while parameterizing is
1. get Data (variable, dtGlobalSheet)
2. get DataTable(variable, dtGlobalSheet)
3. Set Data(variable, dtGlobalSheet)
4. Set DataTable(variable, dtGlobalSheet)
D
44. The length of the array can be get by the method
1. length(array)
2. ubound(array)
3. count(array)
B
45. The method used to get the count value of list box or combo box os
1. GetItemsCount
2. GetCount
3. GetItemCount
A
46. Can we parameterize the checkpoints properties?
1. No
2. Yes
B
47. In data base check point we can not set the expected value from the test?
1. True
2. False
B
48. The checkpoint used to check the alt attribute exists for all relevant objects (such as images) is
1. DataBase CheckPoint
2. Accessibility checkpoint
3. Bitmap checkpoint
4. Standard checkpoint
B
49. The method used to continue the test execution after getting run-time error is
1. On Error Resume Next
2. On Error Raise Next
3. On Error Next
A
Descriptive Programming
How to write Descriptive Programming?
When and Where to use Descriptive programming?
Some points to note with Descriptive Programming.
Introduction to Descriptive Programming:
Descriptive programming is used when we want to perform an operation on an object that is not present in the object repository. There can be various valid reason to do so. We will discuss them later in this article.
How to write Descriptive Programming?
There are two ways in which descriptive programming can be used
1. By giving the description in form of the string arguments.
2. By creating properties collection object for the description.
1. By giving the description in form of the string arguments.
This is a more commonly used method for Descriptive Programming.
You can describe an object directly in a statement by specifying property:=value pairs describing the object instead of specifying an object’s
name. The general syntax is:
TestObject("PropertyName1:=PropertyValue1", "..." , "PropertyNameX:=PropertyValueX")
TestObject—the test object class could be WebEdit, WebRadioGroup etc….
PropertyName:=PropertyValue—the test object property and its value. Each property:=value pair should be separated by commas and quotation
marks. Note that you can enter a variable name as the property value if you want to find an object based on property values you retrieve during a run session.
Consider the HTML Code given below:
<--!input type="”textbox”" name="”txt_Name”"-->
<--!input type="”radio”" name="”txt_Name”"-->
Now to refer to the textbox the statement would be as given below
Browser(“Browser”).Page(“Page”).WebEdit(“Name:=txt_Name”,”html tag:=INPUT”).set “Test”
And to refer to the radio button the statement would be as given below
Browser(“Browser”).Page(“Page”).WebRadioGroup(“Name:=txt_Name”,”html tag:=INPUT”).set “Test”
If we refer to them as a web element then we will have to distinguish between the 2 using the index property
Browser(“Browser”).Page(“Page”).WebElement(“Name:=txt_Name”,”html tag:=INPUT”,”Index:=0”).set “Test” ‘ Refers to the textbox
Browser(“Browser”).Page(“Page”).WebElement(“Name:=txt_Name”,”html tag:=INPUT”,”Index:=1”).set “Test” ‘ Refers to the radio button
To determine which property and value pairs to use, you can use the Object Spy:
1. Go to Tools -> Object Spy.
2. Select the "Test Object Properties" radio button.
3. Spy on the desired object.
4. In the Properties list, find and write down the properties and values that can be used to identify the object.
2. By creating properties collection object for the description.
Properties collection also does the same thing as string arguments. The only difference is that it "collects" all the properties of a particular object in an instance of that object. Now that object can be referenced easily by using the instance, instead of writing "string arguments" again and again. It is my observation that people find "string arguments" [1] method much easier and intuitive to work with.
To use this method you need first to create an empty description
Dim obj_Desc ‘Not necessary to declare
Set obj_Desc = Description.Create
Now we have a blank description in “obj_Desc”. Each description has 3 properties “Name”, “Value” and “Regular Expression”.
obj_Desc(“html tag”).value= “INPUT”
When you use a property name for the first time the property is added to the collection and when you use it again the property is modified. By default each property that is defined is a regular expression. Suppose if we have the following description
obj_Desc(“html tag”).value= “INPUT”
obj_Desc(“name”).value= “txt.*”
This would mean an object with html tag as INPUT and name starting with txt. Now actually that “.*” was considered as regular expression. So, if you want the property “name” not to be recognized as a regular expression then you need to set the “regularexpression” property as FALSE
obj_Desc(“html tag”).value= “INPUT”
obj_Desc(“name”).value= “txt.*”
obj_Desc(“name”).regularexpression= “txt.*”
This is how we create a description. Now below is the way we can use it
Browser(“Browser”).Page(“Page”).WebEdit(obj_Desc).set “Test”
When we say .WebEdit(obj_Desc) we define one more property for our description that was not earlier defined that is it’s a text box (because QTPs WebEdit boxes map to text boxes in a web page).
If we know that we have more than 1 element with same description on the page then we must define “index” property for the that description
Consider the HTML code given below
<--!input type="”textbox”" name="”txt_Name”"-->
<--!input type="”textbox”" name="”txt_Name”"-->
Now the html code has two objects with same description. So distinguish between these 2 objects we will use the “index” property. Here is the description for both the object
For 1st textbox:
obj_Desc(“html tag”).value= “INPUT”
obj_Desc(“name”).value= “txt_Name”
obj_Desc(“index”).value= “0”
For 2nd textbox:
obj_Desc(“html tag”).value= “INPUT”
obj_Desc(“name”).value= “txt_Name”
obj_Desc(“index”).value= “1”
Consider the HTML Code given below:
<--!input type="”textbox”" name="”txt_Name”"-->
<--!input type="”radio”" name="”txt_Name”"-->
We can use the same description for both the objects and still distinguish between both of them
obj_Desc(“html tag”).value= “INPUT”
obj_Desc(“name”).value= “txt_Name”
When I want to refer to the textbox then I will use the inside a WebEdit object and to refer to the radio button I will use the description object with the WebRadioGroup object.
Browser(“Browser”).Page(“Page”).WebEdit(obj_Desc).set “Test” ‘Refers to the text box
Browser(“Browser”).Page(“Page”).WebRadioGroup(obj_Desc).set “Test” ‘Refers to the radio button
But if we use WebElement object for the description then we must define the “index” property because for a webelement the current description would return two objects.
Getting Child Object:
We can use description object to get all the objects on the page that matches that specific description. Suppose we have to check all the checkboxes present on a web page. So we will first create an object description for a checkboxe and then get all the checkboxes from the page
Dim obj_ChkDesc
Set obj_ChkDesc=Description.Create
obj_ChkDesc(“html tag”).value = “INPUT”
obj_ChkDesc(“type”).value = “checkbox”
Dim allCheckboxes, singleCheckBox
Set allCheckboxes = Browse(“Browser”).Page(“Page”).ChildObjects(obj_ChkDesc)
For each singleCheckBox in allCheckboxes
singleCheckBox.Set “ON”
Next
The above code will check all the check boxes present on the page. To get all the child objects we need to specify an object description.
If you wish to use string arguments [1], same thing can be accomplished by simple scripting.
Code for that would be:
i=0
Do While Browse(“Browser”).Page(“Page”).WebCheckBox("html tag:=INPUT",type:=checkbox, "index:="&i).Exist
Browse(“Browser”).Page(“Page”).WebCheckBox("html tag:=INPUT",type:=checkbox, "index:="&i).Set "ON"
i=i+1
Loop
Possible Operation on Description Objects
Consider the below code for all the solutions
Dim obj_ChkDesc
Set obj_ChkDesc=Description.Create
obj_ChkDesc(“html tag”).value = “INPUT”
obj_ChkDesc(“type”).value = “checkbox”
Q: How to get the no. of description defined in a collection
A: obj_ChkDesc.Count ‘Will return 2 in our case
Q: How to remove a description from the collection
A: obj_ChkDesc.remove “html tag” ‘would delete the html tag property from the collection
Q: How do I check if property exists or not in the collection?
A: The answer is that it’s not possible. Because whenever we try to access a property which is not defined its automatically added to the collection. The only way to determine is to check its value that is use a if statement “if obj_ChkDesc(“html tag”).value = empty then”.
Q: How to browse through all the properties of a properties collection?
A: Two ways
1st:
For each desc in obj_ChkDesc
Name=desc.Name
Value=desc.Value
RE = desc.regularexpression
Next
2nd:
For i=0 to obj_ChkDesc.count - 1
Name= obj_ChkDesc(i).Name
Value= obj_ChkDesc(i).Value
RE = obj_ChkDesc(i).regularexpression
Next
Hierarchy of test description:
When using programmatic descriptions from a specific point within a test object hierarchy, you must continue to use programmatic descriptions
from that point onward within the same statement. If you specify a test object by its object repository name after other objects in the hierarchy have
been described using programmatic descriptions, QuickTest cannot identify the object.
For example, you can use Browser(Desc1).Page(Desc1).Link(desc3), since it uses programmatic descriptions throughout the entire test object hierarchy.
You can also use Browser("Index").Page(Desc1).Link(desc3), since it uses programmatic descriptions from a certain point in the description (starting
from the Page object description).
However, you cannot use Browser(Desc1).Page(Desc1).Link("Example1"), since it uses programmatic descriptions for the Browser and Page objects but
then attempts to use an object repository name for the Link test object (QuickTest tries to locate the Link object based on its name, but cannot
locate it in the repository because the parent objects were specified using programmatic descriptions).
When and Where to use Descriptive programming?
Below are some of the situations when Descriptive Programming can be considered useful:
1. One place where DP can be of significant importance is when you are creating functions in an external file. You can use these function in various actions directly , eliminating the need of adding object(s) in object repository for each action[If you are using per action object repository]
2. The objects in the application are dynamic in nature and need special handling to identify the object. The best example would be of clicking a link which changes according to the user of the application, Ex. “Logout <>”.
3. When object repository is getting huge due to the no. of objects being added. If the size of Object repository increases too much then it decreases the performance of QTP while recognizing a object. [For QTP8.2 and below Mercury recommends that OR size should not be greater than 1.5MB]
4. When you don’t want to use object repository at all. Well the first question would be why not Object repository? Consider the following scenario which would help understand why not Object repository
Scenario 1: Suppose we have a web application that has not been developed yet.Now QTP for recording the script and adding the objects to repository needs the application to be up, that would mean waiting for the application to be deployed before we can start of with making QTP scripts. But if we know the descriptions of the objects that will be created then we can still start off with the script writing for testing
Scenario 2: Suppose an application has 3 navigation buttons on each and every page. Let the buttons be “Cancel”, “Back” and “Next”. Now recording action on these buttons would add 3 objects per page in the repository. For a 10 page flow this would mean 30 objects which could have been represented just by using 3 objects. So instead of adding these 30 objects to the repository we can just write 3 descriptions for the object and use it on any page.
5. Modification to a test case is needed but the Object repository for the same is Read only or in shared mode i.e. changes may affect other scripts as well.
6. When you want to take action on similar type of object i.e. suppose we have 20 textboxes on the page and there names are in the form txt_1, txt_2, txt_3 and so on. Now adding all 20 the Object repository would not be a good programming approach.
QTP & Reporter Objects
* >Report the status of test results (like pass, fail, warning)
* >Enable/Disable reporting of step(s) following the statement.
* >Retrieve the folder path in which the current test's results are stored.
* >Retrieve the run status at the current point of the run session.
There are some very important methods and properties associated with it.
ReporterEvent Method:
I think this is a very common method used with Reporter object. I am sure even if you have worked on QTP for a relatively short period, you would have come across this.
Its syntax:
Reporter.ReportEvent EventStatus, ReportStepName, Details
where EventStatus can be:
0 or micPass: If this step runs test passes which is shown in test report.
1 or micFail: If this step runs test fails which is shown in test report.
2 or micDone: Used to send message to the test report and does not affect status of test.
3 or micWarning: Again, used to send warning message to the test report and does not affect status of test.
and
ReportStepName is name of step
and
Details are the user defined details for the given step.
For Example:
Reporter.ReportEvent micPass, "Login Authorization", "The user-defined step passed."
Filter property
There can be situations where we don't want the full status displayed on the test report. This property can be used to selectively filter the status of your tests.
Its syntax:
Reporter.Filter = NewMode
where NewMode can be:
0 or rfEnableAll: This is the default mode. All reported events are displayed in the Test Results.
1 or rfEnableErrorsAndWarnings: Only those events with a warning or fail status are displayed in the Test Results.
2 or rfEnableErrorsOnly: Only those events with a fail status are displayed in the Test Results.
3 or rfDisableAll: All events in the Test Results are disabled.
ReportPath Property
This is used to get the path in which current test results are stored.
Its syntax:
Path_of_Results = Reporter.ReportPath
RunStatus Property
This is used to get the current status of the run session
Its syntax:
Reporter.RunStatus
For Example:
if Reporter.RunStatus = 0 then flag=1;
QTP & File Handling
We use FSO object to do this.
What is FSO?
FSO stands for File System Object. This is used to support text file creation and manipulation through the TextStream object and is contained in the Scripting type library (Scrrun.dll)
The FSO Object Model has a rich set of properties, methods and events to process folders and files.
How to create a file?
We first create a FSO object using CreateObject and then create a text file using CreateTextFile.
For Example: Suppose you want to create a file called "test.txt" located in C:
Dim fso, file, file_location
file_location = "C:\file_location"
Set fso = CreateObject(“Scripting.FileSystemObject”)
Set file = fso.CreateTextFile(file_location, True) // True--> file is to be overwritten if it already exists else false
We would use the same example for the rest of this post.
How to open a file?
Set file= fso.OpenTextFile("C:\file_location", ForWriting, True)
//2nd argument can be ForReading, ForWriting, ForAppending
//3rd argument is "True" if new file has to be created if the specified file doesn’t exist else false, blank signify false.
How to read content from a file?
Use ReadLine() method
For example:
Set file= fso.OpenTextFile("C:\file_location", ForReading, True) //2nd argument should always be "ForReading" in order to read contents from a file
Do while file.AtEndofStream <> True
data = file.ReadLine()
msgbox data
Loop
How to write content to a file?
You can use Write() or WriteLine() Methods to write text into a file. The difference between the Write() and WriteLine() Method is that the latter automatically inserts a new line character while the former doesn’t insert a new line character.
For example:
Set file= fso.OpenTextFile("C:\file_location", ForWriting, True) //2nd argument should always be "ForWriting" in order to write contents to a file
file.Write("This is a place to get all your qtp")
file.Write("questions and answers solved.")
//Output will be:
This is a place to get all your qtp questions and answers solved.
while
file.WriteLine("This is a place to get all your qtp")
file.Write("questions and answers solved.")
//Output will be:
This is a place to get all your qtp
questions and answers solved.
How to delete content?
Use DeleteFile() method to delete a file from a particular location
Foe Example:
file_location = "C:\file_location"
Set fso = CreateObject(“Scripting.FileSystemObject”)
fso.DeleteFile(file_location)
qtp,textfile,read,write,delete
QTP Tips
No, QTP will not run on this OS.
What to do if you are not able to run QTP from quality center?
This is for especially for new users with QTP.
Check that you have selected Allow other mercury products to run tests and components from Tools--> Options--> Run Tab.
How to rename a checkpoint (QTP 9.0)?
Example:
Window("Notepad").WinEditor("Edit").Check CheckPoint("Edit")
In the above example, the user would like to change the name of the CheckPoint object from "Edit" to something more meaningful.
Note:
This functionality is new to QuickTest Professional 9.0.This is not available for QTP 8.2 and below.
1. Right-click on the Checkpoint step in the Keyword View or on the Checkpoint object in Expert View.
2. Select "Checkpoint Properties" from the pop-up menu.
3. In the Name field, enter the new checkpoint name.
4. Click . The name of the checkpoint object will be updated within the script.
Example:
Window("Notepad").WinEditor("Edit").Check CheckPoint("NewCheckPointName")
Note:
You must use the QuickTest Professional user interface to change the name of the checkpoint. If you manually change the name of the checkpoint in the script, QuickTest Professional will generate an error during replay. The error message will be similar to the following:
"The "" CheckPoint object was not found in the Object Repository. Check the Object Repository to confirm that the object exists or to find the correct name for the object."
The CheckPoint object is not a visible object within the object repository, so if you manually modify the name, you may need to recreate the checkpoint to resolve the error.
What are the files and subfolders of a QuickTest Professional test?
The files and folders hold binary and text data that are required for the test to run successfully.
The following table provides a description, the type, and comments regarding the files that make up a QuickTest Professional test.
File Name
Description
Type
Comments Regarding File
Test.tsp
Test settings
Binary
Do not edit
Default.xls
Data table parameters
Excel similar
Can be edited using Excel
Parameters.mtr
Parameterization information
Binary
Do not edit
Action
Action folder (See other table)
Default.cfg
Load test configuration file
Text
Do not edit
Default.prm
Load test configuration file
Text
Do not edit
Default.usp
Load test configuration file
Text
Do not edit
.usr
Load test configuration file
Text
Do not edit
Thick_usr.dat
Load test configuration file
Text
Do not edit
Thin_usr.dat
Load test configuration file
Text
Do not edit
Files within Action folder:
File Name
Description
Type
Comments Regarding File
Script.mts
Action script
Text
Edit text preceding the @@ sign only
Resource.mtr
Object Repository
Binary
Do not edit
Snapshots
Active screen files
Folder
Do not edit
There are few more files extensions like
.MTB Batch File
.LCK Locked
When to use a Recovery Scenario and when to us on error resume next?
Recovery scenarios are used when you cannot predict at what step the error can occur or when you know that error won't occur in your QTP script but could occur in the world outside QTP, again the example would be "out of paper", as this error is caused by printer device driver. "On error resume next" should be used when you know if an error is expected and dont want to raise it, you may want to have different actions depending upon the error that occurred. Use err.number & err.description to get more details about the error.
What is the difference between an Action and a function?
Action is a thing specific to QTP while functions are a generic thing which is a feature of VB Scripting. Action can have a object repository associated with it while a function can't. A function is just lines of code with some/none parameters and a single return value while an action can have more than one output parameters.
Where to use function or action?
Well answer depends on the scenario. If you want to use the OR feature then you have to go for Action only. If the functionality is not about any automation script i.e. a function like getting a string between to specific characters, now this is something not specific to QTP and can be done on pure VB Script, so this should be done in a function and not an action. Code specific to QTP can also be put into an function using DP. Decision of using function/action depends on what any one would be comfortable using in a given situation.
How to add a constant number in a datatable?
This is more to do with MS excel then QTP!! but useful to know because at times it becomes frustrating to the novices.
Just append ' to the number
Ex: if you wish to enter 1234567 in datatable then write it as '1234567
How can i check if a parameter exists in DataTable or not?
The best way would be to use the below code:
on error resume next
val=DataTable("ParamName",dtGlobalSheet)
if err.number<> 0 then
'Parameter does not exist
else
'Parameter exists
end if
How can i check if a checkpoint passes or not?
chk_PassFail = Browser(...).Page(...).WebEdit(...).Check (Checkpoint("Check1"))
if chk_PassFail then
MsgBox "Check Point passed"
else MsgBox "Check Point failed"
end if
Friday, July 11, 2008
Interview Questions of QTP
A) Quick Test is a graphical interface record-playback automation tool. It is able to work with any web, java or windows client application. Quick Test enables you to test standard web objects and ActiveX controls. In addition to these environments, Quick Test Professional also enables you to test Java applets and applications and multimedia objects on Applications as well as standard Windows applications, Visual Basic 6 applications and .NET framework applications…
Q. Explain QTP Testing process ?
A) The Quick Test testing process consists of 6 main phases:
1. Create your test plan
Prior to automating there should be a detailed description of the test including the exact steps to follow, data to be input, and all items to be verified by the test. The verification information should include both data validations and existence or state verifications of objects in the application.
2. Recording a session on your application
As you navigate through your application, Quick Test graphically displays each step you perform in the form of a collapsible icon-based test tree. A step is any user action that causes or makes a change in your site, such as clicking a link or image, or entering data in a form.
2. Enhancing your test
o Inserting checkpoints into your test lets you search for a specific value of a page, object or text string, which helps you identify whether or not your application is functioning correctly.
NOTE: Checkpoints can be added to a test as you record it or after the fact via the Active Screen. It is much easier and faster to add the checkpoints during the recording process.
o Broadening the scope of your test by replacing fixed values with parameters lets you check how your application performs the same operations with multiple sets of data.
o Adding logic and conditional statements to your test enables you to add sophisticated checks to your test.
3. Debugging your test
If changes were made to the script, you need to debug it to check that it operates smoothly and without interruption.
4. Running your test on a new version of your application
You run a test to check the behavior of your application. While running, QuickTest connects to your application and performs each step in your test.
5. Analyzing the test results
You examine the test results to pinpoint defects in your application.
6. Reporting defects
As you encounter failures in the application when analyzing test results, you will create defect reports in Defect Reporting Tool.
Q.Explain the QTP Tool interface.
A)It contains the following key elements:
Title bar, displaying the name of the currently open test
Menu bar, displaying menus of Quick Test commands
File toolbar, containing buttons to assist you in managing tests, containing buttons used while creating and maintaining tests
Test toolbar
Debug toolbar, containing buttons used while debugging tests.Note: The Debug toolbar is not displayed when you open Quick Test for the first time. You can display the Debug toolbar by choosing View > Toolbars > Debug. Note that this tutorial does not describe how to debug a test. For additional information, refer to the
Quick Test Professional User’s Guide.
Action toolbar, containing buttons and a list of actions, enabling you to view the details of an individual action or the entire test flow.
Note: The Action toolbar is not displayed when you open Quick Test for the first time. You can display the Action toolbar by choosing View > Toolbars > Action. If you insert a reusable or external action in a test, the Action toolbar is displayed automatically. For additional information, refer to the Quick Test Professional User’s Guide.
Test pane, containing two tabs to view your test-the Tree View and the Expert View
Test Details pane, containing the Active Screen
Data Table, containing two tabs, Global and Action, to assist you in parameterizing your test
Debug Viewer pane, containing three tabs to assist you in debugging your test-Watch Expressions, Variables, and Command. (The Debug Viewer pane can be opened only when a test run pauses at a breakpoint.)
Status bar, displaying the status of the test
Q. Explain about the Test Fusion Report of QTP ?
A) Once a tester has run a test, a Test Fusion report displays all aspects of the test run: a high-level results overview, an expandable Tree View of the test specifying exactly where application failures occurred, the test data used, application screen shots for every step that highlight any discrepancies, and detailed explanations of each checkpoint pass and failure. By combining Test Fusion reports with Quick Test Professional, you can share reports across an entire QA and development team.
Q. To which environments does QTP supports ?
A) Quick Test Professional supports functional testing of all enterprise environments, including Windows, Web, ..NET, Java/J2EE, SAP, Siebel, Oracle, PeopleSoft, Visual Basic, ActiveX, mainframe terminal emulators, and Web services.
Q. How the exception handling can be done using QTP
A. It can be done Using the Recovery Scenario Manager which provides a wizard that gudies you through the process of defining a recovery scenario. FYI.. The wizard could be accessed in QTP> Tools-> Recovery Scenario Manager …….
Q. How many types of Actions are there in QTP?
A. There are three kinds of actions:
non-reusable action—an action that can be called only in the test with which it is stored, and can be called only once.
reusable action—an action that can be called multiple times by the test with which it is stored (the local test) as well as by other tests.
external action—a reusable action stored with another test. External actions are read-only in the calling test, but you can choose to use a local, editable copy of the Data Table information for the external action.
Q. What is Parameterizing Tests?
A. When you test your application, you may want to check how it performs the same operations with multiple sets of data. For example, 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. Alternatively, you can create a parameterized test that runs ten times: each time the test runs, it uses a different set of data.
Q. What is test object model in QTP ?
A) The test object model is a large set of object types or classes that QuickTest
uses to represent the objects in your application. Each test object class has a
list of properties that can uniquely identify objects of that class and a set of
relevant methods that QuickTest can record for it.
A test object is an object that QuickTest creates in the test or component to
represent the actual object in your application. QuickTest stores information
about the object that will help it identify and check the object during the
run session.
A run-time object is the actual object in your Web site or application on
which methods are performed during the run session.
When you perform an operation on your application while recording,
QuickTest:
? identifies the QuickTest test object class that represents the object on which
you performed the operation and creates the appropriate test object
? reads the current value of the object’s properties in your application and
stores the list of properties and values with the test object
? chooses a unique name for the object, generally using the value of one of its
prominent properties
? records the operation that you performed on the object using the
appropriate QuickTest test object method
For example, suppose you click on a Find button with the following HTML
source code:
QuickTest identifies the object that you clicked as a WebButton test object.
It creates a WebButton object with the name Find, and records the following
properties and values for the Find WebButton:
It also records that you performed a Click method on the WebButton.
QuickTest displays your step in the Keyword View like this:
QuickTest displays your step in the Expert View like this:
Browser(”Mercury Interactive”).Page(”Mercury Interactive”).WebButton(”Find”).Click
Q. What is Object Spy in QTP?
A. Using the Object Spy, you can view the properties of any object in an open application. You use the Object Spy pointer to point to an object. The Object Spy displays the selected object’s hierarchy tree and its properties and values in the Properties tab of the Object Spy dialog box.
Q. Syntax for how to call one script from another? and Syntax to call one “Action” in another?
A. RunAction ActionName, [IterationMode , IterationRange , Parameters] Here the actions becomes reusable on making this call to any Action. IterationRange String Not always required. Indicates the rows for which action iterations will be performed. Valid only when the IterationMode is rngIterations. Enter the row range (i.e. “1-7″), or enter rngAll to run iterations on all rows. If the action called by the RunAction statement includes an ExitAction statement, the RunAction statement can return the value of the ExitAction’s RetVal argument.
Q. What is the Diff between Image check-point and Bit map Check point?
A. Image checkpoints enable you to check the properties of a Web image.
You can check an area of a Web page or application as a bitmap. While
creating a test or component, you specify the area you want to check by
selecting an object. You can check an entire object or any area within an
object. QuickTest captures the specified object as a bitmap, and inserts a
checkpoint in the test or component. You can also choose to save only the
selected area of the object with your test or component in order to save disk Space
For example, suppose you have a Web site that can display a map of a city
the user specifies. The map has control keys for zooming. You can record the
new map that is displayed after one click on the control key that zooms in
the map. Using the bitmap checkpoint, you can check that the map zooms
in correctly.
You can create bitmap checkpoints for all supported testing environments
(as long as the appropriate add-ins are loaded).
Note: The results of bitmap checkpoints may be affected by factors such as
operating system, screen resolution, and color settings.
Q. How many ways we can parameterize data in QTP ?
A. There are four types of parameters:
Test, action or component parameters enable you to use values passed
from your test or component, or values from other actions in your test.
Data Table parameters enable you to create a data-driven test (or action)
that runs several times using the data you supply. In each repetition, or
iteration, QuickTest uses a different value from the Data Table.
Environment variable parameters enable you to use variable values from
other sources during the run session. These may be values you supply, or
values that QuickTest generates for you based on conditions and options
you choose.
Random number parameters enable you to insert random numbers as
values in your test or component. For example, to check how your
application handles small and large ticket orders, you can have QuickTest
generate a random number and insert it in a number of tickets edit field.
Q. How do u do batch testing in WR & is it possible to do in QTP, if so explain?
A.Batch Testing in WR is nothing but running the whole test set by selecting “Run Testset” from the “Execution Grid”. The same is possible with QTP also. If our test cases are automated then by selecting “Run Testset” all the test scripts can be executed. In this process the Scripts get executed one by one by keeping all the remaining scripts in “Waiting” mode.
How to capture a tool tip text in QTP?
A.For example, how to get tool tip ('Go to My Yahoo!') from the yahoo page:
Actually, this is not a difficult task. The steps are:
1. Place mouse cursor over the link
2. Wait for tool tip
3. Get text of shown tool tip
This QTP script captures a text of a tool tip:
' Place mouse cursor over the link
Browser("Yahoo!").Page("Yahoo!").WebElement("text:=My Yahoo!").FireEvent "onmouseover"
wait 1
' Grab tooltip
ToolTip = Window("nativeclass:=tooltips_class32").GetROProperty("text")
Please, pay attention on details:
1. We use FireEvent("onmouseover") to simulate mouse placing over the link
2. Function wait(1) waits 1 second for a tool tip
3. To get tool tip text, we use:
Window("nativeclass:=tooltips_class32").GetROProperty("text")
Let's run our code and compare captured tool tip with expected ('Go to My Yahoo!'):
As you can see, above QTP script captures correct text of a Tool tip.
Thursday, July 3, 2008
Quick Test Professional (QTP) - Tutorial
Test Object Model(TOM):
It is a Set of classes,Environment & Properties.
It helps QTP to record properties for each Test Object.
TOM will supply properties that QTP records for each test object during recording,for every class of the selected environment ,properties will configured in the above given order.
With the help of AD-Ins we have selected in the AD-in s manager screen. QTP will get to know the environment and class name of the object,With this information ,it goes to object identification screens and get the list of properties configured in mandatory list. Imedialty it goes to the application window and records current properties of these values. Now the properties and its current values will be placed in the object repository and a statement will be generated in expert view(Script Editor Window).
During Play back QTP goes to object repository and recollects properties description ,with this it recognizes object in the application window and repeats the operation. Sometimes execution fails and a message will appear saying that “Can not Identifying an Object of Class**”Make sure that Properties available in the application. This may happen due to two reasons
Properties available in the repository in adequate to recognized the object.
Properties description in Object repository does not match with the description in AUT(Application Under Test).
When QTP identifies that the properties in the mandatory list are not enough to uniquely identify an object then it records current values of properties available in Assistive properties list.
Smart Identification is properties intelligent,It is complex and reduces performance of test execution. When test execution is posses because object was found with the help of Smart Identification then a warning message will appear in test results window.
- For window application we need to configure Smart Identification by Manually.
- For Web applications Smart identification will be configured automatically.
In Smart Identification we have to separate list to configure includes “ Base filter properties & Optional filter properties”.
Play Back: Steps
Hit Run ----Expert view –Object repository-- application----Expert view –Application –Result screen
OBJECT REPOSITORY :
It stores : ------ Resource file
-------Test object repository description
------- File extensions .mtr & .tsr
File extension of
-- Per test object rep :- filename.mtr
-- Shared Oject rep :- filename.tsr
---Code file extension id script.mts
The purpose of Logical Name is to identify the object in the repository.The purpose of Properties Description is to identify the Object in the repository.
For each object in the application on which end user perform on application a logical name and Physical description of that object will be place in the object repository. Then a statement will be generated in Expert View.
Purpose of the Logical Name is to identify the object in Object repository. QTP generates a Logical name for test object in the repository and the same logical name will be maintained in the expert view.
During test run QTP takes Logical name from the current line from the expert view and find the match in the object repository. For each logical name properties description has been attached .QTP takes properties description to the identified logical name and recognize the object in the application to repeat same operation.
It means the purpose of the properties description is to identify an object in the application.
By default QTP takes Label name to generate Logical Name. This is the unique within the repository file. When multiple objects in the same application window share similar Logical name then for the second object the logical name would be Label name_2.If the another same object is
Identify name would be label name-3 etc...
When an object in the application does not have any label name then QTP generates Class name of that object as logical name. If multiple objects have the same description the logical name would be Class name_2 etc....
Ex: Vbedit_2, Link_3 ,WinButton_4 ......
We can edit auto generated Logical name to any other meaningful name.But make sure that this new name will updated in test script automatically.
Steps for edit Logical name:
1.Go to Resource ---->Object repository
2.Object repository Window will displaying.
3.Select the required logical name to change and press mouse right button and chose the Rename option or press F2.
4.Specify new logical name and press Enter button.
Note:1 When we edit Logical name in the repository all the occurance of existing logical names in script will be updated at a time,but vise verse is not possible.
Note:2 To delete object description from object repository completely, we need to follow the steps sequences.
Steps for Delete object description:
1.Go to Resource -----> Object repository.
2.Object repository Window will displaying.
3.Select logical name to delete its description
4.Press mouse right click for delete option.
Note :3 : To ensure weather properties description uniquely identifies an object in the description and follow the bellow steps:
1.Go to Resource -----> Object repository.
2.Object repository Window will displaying.
3.Select logical name to ensure its properties description
4.View -----> highlight in the application or click on highlight button from tool bar of QTP.
5.If properties are enough to identify the object the respective object will be highlighted else a pop up window with error message appeared.
Steps to Creates Repository by manually:
1.Make sure that application is invoked and navigated to the desired screen.
2.Resource-------> Object Repository
3.Object repository screen appeared.
4.Object --->
Add object to local
5.Mouse pointer changes to pointing icon
6.select the required object in the application window
7.Object selection dialog box with the selected object and all its assendents (Parent)will appear.
8.Make sure that required object is selected and click on OK button.
9.Select object Logical name and properties description will be placed within the object repository under test object root
10.Repeat the steps 4 to 8 to add more objects into repository.
Note:1 Place only the required object into the object repository screen to reduce repository size.
Note:2 the max size of the object repository file is 2MB
OBJECT SPY
This tool is used to let us know all the properties with in current values ,completes object hierarchy and available methods.
Steps:
1.Make sure that application is invoked and navigated to the desired screen.
2.Tools-Object spy
3.Object spy screen appears
4.Hit pointing hand icon from object spy window.
5.Mouse pointer changes to pointer icon
6.select the required object
7.Information of the selected object will be displaying within SPY window.
8.Repeat above to Spy on other objects.
Note: Properties and its object values displayed in object SPY window cannot be saved
Run time object properties are the internal properties of a n object given by developer. Its is not necessary that all the objects must have internal properties.
Test Script Template:
Parent1 Object Class name (“Logical Name”).Parent2 Object Class Name(“Logical Name). ------------- .Child object Class Name(“Logical Name”).Method (Arguments).
Test Object:
It is an object which we creates in the test script. All the test objects would be placed in the object repository
Test Object Properties :
All the properties the test object holds are called test object properties. Test object properties would be placed in the object repository along with the logical Name.
Run Time object:
An object exists in the application on which we execute method during test run.
Run Time object Properties :
All the properties developer associated to an object in the application are called run time object properties.
Note: Test properties are a subset of run time object Methods.
TEST OBJECT METHODS:
1.Button Class:
Click : Click is specified object during the test run.
Syntax : object . click ([x],[y],[button]).
Example: Dialog(“Login”).WinButton(“Ok”).click
Note: [] indicates that Optional
Dbclick : It double clicks on object.
Sytax: object .dbclick (x,y,[button]).
2.Edit Box/Text Box
Set: Sets the value of the specified edit object.click
Syntax: Object . set “text”
Example: Dialog (“Login”).WinEdit(Agent Name”).Set “sekhar”
Setcaretpos : Place the cursor at specified edit object.
Syntax: Object . setcaretpos Position
Example :Dialog(“Login”) winedit(“Agent Name”).setcaretpos 4
Set selection : Selects the specified characters of the string within the specified object
Syntax : Object . Selection startpo,end pos
Example:Dialg(“Login”) .winedit (“Agent name”).set selection 0,4
result: S ekha R
Setsecure: Sets the encoded string in to the password edit object.
Syntax: Object .Setsecure Encryptedstring
Example: 1.Dialog(“Login”).Winedit(“Password”).setsecure “***********”
Navigations : Start--> programs--> QTP—>Tools( to encrypt the password by using QTP)
Example: 2: str= crypt.encrypt.encrypt(“Mercury”)
Dialog(“Login”).Winedit(“Password”).setsecure. Str
3.Window:
Maximize: Maximize the window during the test run.
Syn: Object . Maximize
Example: window(“Notepad”).Maximize
Minimize : Minimize the window during the test run.
Syntax: Object . Minimize
Example: window(“Notepad”). Minimize
Activate: Activate the window
Syntax: Object .Activate
Ex: Window(“Notepad”).Activate
Move: Move the window to the specified co ordinates
Syn: Object move x,y
Ex : Window(“Notepad”).move 150,162
Resize: Resizes the window to the specified dimensions
Syn: object. Resize width,height
Ex: Window(“Notepad”). Resize 180,520
Close: close the window
Syn: Object . close
Ex: Window(“Notepad”). close
4.Radio button:
Set: Set the specified radio button object
Syntax: object . set
Ex: Window(“Flight Reservation”).WinRadiobutton(“Economy”).Set
5.Check Box:
Set: Selects/Unselects the specified check box
Syntax: object . Set boolean value --------- >boolean values: ON/OFF
Ex:For i=1 to 4
Window (“Flight Reservation”).Diallog(“Openorder).WinCheckbox(“customer name”).Set “ON”
wait1
Window(“Flight Reservation”).Diallog(“Open order").WinCheckbox(“customername”).Set
“OFF”
6.Combo Box:
Select :
Selects an items from the specified combo box.
Syn: Object .select “ item name/index”
Ex: Window(“Flight Reservation”).WinCombobox(“FlyFrom”).select”London”
Get items Count:
Retrieves the count of max items from specified object
Syn: object . GetitemsCount
Ex:CNT=Window(“Flight Reservation”).WinCombobox(“Fly From”).Get items count
MSGBOX CNT
Get Selection:
Retrieves item name currently selected in the specified object
syn: Object.Getselection
Ex: Msgbox Window(“Flight Reservation”).WinCombobox(“Fly From”).getselection
Get item :
Retrieves item name for specified index value from the object
Syn: Object.get item (Index)
Ex:Msgbox Window(“Flight Reservation”).WinCombobox(“Fly From”).Getitem(10)
Get content:
Names of the all items will displayed for specified object
Syn : Object .Get Content
7.List Box:
Extend select : Adds current selection to the existing items selection.
Syn: Object . Extend select “item name”
Ex: Browser (“JobsAhead”).page(“JobsAhead”).Weblist(“JobLoc”).Select “Bangalore”
Browser (“JobsAhead”).page(“JobsAhead”).Weblist(“JobLoc”).Extend Select “HYD”
Browser (“JobsAhead”).page(“JobsAhead”).Weblist(“JobLoc”).Extend Select “Goa”
Note: we can select at a time list of locations in the list box.
8.Web Table:
Column Count: Returns count of Max columns for the specified row id from the specified web Table.
Syn: Object. Column count(Row id)
Row Count: Returns counts of maximum rows for a specified web table.
Syn. Object. Row count
Set cell date: Sets the values of specified cell within the specified web table.
Syn: Object. Set cell data Row id ,column id,Value
Get cell date: Returns the current value of the specified cell from web table
Syn: Object . getcelldata (Rowid,columnid)
Example:
Column Count=Browser(“JobsAhead”).Page(“JobsAhead”).webTable(“Personal
Details”).Columncount(1)
Row Count =Browser (“JobsAhead”).Page(“JobsAhead”).webTable(“Personal Details”).Row count
Msgbox Column count
Msgbox row count
For i=1 to Row count
For j=1 to column count
Msgbox Browser (“JobsAhead”).Page(“JobsAhead”).webTable(“Personal Details”).Getcelldata(i,j)
Next
Next
---------------*--------------
Get row with cell text: Returns first row id found that contains the cell with the specified text.
Syn : Object . Get row with cell text “ Text”
Ex:Msgbox Browser (“JobsAhead”).Page(“JobsAhead”).webTable(“Personal Details”).Getrow with cell text ( “Mobile number”).
9.Browser
Refresh: Reloads the specified web browser
Syn: Object.Refresh
Ex: Browsers(“Google”).Refresh
Navigate: Navigates the specified browser to the specified URL
Sny: Object.Navigate “URL Path
Ex : Browsers(“Google”).Navigate ”www.globe7.com”
Back: Navigates the browser to its previous page
Sny: Object. Back
Ex: Browsers(“Google”).Back
Forward: Navigates the specified browser to the next page in the history list
Sny: Object .Forward
Example : Browsers(“Google”).Forward
Home: Navigates the browser to have page specified
Sny: Object.home
Ex:Browsers(“Google”).home
Full screen: Shows the browser in full screen mode
Syn: Object.Full.screen
Example : Browsers(“Google”). Full screen
Stop: Stops the browser request
Syn: Object.Stop
Ex: Browsers(“Google”).Stop
Sync: Wait until the current browser loads completely (Synchronization)
Syn: Object .sync
Ex: Browsers(“Google”).Snyc
Close: Closes the browser
Syn: Object.Close
Ex: Browsers(“Google”).Close
10.Page:
Waits until the specified page loads completely
Ex:Browser(“Google”.page(“qtp-googleserach”.Sync
Common Methods
1.Capture BitMap: Caputures the specified object from the application has an image(.bmp or .png) and saves in the specified file drop
Syn: Object . capturebitmap “Full file Path” over write existing (TRUE)
Ex: Browser(“Google”).capturebitmap “C:\New.bmp”,True ----To overwrite
2.Child Objects: Retries the child objects of the specified parent object that matches the given description.
Syn:Object . Childobjects (description)
Example: Set desc =Description . Create
desc(“Nativeclass”).value=”edit”
Set coll =Dialog(“Login”).ChildObjects(Close)
Msgbox coll.count
3.Exist: Checks weather the specified object exists in the open application and window and returns between value(True or False).The default time for exist method wait when an object is not available in the open application window is 20Sec.
The default time for web application is 60Sec
Syn: object . Exist [Time out]
4.Getvisible Text: Returns text visible for the specified Object
Syn: Object.getvisible Text
Ex: Msgbox Dialog(“Login”).getvisibletext
Note:This method is not met for web objects
3.GetTOProperty: Returns the current value of specified test object property of the specified object from the repository
Syn: Object.GetTOProperty(“Property Name”)
Ex: MSGbox Dialog(“Login”).GetTOProperty(“Text”)
6.GetTOProperties: Returns properties collection of the specified test Object from Object repository.
Syn: Object.GetToProperties
Ex: Set Props = Dialog("BOLOTOLINE"). GetTOProperties
PropsCount = Props.Count
For i = 0 To PropsCount - 1
PropName = Props(i).Name
PropValue = Props(i).Value
MsgBox PropName & " = " & PropValue
Next
7.GetROProperty: Returns current value of the specified property of an object from the application window.
Syn: Object.GetROProperty(“Propertyname”)
Ex: Msgbox window(“Login”).GetROProperty(“Height”)
Note: GetROProperties is not work for runtime application
8.SetTOproperty: Sets the value of the specified test object property dynamically. This new value is not updated in the object Repository.
Syn: Object . SetTOProperty “Property Name”,Property value”
Ex: Dialog (“Login”).Set To Property “Text”, “Login1”
Note: The scope of the new value is till the end of the execution of the script.
9.Type: Performs the keyboard inputs in to the specified objects
Ex: Dialog(“Login”).winEdit(“Agent Name”) .Type “Quick”
Ex: Dialog(“Login”).Winedit(“Agent Name”) .Type “Test”
Ex: Dialog9”Login”).Type mic AltDwn +mic F4 + Mic All Up
Ex: Dialog(“Login”).Type mic ESC
Note: Type and Set perform same operation for edit field,But Type can also perform Active X edit
10.WaitProperty:
Waits until specified property reaches specified target value.
Syn: Object .waitproperty “Property Name”,”target Value”
Ex: Window(“Flight Reservation”).WinButton(“insert Order”).Waitproperty “Enabled”,False
Quality Center
Quality Center
A Quality Center project is a database for collecting and storing data relevant to a testing process. For QuickTest to access a Quality Center project, you must connect to the local or remote Web server where Quality Center is installed. When QuickTest is connected to Quality Center, you can create tests and save them in your Quality Center project. After you run your tests, you can view the results in Quality Center.
Quality Center helps you maintain a project of all kinds of tests (such as QuickTest tests, business process tests, manual tests, tests created using other Mercury products, and so forth) that cover all aspects of your application's functionality. Each test in your project is designed to fulfill a specified testing requirement of your application. To meet the goals of a project, you organize the tests in your project into unique groups.
You can instruct QuickTest to automatically submit a defect to a Quality Center project for each failed step in your test. You can also manually submit a defect for a specific step to Quality Center directly from within your QuickTest Test Results window. These options are only available when you are connected to a Quality Center project.
Saving Tests to a Quality Center Project
When QuickTest is connected to a Quality Center project, you can create new tests in QuickTest and save them directly to your project. To save a test, you give it a descriptive name and associate it with the relevant subject in the test plan tree. This helps you to keep track of the tests created for each subject and to quickly view the progress of test planning and creation. In QuickTest, click Save or choose File > Save to save the test. The Save Test to Quality Center dialog box opens and displays the test plan tree.
The Save Test to Quality Center dialog box opens only when QuickTest is connected to a Quality Center project. To save a test directly in the file system, click the File System button to open the Save QuickTest Test dialog box. You can return to the Save Test to Quality Center project dialog box by clicking the Quality Center button.
Submitting Defects to a Quality Center
When viewing the results of a run session, you can submit any defects detected to a Quality Center project directly from the Test Results window.
To manually submit a defect to Quality Center: or click the Choose Tools > Quality Center ConnectionQuality Center Connection button to connect to a Quality Center project. Choose Tools > Add Defect or click the Add Defect button to open the Add Defect dialog box in the specified Quality Center project. The Add Defect dialog box opens. You can modify the defect information if required. Basic information about the test and any checkpoints (if applicable) is included in the description. Click submit button.
To automatically submit defects to Quality Center: Choose Tools > Options or click the Options button . The Options dialog box opens. Click the Run tab. Select the Submit a defect to Quality Center for each failed step check box.