QTP Programs
QTP is widely/most popularly used as Functional/Regression Test automation tool. It was initially developed by Mercury Interactive and then acquired by HP. It is really user friendly tool. Anyone can easily start using it, at the same time it can be used extensively by the experts to utilize many features of QTP. If you have any questions and need any clarification about Sofware Testing and QTP, you can ask/discuss thro' the Comment Section of this knol.
Search This Blog
Wednesday, 16 January 2013
Finding RAM size using QTP Program?
Sorting Data in Excel Sheet ?
Sunday, 11 November 2012
Basic Concepts in QTP
What is QTP?
This is the topic you should ideally start with. You should have an idea of what QTP is all about, what type of testing you can do with QTP, different types of applications that it supports & other general stuff like what is the latest QTP version, from where you can download QTP, what are the different license modes etc.
What sort of Applications / Test Cases should be considered for Automation using QTP.
Now this is a very important concept that must be looked at before starting with any automation project using QTP. You should be able to analyze your manual test cases and your application to see if it is can be automated or not. If it can be automated, you should be able to figure out if you’d really derive any benefit by automating the test cases.
Get familiar with the QTP tool.
Before starting to create test scripts in QTP, you should be familiar with the QTP tool. You should be aware of the different panes and controls in the QTP window. You should know what they are and for what purpose they are used.
Test Objects and Object Repositories.
You should know what are test objects, what is object hierarchy, how you can identify objects using QTP and how you can identify unique properties for your objects. You should also know what object repositories are, why they are used and how you can use them to add objects.
Creating Test Scripts / Actions.
Now comes the real scripting part. You should be able to use the record & playback method to create & run test cases. Together with record & playback method, you should be able to ‘write’ your code after associating object repositories to your actions.
Analyzing your Test Run Results.
Once you run your test scripts, you should be able to analyze the test run results. You should be able to find out which steps have passed & which have failed. You should also be able to identify the test case flow using the run results.
Creating Functions & Using Function Libraries.
You should be able to identify reusable flows & functionality in your test cases. You should be able to write user defined functions for the reusable flows. You should also be able to create new function libraries, add some reusable functions to these function libraries and use these functions in your script by associating the function libraries to your test script.
Working with Data Tables.
You should know how you can use data table to pass on data values in your test script. You should also be aware of how you can take data from excel sheets and use it in your scripts.
Basics of Debugging.
You should have a clear understanding of the basic debugging techniques in QTP. You should know how to use breakpoints in your code. You should also know how you can make use of the debug viewer pane while running your test scripts.
QTP File Handling
Many a times you may need to interact with text files using QTP. Interaction can be(but not limited to) in the form of reading input from a file, writing output to a file. This post describe in detail "File handling using QTP".
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_locationWe would use the same example for the rest of this post.
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
How to open a file?
Set file= fso.OpenTextFile("C:\file_location", ForWriting, True)How to read content from a file?
//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.
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 fileHow to write content to a file?
Do while file.AtEndofStream <> True
data = file.ReadLine()
msgbox data
Loop
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 fileHow to delete content?
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.
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)
Tuesday, 6 November 2012
Create excel file and enter some data save it
- '###############################################
- 'Create excel file and enter some data save it
- '###############################################
- 'Create Excel Object
- Set excel=createobject("excel.application")
- 'Make it Visible
- excel.Visible=True
- 'Add New Workbook
- Set workbooks=excel.Workbooks.Add()
- 'Set the value in First row first column
- excel.Cells(1,1).value="testing"
- 'Save Work Book
- workbooks.saveas"D:\excel.xls"
- 'Close Work Book
- workbooks.Close
- 'Quit from Excel Application
- excel.Quit
- 'Release Variables
- Set workbooks=Nothing
- Set excel=Nothing
- '###############################################
- ' Reading Values from a Specific excel Sheet
- '###############################################
- 'Create Excel Object
- Set excel=createobject("excel.application")
- 'Make it Visible
- excel.Visible=True
- 'Open the Excel File
- Set workbook=excel.Workbooks.Open("D:\excel.xls")
- 'Get the Control on Specific Sheet
- Set worksheet1=excel.Worksheets.Item("Sheet1")
- ' Display the Values
- Msgbox worksheet1.cells(1,1).value
- 'Close Work Book
- workbook.Close
- 'Quit from Excel Application
- excel.Quit
- 'Release Variables
- Set worksheet1=Nothing
- Set workbook=Nothing
- Set excel=Nothing
- '###############################################
- ' Deleting Rows from Excel Sheet
- '###############################################
- 'Create Excel Object
- Set excel=createobject("excel.application")
- 'Make it Visible
- excel.Visible=True
- 'Open the Excel File
- Set workbook=excel.Workbooks.Open("D:\excel.xls")
- 'Get the Control on Specific Sheet
- Set worksheet1=excel.Worksheets.Item("Sheet1")
- 'Delete Row1
- worksheet1.Rows("1:1").delete
- 'Save Excel
- workbook.SaveAs("D:\excel.xls")
- 'Close Work Book
- workbook.Close
- 'Quit from Excel Application
- excel.Quit
- 'Release Variables
- Set worksheet1=Nothing
- Set workbook=Nothing
- Set excel=Nothing
- ############################################
- ' Add and Delete ExcelSheet
- '###############################################
- 'Create Excel Object
- Set excel=createobject("excel.application")
- 'Make it Visible
- excel.Visible=True
- 'Open Existing Excel File
- Set workbook=excel.Workbooks.Open("D:\excel.xls")
- 'Add New Sheet
- Set newsheet=workbook.sheets.Add
- 'Assign a Name
- newsheet.name="raj"
- 'Delete Sheet
- Set delsheet=workbook.Sheets("raj")
- delsheet.delete
- 'Close Work Book
- workbook.Close
- 'Quit from Excel Application
- excel.Quit
- 'Release Variables
- Set newsheet=Nothing
- Set delsheet=Nothing
- Set workbook=Nothing
- Set excel=Nothing
- '###############################################
- ' Copy an Excel Sheet of one Excel File to another Excel File
- '###############################################
- 'Create Excel Object
- Set excel=createobject("excel.application")
- 'Make it Visible
- excel.Visible=True
- 'Open First Excel File
- Set workbook1=excel.Workbooks.Open("D:\excel1.xls")
- 'Open Second Excel File
- Set workbook2=excel.Workbooks.Open("D:\excel2.xls")
- 'Copy data from first excel file sheet
- workbook1.Worksheets("raj").usedrange.copy
- 'Paste Data to Second Excel File Sheet
- workbook2.Worksheets("Sheet1").pastespecial
- 'Save Workbooks
- workbook1.Save
- workbook2.Save
- 'Close Workbooks
- workbook1.Close
- workbook2.Close
- 'Quit from Excel Application
- excel.Quit
- 'Release Variables
- Set workbook1=Nothing
- Set workbook2=Nothing
- Set excel=Nothing
- ###############################################
- ' Comapre Two Excel Sheets Cell By Cell for a specific Range
- '###############################################
- 'Create Excel Object
- Set excel=createobject("excel.application")
- 'Make it Visible
- excel.Visible=True
- 'Open Excel File
- Set workbook=excel.Workbooks.Open("D:\excel.xls")
- 'Get Control on First Sheet
- Set sheet1=excel.Worksheets.Item("Sheet1")
- 'Get Control on Second Sheet
- Set sheet2=excel.Worksheets.Item("Sheet2")
- 'Give the specific range for Comparision
- CompareRangeStartRow=1
- NoofRows2Compare=4
- CompareRangeStartColumn=1
- NoofColumns2Compare=4
- 'Loop through Rows
- For r=CompareRangeStartRow to(CompareRangeStartRow+(NoofRows2Compare-1))
- 'Loop through columns
- For c=CompareRangeStartColumn to(CompareRangeStartColumn+(NoofColumns2Compare-1))
- 'Get Value from the First Sheet
- value1=Trim(sheet1.cells(r,c))
- 'Get Value from the Second Sheet
- value2=Trim(sheet2.cells(r,c))
- 'Compare Values
- If value1<>value2 Then
- ' If Values are not matched make the text with Red color
- sheet2.cells(r,c).font.color=vbred
- End If
- Next
- Next
- 'Save workbook
- workbook.Save
- 'Close Work Book
- workbook.Close
- 'Quit from Excel Application
- excel.Quit
- 'Release Variables
- Set sheet1=Nothing
- Set sheet2=Nothing
- Set workbook=Nothing
- Set excel=Nothing
- ###############################################
- ' Reading complete data from excel file
- '###############################################
- 'Create Excel Object
- Set excel=createobject("excel.application")
- 'Make it Visible
- excel.Visible=True
- 'Open Excel File
- Set workbook=excel.Workbooks.Open("D:\excel.xls")
- 'Get Control on Sheet
- Set worksheet=excel.Worksheets.Item("raj")
- 'Get the count of used columns
- ColumnCount=worksheet.usedrange.columns.count
- 'Get the count of used Rows
- RowCount=worksheet.usedrange.rows.count
- 'Get the Starting used Row and column
- top=worksheet.usedrange.row
- lft=worksheet.usedrange.column
- 'Get cell object to get the values cell by cell
- Set cells=worksheet.cells
- 'Loop through Rows
- For row=top to (RowCount-1)
- rdata=""
- 'Loop through Columns
- For col=lft to ColumnCount-1
- 'Get Cell Value
- word=cells(row,col).value
- 'concatenate all row cell values into one variable
- rdata=rdata&vbtab&word
- Next
- 'Print complete Row Cell Values
- print rdata
- Next
- 'Close Work Book
- workbook.Close
- 'Quit from Excel Application
- excel.Quit
- 'Release Variables
- Set worksheet=Nothing
- Set workbook=Nothing
- Set excel=Nothing
- #############################################
- ' Read complete data from an Excel Sheet content
- '###############################################
- 'Create Excel Object
- Set excel=createobject("excel.application")
- 'Make it Visible
- excel.Visible=True
- 'Open Excel File
- Set workbook=excel.Workbooks.open("D:\excel.xlsx")
- 'Get Control on Sheet
- Set worksheet=excel.Worksheets.Item("Sheet1")
- 'Get Used Row and Column Count
- rc=worksheet.usedrange.rows.count
- cc=worksheet.usedrange.columns.count
- 'Loop through Rows
- For Row=1 to rc
- 'Loop through Columns
- For Column=1 to cc
- 'Get Cell Data
- RowData=RowData&worksheet.cells(Row,Column)&vbtab
- Next
- RowData=RowData&vbcrlf
- Next
- 'Display complete Data
- msgbox RowData
- 'Close Work Book
- workbook.Close
- 'Quit from Excel Application
- excel.Quit
- 'Release Variables
- Set worksheet=Nothing
- Set workbook=Nothing
- Set excel=Nothing
- ###############################################
- ' Assign Colours to Excel Sheet Cells, Rows
- '###############################################
- 'Create Excel Object
- Set excel=createobject("excel.application")
- 'Make it Visible
- excel.Visible=True
- 'Add a New work book
- Set workbook=excel.workbooks.add()
- 'Get the Excel Sheet
- Set worksheet=excel.worksheets(1)
- 'Coloring Excell Sheet Rows
- Set objrange=excel.activecell.entirerow
- objrange.cells.interior.colorindex=37
- 'Coloring Excell Sheet Cell
- worksheet.cells(2,1).interior.colorindex=36
- 'Save Excel
- workbook.SaveAs("D:\excel.xls")
- 'Close Work Book
- workbook.Close
- 'Quit from Excel Application
- excel.Quit
- 'Release Variables
- Set objrange=Nothing
- Set worksheet=Nothing
- Set workbook=Nothing
- Set excel=Nothing