0% found this document useful (0 votes)
45 views

Qtpscripts 100121132944 Phpapp02

This document contains code snippets for performing various operations using QTP scripts. It includes examples of file system operations like creating and checking for files, database operations like retrieving test data from a database, web scripts for counting browsers and links, and Excel scripts for creating a file, entering data, and using an external Excel file for data-driven testing. The snippets provide examples of automating common tasks like file/database access, web testing, and data-driven testing using QTP scripts.

Uploaded by

Akram Ma
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Qtpscripts 100121132944 Phpapp02

This document contains code snippets for performing various operations using QTP scripts. It includes examples of file system operations like creating and checking for files, database operations like retrieving test data from a database, web scripts for counting browsers and links, and Excel scripts for creating a file, entering data, and using an external Excel file for data-driven testing. The snippets provide examples of automating common tasks like file/database access, web testing, and data-driven testing using QTP scripts.

Uploaded by

Akram Ma
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 5

QTP Scripts

http://www.gcreddy.com/
File System Operations

1) Creating a Flat File


Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("E:\Gcreddy.txt")
2) Checking weather the File is available or not, if not creating
the File
strDirectory="E:\"
strFile="Gcreddy.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strDirectory & strFile) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFile = objFSO.CreateTextFile("E:\Gcreddy.txt")
End if

For more Scripts visit: www.gcreddy.com


Database Operations
1) Get Test Data From a Database and use in Data Driven Testing
(through Scripting)
1) Dim con,rs
2) Set con=createobject("Adodb.connection")
3) Set rs=createobject("Adodb.recordset")
4) con.provider=("microsoft.jet.oledb.4.0")
5) con.open "C:\Documents and Settings\Administrator\My
Documents\Gcreddy.mdb"
6) rs.open "Select * From Login",con
7) While rs.eof <>True
8) SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest
Professional\samples\flight\app\flight4a.exe"
9) Dialog("Login").Activate
10) Dialog("Login").WinEdit("Agent Name:").Set rs.fields ("Agent")
11) Dialog("Login").WinEdit("Password:").Set rs.fields ("Password")
12) Dialog("Login").WinButton("OK").Click
13) Window("Flight Reservation").Close
14) rs.movenext
15) Wend

For more Scripts visit: www.gcreddy.com


Web Scripts
1) Count all opened Browsers on desktop and close them all?

Set oDesc = Description.Create()


oDesc("micclass").Value = "Browser"
Set Browsers =Desktop.ChildObjects (oDesc)
NumberofBrowsers = Browsers.Count()
Reporter.ReportEvent 2,"Res","Number of Browsers are:
"&NumberOfBrowsers
For Counter=0 to NumberofBrowsers-1
Browsers(Counter).Close
Next
2) Count, how many links available in Mercury Tours Home Page.
Set oDesc = Description.Create()
oDesc("micclass").Value = "Link"
Set Lists = Browser("Welcome: Mercury").Page("Welcome:
Mercury").ChildObjects (oDesc)
NumberOfLinks = Lists.Count()
Reporter.ReportEvent 2,"Res","Number of Links are: "&NumberOfLinks
For more Scripts visit: www.gcreddy.com
1)
Excel Scripts
Create an Excel file, enter some data and save the file through VB scripting?
1) Dim objexcel
2) Set objExcel = createobject("Excel.application")
3) objexcel.Visible = True
4) objexcel.Workbooks.add
5) objexcel.Cells(1, 1).Value = "Testing"
6) objexcel.ActiveWorkbook.SaveAs("f:\exceltest.xls")
7) objexcel.Quit
2) Data Driven Testing through an External Excel Sheet

1) Set myExcel=Createobject("Excel.Application")
2) Set myFile=myExcel.workbooks.open ("C:\Documents and Settings\admin\My Documents\gcreddy.xls")
3) Set mySheet=myFile.worksheets("Sheet1")
4) Rows_Count=mySheet.usedrange.rows.count
5) For i= 1 to Rows_Count
6) Agent=mySheet.cells(i,"A")
7) pwd=mySheet.Cells(i,"B")
8) SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest
Professional\samples\flight\app\flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest
Professional\samples\flight\app\","open"
9) Dialog("Login").Activate
10) Dialog("Login").WinEdit("Agent Name:").Set Agent
11) Dialog("Login").WinEdit("Password:").SetSecure pwd
12) Dialog("Login").WinEdit("Password:").Type micReturn
13) Window("Flight Reservation").Close
14) Next

For more Scripts visit: www.gcreddy.com

You might also like