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
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.