How to get the count of links, images, buttons and edits in a web page using QTP
Function GetAllSpecificControls(Page, MicClass) Set Desc = Description.Create()
Posted by Kanikaram Kiranpaul 109 comments
How to get the count of drop down values in QTP
Write a Script to get the count of the drop down items and then print the drop down values in an excel sheet from QTP.
Before running the script in QTP the user needs to add the dropdown box in the Object repository. Here we are using excel application object so that QTP creates and excel application. We are setting the excel application to be visible so that during run time we can see exactly whats happening. GetROProperty Item Count actaully counts the total number of items in the drop down during run time. Once this count is received we will pass them in a loop so that we can pass them to the excel sheet to be added one by one. msgbox is kept in the loop just to see that each item is being retreived.
'Initializing an array with 3 columns and 4 rows
Dim Eobj Set Eobj= createobject ("Excel.Application")
Eobj.visible = true
Eobj.workbooks.add
Set obj = description.Create()
obj= Browser("Browser").Page("Page").Frame("Frame").WebList("city").GetROProperty("Items Count")
For i=1 to obj
obj2= Browser("Browser").Page("Page").Frame("Frame").WebList("city").GetItem(i)
Msgbox obj2
Eobj.cells(i,1).value = obj2
Next
Eobj.Activeworkbook.Saveas("c:\citylist.xls")
Eobj.quit
Posted by Kanikaram Kiranpaul 119 comments
Automation Testing
In order to enter the field of Automation Testing let us understand what automation is all about and why automation is needed. Find below some quick glance on Automation.
1. Overview of Automation: Automation is preferred in below cases.
- Redundancy
- Avoid Manual misses and assumptions
- Reduce Cost
- Reduce execution time
- Unattended automation
- Good ROI [Return On Investment]
2. Overview of Framework: Framework is a concept/template/structure.
3. Types of Frame Work
Depends on Test Data
User can provide the Test Data
QTP can auto generate the test data as well
Keyword Driven Framework
This require excel sheet till QTP version 9.2
This is in-built in QTP version 9.5
Sample script:
function func_add (i,j)
i=2
j=3
z=i+j
msgbox z
End function
Functions are stored in Function.qfli=2
j=3
z=i+j
msgbox z
End function
Hybrid Framework
This is the combination of Data Driven and Keyword Driven.
Posted by Kanikaram Kiranpaul 0 comments
Labels: automation, automation testing, QTP, rft, selenium, what is automation
How to set Internet Explorer as the default browser in Windows XP SP1 and above for QTP
There is a way to set the Internet Explorer as default browser. Following are the ways to set the browser.
1. This can be done by using the Set Program Access and Defaults feature in windows to set the default browser. To set Internet Explorer as the default which also repairs the file association settings try the following method:
From the Control Panel click on Add/Remove Programs then choose the Set Program Access and Defaults button. Click the Custom button once. From the list that appears, select Internet Explorer and then click the OK button.
2. Another way is to directly click Start and Run. In the Run window type control appwiz.cpl,,3
The Add or Remove Program window will open. Click the Custom button once. From the list that appears, select Internet Explorer and then click the OK button.
QTP Interview Questions-I
1) What are the advantages in Test Automation using a Tool?
a) Fast: Test Tool runs tests significantly faster than human users.
b) Reliable: Automation tool can perform the same operation each time, if we repeated multiple times, so that we can eliminate human errors.
c) Repeatable: We can check how application or website reacts after repeated the same operation with multiple times.
d) Reusable: Automation scripts are reusable on different version of the application of websites even if the user interfaces changes.
e) Comprehensive: In automation testing we can build a suit of tests that covers every feature in the application or website.
f) Programmable: We can program sophisticated Tests that bring out hidden information from the application
2) What are the drawbacks in Test Automation?
a) It is expensive.
b) We cannot automate all areas.
c) Lack of Skill.
d) It has some limitations (It cannot test every thing).
3) What type of test tools available in the industry?
We can segregate Test tools in 2 categories
1) Business Classification
a) Vendor Tools
b) Open Source Tools
c) In-house Tools
2) Technical Classification
a) Functional and Regression Test Tools
b) Load/Stress/Performance Test Tools
c) Security Test Tools
d) Test Management Tools
e) Unit Test Tools
f) Requirement Management Tools Etc...
4) What are the important factors in test tool selection?
1. Technical factors:
a) Nature of the AUT (Application Under Test)
b) Tool Features (Facilities available)
c) Availability of Skilled professionals
d) Organizations experience
e) Technical support from vendor
2. Business factors:
a) Budget
b) Vendor’s Reputation
c) Client’s Interest
5) What test cases can be automated?
Test cases that we want to execute on number of versions of the software. Ex: Regression test cases
Test cases that we want to execute with multiple sets of data. Ex: Data driven test cases
Test cases having complex functionality
6) What test cases cannot be automated?
Dynamically changing functionality
Test cases that require more Human interaction.
CUI (command user interface) based test cases.
7) Explain about the Testing process in QTP?
Planning:
• Analyzing the Application
• Automation Framework Implementation
• Selecting/Generating Test cases for Automation
• Collecting Test Data
• Configuring Tool Settings
Generating the basic tests
Using Object Repository method or using Descriptive Programming, we can generate Tests
Enhancing Tests
With respect to our project requirements, we have to enhance our tests. For enhancing tests QTP is providing various features like:
Inserting Transaction points
Synchronization
Parameterization
Inserting VB script Flow Control statements
Adding comments
Calling Functions/ calling Actions
Using Environment variables
Entering Regular Expressions
Inserting Checkpoints
Inserting Output values
Note: For any Test all enhancement methods not required.
Debugging Tests (if required)
It is optional; basically scripting languages are Light weight languages, no need to compile them separately. During execution Scripts can be compiled and Run.
If we have any doubts about some scripts, then we can execute them step by step with the support of VBScript Debug commands and Break points.
Running tests
Generally, many companies are using Framework feature for Running Tests.
QTP Supports many kinds of test execution like Individual Test execution, Batch execution which means you can run many scripts by forming a batch, Tests execution through AOM Scripting, and Scheduled execution i.e setting up a certain time or configuring the test with the support of Windows Operating system to set up time when the script should execute.
Analyzing Results
It is not the Responsibility of QTP; Test engineer has to do this manually.
QTP is providing Result window in XML format.
QTP is providing Result deletion tool also.
QTP is providing Test results exporting facility. It supports HTML, Word document and PDF (portable document format) formats.
Reporting Defects
Reporting defects of a Application under Test is not a QTP responsibility. Reporting of defects should be done manually after analyzing the test results, but if Quality Center is used then from the QTP result window the defects can be send directly..
8) What types of License available for QTP?
a) Seat License or Node locked
Fixed for one System (Machine), we can use from that System only
b) Concurrent License or Floating License
This License, we can use from different Systems but one at a time
9) What are the QTP supported environments?
QTP Supports Software Applications based on Add-ins only. Add-in means Technology supporting files. QTP Add ins available for following technologies:
a) Default Add ins
1) Activex
2) Visual Basic
3) Web
b) Other Add-ins
1) Delphi
2) Java
3) .NET Web forms
4) .NET Windows forms
5) WPF (Windows Presentation Foundation)
6) Oracle
7) People Soft
8) Power Builder
9) SAP for Web
10) SAP GUI for windows environment
11) Siebel Environment
12) Standard Windows
13) Terminal Emulator (TE)
14) Visual Age Smalltalk Environment
15) Web Services Environment
10) Does QTP Support UNIX Environment?
No, QTP doesn’t support UNIX/Linux Environment, Supports Windows Operating Environment only, but LoadRunner and Quality Center have support both Windows and UNIX Operating Environments.
11) What scripting language is used in QTP to applying programming logic?
Micro Soft Visual Basic Scripting edition (VBScript) engine embedded with QTP.
12) Does QTP Support Database Testing and Data driven Testing?
Yes, SQL Engine embedded with QTP Tool, so we use SQL Statements directly in QTP Test Pane as well as in Function Library. QTP has an integrated Spread sheet(Excel like) for Performing Data Driven Testing, otherwise we can fetch test data directly from external files and databases using VB Script.
Posted by Kanikaram Kiranpaul 1 comments
Labels: interview questions, QTP, QTP 11, QTP 9.2, QTP interview questions
Write a Script to open an excel workbook through VB Scripting
The below vb script will open an excel work book for which the path is mentioned.
set xl = CreateObject("Excel.Application")
xl.visible = true
set wb = xl.workbooks.open("C:\test.xls")
wb.close
xl.quit
Posted by Kanikaram Kiranpaul 0 comments
Child Objects in QTP scripts with examples
Many at times in Scripting we come across scenarios where we need to count the objects in the application or even highlight a child object like highlighting a text box or check and uncheck check boxes using scripting in QTP.
Below are some of the examples where in you can do different actions. For our example we are using Flight Reservation application as reference.
Below are some of the examples where in you can do different actions. For our example we are using Flight Reservation application as reference.
'Script to count the number of child objects of flight reservation application
Set chd_obj = Dialog("text:=Login").ChildObjects
msgbox chd_obj.count
'Script to highlight all the child objects in Login dialog of flight reservation application
Set chd_obj = Dialog("text:=Login").ChildObjects
For i = 0 to chd_obj.count - 1
chd_obj(i).Highlight
Next
'Script to highlight all the child objects(buttons) in Login dialog of flight reservation application
Set button_obj = Description.Create
button_obj("nativeclass").Value = "Button"
Set chd_obj = Dialog("text:=Login").ChildObjects(button_obj)
For i = 0 to chd_obj.count - 1
chd_obj(i).Highlight
Next
'Script to check and uncheck all the check boxes in open order dialog box of flight reservation application
Set checkbox_obj = Description.Create
checkbox_obj("Class Name").value = "WinCheckBox"
Set chd_obj = Window("text:=Flight Reservation").Dialog("text:=Open Order").ChildObjects(checkbox_obj)
For i = 0 to chd_obj.Count - 1
chd_obj(i).Set "ON"
chd_obj(i).Set "OFF"
Next
Posted by Kanikaram Kiranpaul 9 comments
Write a Script to delete all the spam mails in Gmail
We will write a script in QTP for deleting all the spam mails in Gmail Account. What we will do is first we will get the innertext of the Spam Link using GetROProperty so that if there are no spam mails then we will exit the test using ExitTest method or can use ExitAction method if we want to only exit that particular action.
'Script to Delete spam messages from Gmail
'First get the spam count. if there are no spam mails then exit test
'using GetROProperty to get the innertext of the Spam Link
spamct = browser("title:=Gmail.*").Page("title:=Gmail.*").link("innertext:=Spam.*").GetROProperty("innertext")
'Checking whether spam mails are there or not
If spamct = "Spam" Then
Print "No spam Mails"
'Since there are no spam mail you can exit Test or Exit Action. Based on users decision
ExitTest
'If spam mails are present then we will enter the else part
Else
'we will take the innertext of Spam link and remove all the unnecessary characters and print only the spam count.
spamcount = Replace(spamct, "spam", "") 'replacing the spam word with space
spamcount = Trim(spamcount)
spamcount = Replace(spamcount, "(","")
spamcount = Replace(spamcount, ")","")
'Printing the number of spam mails to the user
print "You have "&spamcount& " unread spam mails and all the available spam mails will be deleted forever"
'clicking on the spam link
Browser("title:=Gmail.*").Page("title:=Gmail.*").sync
Browser("title:=Gmail.*").Page("title:=Gmail.*").link("innertext:=Spam.*").Click
'Creating a description object for check boxes
Set abc_obj = Description.Create
abc_obj("micclass").Value = "WebCheckBox"
'Getting the childobjects i.e Checkboxes
Set browser_checkbox = Browser("title:=Gmail.*").Page("title:=Gmail.*").childobjects(abc_obj)
'using a for loop to set the check boxes to on position i.e selecting them
For i = 0 to browser_checkbox.Count - 1
browser_checkbox(i).Set "ON"
Next
'Clicking on the delete forever button to delete the spam mails
Browser("title:=Gmail.*").Page("title:=Gmail.*").webElement("innertext:=Delete forever","index:=*.*").Click
'using windows script host environment to make sure that the delete forever button is clicked
Set wsh = CreateObject("wscript.Shell")
wsh.sendkeys ("{Enter}")
End If
Posted by Kanikaram Kiranpaul 1 comments
Description Object in QTP (Description. Create)
We will look at Description Objects (Description. Create in QTP) which is very important in Descriptive programming in QTP. In Descriptive programming we can create object with description being a single property or multiple properties. We actually put a collection of properties for an object. We can create and empty object and place all the required properties in it. This object can be used instead of the actual object.
We will see how to create a Description Object
Set Desc = Description.Create
'script to login flight reservation using dynamic descriptive programming
Set dialog_login = Description.create
dialog_login("text").value ="Login"
Set edit_agentname = Description.Create
edit_agentname("attached text").value = "Agent Name:"
Set edit_password = Description.Create
edit_password("attached text").value = "Password:"
Set button_ok = Description.Create
button_ok("text").value ="OK"
Dialog(dialog_login).Activate
Dialog(dialog_login).WinEdit(edit_agentname).Set "Ravi"
Dialog(dialog_login).WinEdit(edit_password).Set "mercury"
Dialog(dialog_login).WinButton(button_ok).Click
The other way to login in to the Flight Reservation Application is by simply putting in the properties and values in the script it self instead of creating description Objects. Instead of learning the objects into the object repository we use the associated properties and values of the object and directly pass them.
Look at the simple script using descriptive programming.
'Descriptive programming to login to the flight application.
Dialog("text:=Login").Activate
Dialog("text:=Login").WinEdit("attached text:=Agent Name:").Set "Ravi"
Dialog("text:=Login").WinEdit("attached text:=Password:").Set "mercury"
Dialog("text:=Login").WinButton("text:=OK").Click
Posted by Kanikaram Kiranpaul 8 comments
Write a script to delete the mails in the Trash Folder in Gmail Account?
We can write a script to delete all the trash mails in the Gmail Account. First we need to Click the Trash link then click the all link in the trash mail page so that all the available mails in the table are checked and then we need to click the Delete Forever button. I have faced a problem when clicking on the All Link because when the All link is clicked it is actually selecting all the mails in the Inbox because the objects used like Select: All, None, Read, Unread, Starred, Unstarred are being used the same. So I faced a little problem but we can solve that by using object repository for that particular line of code.
Please note that you need to be logged in to the Gmail Account to successfully run the below scripts.
First Method to delete the trash mails from Gmail Account:
Browser("title:=Gmail.*").Page("title:=Gmail.*").Link("text:=Trash", "class:=n.*").Click
Browser("title:=Gmail - Trash.*").Page("title:=Gmail - Trash.*").Sync
If Browser("title:=Gmail - Trash.*").Page("title:=Gmail - Trash.*").WebElement("innertext:=Empty Trash.*", "html id:=:.*").Exist(1) Then
Browser("title:=Gmail - Trash.*").Page("title:=Gmail - Trash.*").WebElement("innertext:=All", "Index:=*.*").Click
Wait 2
Browser("title:=Gmail - Trash.*").Page("title:=Gmail - Trash.*").WebElement("innertext:=Delete forever","index:=*.*").Click
Else
Print "You are not in proper page"
End If
Set wsh = CreateObject("WScript.Shell")
wsh.SendKeys ("{ENTER}")
Second Method to delete the trash mails from Gmail Account:
Browser("Gmail").Page("Gmail").Frame("frame").Link("Trash").Click
If Browser("Gmail").Page("Gmail").Frame("frame").Webtable("No conversations in the").Exist (1) Then
Reporter.ReportEvent micPass, "No messages", "There are no messages to be deleted"
Else
Browser("Gmail").Page("Gmail").Frame("frame").WebElement("All").Click
Browser("Gmail").Page("Gmail").Frame("frame").WebElement("Delete forever").Click
Set wsh = CreateObject("wscript.shell")
wsh.sendkeys ("{Enter}")
Reporter.ReportEvent micPass, "Deleted", "All the selected messages are deleted"
End If
Posted by Kanikaram Kiranpaul 2 comments
Write a Script in QTP to count the no of buzz messages in a Gmail Account.
We will need to use the GetROProperty method to get the count of the buzz messages in the Gmail Account for a user and this number is dynamic so we use the GetRoProperty method and get the innertext value. We will use the GetROProperty (Get Run Time Object Property) to get the count of the Buzz Messages ex Buzz (25) and then replace Buzz, (,) with a null and then print only the number to the user.
'You need to be logged into the Gmail account
Browser("title:=Gmail.*").Page("title:=Gmail.*").Link("innertext:=Buzz.*","class:=n.*").Click
'To get the innertext of Buzz link
buzzcount = Browser("title:=Gmail.*").Page("title:=Gmail.*").Link("innertext:=Buzz.*","class:=n.*").GetROProperty("innertext")
If buzzcount = "Buzz" Then
Print "No Buzz Messages"
ExitAction
Else
buzzct = Replace(buzzcount, "Buzz","")
buzzct = Rtrim(ltrim(buzzct))
buzzct = Replace(buzzct, "(","")
buzzct = Replace(buzzct,")","")
Print "You have "&buzzct& " Buzz Messages."
End If
Posted by Kanikaram Kiranpaul 2 comments
Write a Script in QTP to count the unread emails of a gmail account.
In order to count the unread emails of a gmail account you need to be logged into the Gmail account and then run this script which will count all the unread email and display the no of unread emails. We will use the GetROProperty (Get Run Time Object Property) to get the no of unread emails ex Inbox (25) and then replace Inbox, (, ) with a null and then print only the number.
'You need to be logged into the Gmail account
Browser("title:=Gmail.*").Page("title:=Gmail.*").Link("innertext:=Inbox.*").Click
Browser("title:=Gmail.*").Page("title:=Gmail.*").Sync
'To get the innertext of inbox link
inboxcount = Browser("title:=Gmail.*").Page("title:=Gmail.*").Link("innertext:=Inbox.*").getroproperty("innertext")
If inboxcount = "Inbox" Then
Print "No Unread Emails."
ExitAction
Else
emailcount = replace(inboxcount, "Inbox","") 'replaces inbox with space
emailcount = Rtrim(ltrim(emailcount)) 'removes all the spaces
emailcount = replace(emailcount, "(","")
emailcount = replace(emailcount, ")","")
Print "You have "&emailcount& " unread emails in your inbox."
End If
Posted by Kanikaram Kiranpaul 0 comments
Write a Script to Login in to Gmail Account using QTP?
We will write a script to login to a Gmail Account. This QTP Script to log into Gmail Account is a Generic one. There is no need for us to have Object Repository since I am using Descriptive Programming. Where we use the properties and the values to identify the run time object in the Application under test.
Systemutil.Run "http://www.gmail.com"
Or
'Launching Internet Explorer and Opening Gmail Application
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "http://www.gmail.com"
'We will use the sync method to wait till Gmail opens
Browser("Title:=Gmail.*").Page("title:=Gmail.*").Sync
'Script to set username and password to login
Browser("Title:=Gmail.*").Page("title:=Gmail.*").WebEdit("name:=Email").Set "xxxxxx"
Browser("Title:=Gmail.*").Page("title:=Gmail.*").WebEdit("name:=Passwd").Set "yyyyyy"
Browser("Title:=Gmail.*").Page("title:=Gmail.*").WebButton("name:=Sign in").click
Browser("Title:=Gmail.*").Page("title:=Gmail.*").Sync
If Browser("Title:=Gmail.*").Page("title:=Gmail.*").Link("innertext:=Sign out", "html id:=:.*").Exist(1) Then
'Print a Pass message for the user if logged in
Print "User " &Username& " is successfully Logged in"
Else If not Browser("Title:=Gmail.*").Page("title:=Gmail.*").Link("innertext:=Sign out", "html id:=:.*").Exist(1) Then
'Print a Fail message for the user if not able to log in and terminate the action
Print "User " &Username& " is not able to Login in"
Print "The Test has been terminated"
ExitAction
End If
End If
Posted by Kanikaram Kiranpaul 22 comments
What is a Virtual Object and it helps in solving Object Recognition Problem in QTP ?
Virtual Objects comes into picture if QTP is unable to recognize an object and we often see errors as Object not found. This is because even thought you have recorded the actions during playback time QTP is unable to recognize an object and because of which the script fails.
Points to Note:
1. We cannot use object spy on a Virtual Object.
2. We can only record on Virtual Objects.
3. Scroll Bars and Labels cannot be treated as Virtual Objects.
In order to disable the Virtual Objects Navigate to Tools, Options, General, Check the check box for "Disable Recognition of Virtual Objects While Recording"
When Object recognition Problem occurs in QTP during playback on the Application Under test there are ways to handle this Object Recognition Problem. It depends solely on the user as to what they want to use.
The different ways to handle Object Recognition Problem are:
1. By Creating Virtual Objects.
2. Using Low Level Recording.
3. Using Analog Recording.
Posted by Kanikaram Kiranpaul 10 comments
Creating a MS Word Document using QTP 9.2
It is very easy to create a MS Word Document using QTP. There is no need to invoke the MS Word application in QTP but we require to use the Word Library by using the CreateObject method. If you have word on Excel Application in QTP then it is more or less similar working with Word Library. I will show a sample script to create a word document and also add some text to the word Document.
Script to create a Word Document in QTP
Set wordapp = CreateObject("Word.Application")
wordapp.visible = True
wordapp.documents.Add
wordapp.Selection.TypeText "This is a sample document"
wordapp.ActiveDocument.SaveAs "E:\testdoc.doc"
wordapp.Quit
Set wordapp = Nothing
We are using Wordapp.Visible = true because we want the application to be visible for the user while the text is being written to the Word Document. TypeText property is used to write the text in the word document. In order to save the document we use ActiveDocument menthod because in case if there are other word document already opened then the active document will be saved.
Posted by Kanikaram Kiranpaul 0 comments
Recovery Settings in QTP
Recovery scenario comes into picture when you want to handle some exception in the test by creating a Recovery scenario. Now to add this recovery scenario to a test we need to associate it in the test Settings.
Posted by Kanikaram Kiranpaul 0 comments
Environment Settings in QTP
User Defined Environment Variables in QTP
Environment Variables in QTP are the utility objects of QTP which enables us to work with Environment Variables. In the Test Settings we can add user defined Environment Variables for a particular test or can also load an environment XML file to a test.
Posted by Kanikaram Kiranpaul 0 comments
Built in EnvironmentVariables Settings in QTP
Environment Variables in QTP are the utility objects of QTP which enables us to work with Environment Variables. Here in this tab you have two settings one is Built in and user Defined.
You need to Navigate to File > Settings > Test Settings > Environment
Built in Environment Variables:
Posted by Kanikaram Kiranpaul 0 comments
Resources Settings in QTP
Associating Function Libraries to a QTP Test is very important as it is associated from an external location and since we use frame work each of the test script is broken down into different functions and there should be a way to associate them to a test. The Resource Tab in Test Settings helps you to do this.
You need to navigate to File > Settings > Test Settings > Resources.
Posted by Kanikaram Kiranpaul 0 comments
Run Settings in QTP
Test Settings in QTP is very vital as it provides a lot of settings for a test and allows you to control the way QTP should run.
Here we will look at the various options available for user customize Run Settings in QTP while running a test.
Run one iteration only: The test will run only for one time.
Run on all rows: The test will run on all rows
1. Pop up message box
2. Proceed to next action iteration
3. Stop Run
4. Proceed to next step
Check box items are:
Disable smart identification during run session
Posted by Kanikaram Kiranpaul 2 comments