1. Script for sending a mail using outlook express.
Dim
objOutlookMsg,objOutlook
Set objOutlook = CreateObject(“Outlook.Application”)
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
objOutlookMsg.To = “”
objOutlookMsg.CC = “ “
objOutlookMsg.BCC = “”
objOutlookMsg.Subject = “test”
objOutlookMsg.Body = “”
objOutlookMsg.Attachments.Add “C:\Documents and Settings\Desktop\testreport.txt”
objOutlookMsg.Send
Set objOutlook = CreateObject(“Outlook.Application”)
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
objOutlookMsg.To = “”
objOutlookMsg.CC = “ “
objOutlookMsg.BCC = “”
objOutlookMsg.Subject = “test”
objOutlookMsg.Body = “”
objOutlookMsg.Attachments.Add “C:\Documents and Settings\Desktop\testreport.txt”
objOutlookMsg.Send
2. Script for opening a Notepad file.
In Expert view write a
builtin funtion
invokeapplication”c:/whatever the path”
Run
Dim a
Set a = WScript.CreateObject (“WSCript.shell”)
a.run “notepad.exe”
invokeapplication”c:/whatever the path”
Run
Dim a
Set a = WScript.CreateObject (“WSCript.shell”)
a.run “notepad.exe”
Dim oShell
Set oShell = CreateObject (“WSCript.shell”)
oShell.run “cmd/notepad.exe”
Set oShell = Nothing
Set oShell = CreateObject (“WSCript.shell”)
oShell.run “cmd/notepad.exe”
Set oShell = Nothing
DsystemUtil.Run
“Notepad.exe”
3. Script for connecting the oracle database
public void connectDB()
{
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
Set objCon=CreateObject(“ADODB.Connection”)
Set objRec=CreateObject(” ADODB.Recordset”)
objCon.Open “DRIVER={Oracle in OraHome92};SERVER={Servername};UID={Username};PWD={Password};DBQ={Dbnmae}”
objRec.CursorLocation = adUseClient
objRec.Open “Select {Col name} from tablename”,objCon,adOpenStatic,adLockOptimistic
While(objRec.EOF)
objRec.MoveNext
Msgbox ”Result” & objRec.Fields.Item(“{Col name}”)& vbCrLf
Wend
objRec.Close
objCon.Close
Set objRec=Nothing
Set objCon=Nothing
Msgbox “Executed Sucessfully”
}
{
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
Set objCon=CreateObject(“ADODB.Connection”)
Set objRec=CreateObject(” ADODB.Recordset”)
objCon.Open “DRIVER={Oracle in OraHome92};SERVER={Servername};UID={Username};PWD={Password};DBQ={Dbnmae}”
objRec.CursorLocation = adUseClient
objRec.Open “Select {Col name} from tablename”,objCon,adOpenStatic,adLockOptimistic
While(objRec.EOF)
objRec.MoveNext
Msgbox ”Result” & objRec.Fields.Item(“{Col name}”)& vbCrLf
Wend
objRec.Close
objCon.Close
Set objRec=Nothing
Set objCon=Nothing
Msgbox “Executed Sucessfully”
}
Use code only that which
is inside the function connectDB
4. Two ways to connect QC with QTP.
Connect manually
1.
To connect to TD from QTP follow the steps…
2.
Open Qtp ==> Tools ==>
3.
Select TestDirector Connection ==>
4.
In Server Connction Box Enter TD address(URL of TD) ==>
5.
Click Connect==>
6.
In project Connection Box Enter the Details Domain,Project,User
name and Password ==>
7.
Click Connect If you want to reconnect on startup check the
reconnect on startup and save password for reconnection on startup.
8.
Then close.
Using Script
Set qtApp = CreateObject(“QuickTest.Application”)
qtApp.Launch
qtApp.Visible = True
qtApp.TDConnection. Connect “URL”, “DOMAIN”, “PROJECT”, “USERNAME”, “PASSWORD”, False
qtApp.Launch
qtApp.Visible = True
qtApp.TDConnection. Connect “URL”, “DOMAIN”, “PROJECT”, “USERNAME”, “PASSWORD”, False
5. Retrieve Data from Excel sheet
Dim FilePath,
Excelone,ExcelSheet,Val
Set FilePath= CreateObject(“srcfilepath”)
Set ExcelSheet = FilePath.GetSheet(sheetid)
Set Val= ExcelSheet.ActiveSheet.Cells(1,1).value
Set FilePath= CreateObject(“srcfilepath”)
Set ExcelSheet = FilePath.GetSheet(sheetid)
Set Val= ExcelSheet.ActiveSheet.Cells(1,1).value
‘Below script for creating an excel sheet with values 1,2,3
Dim Excel,ExcelSheet
Set Excelone=CreateObject(“Excel.Application”)
Set ExcelSheet=CreateObject(“Excel.Sheet”)
ExcelSheet.Application.visible=true
ExcelSheet.ActiveSheet.Cells(1,1).value=1
ExcelSheet.ActiveSheet.Cells(1,2).value=2
ExcelSheet.ActiveSheet.Cells(1,3).value=3
Excelone.Saveas “E:\tests.xls”
Excelone.quit
Set ExcelSheet=Nothing
Dim Excel,ExcelSheet
Set Excelone=CreateObject(“Excel.Application”)
Set ExcelSheet=CreateObject(“Excel.Sheet”)
ExcelSheet.Application.visible=true
ExcelSheet.ActiveSheet.Cells(1,1).value=1
ExcelSheet.ActiveSheet.Cells(1,2).value=2
ExcelSheet.ActiveSheet.Cells(1,3).value=3
Excelone.Saveas “E:\tests.xls”
Excelone.quit
Set ExcelSheet=Nothing
6. Some more stuff related to QTP Script.
Set Word =
CreateObject(“Word.Application”)
oWord.DisplayAlerts = False
oWord.Visible = False
oWord.documents.open “testWordDoc.doc”
Set Doc = oWord.ActiveDocument
Set Range = oDoc.content
oRange.ParagraphFormat.Alignment = 0
oRange.insertafter vbcrlf ‘& ” ” & vbcrlf
oRange.collapse(0)
oRange.InlineShapes.AddPicture “ImagePath.bmp”, False, True
oWord.ActiveDocument.Save
oWord.Application.Quit True
Set Range = Nothing
Set Doc = Nothing
Set Word = Nothing
oWord.DisplayAlerts = False
oWord.Visible = False
oWord.documents.open “testWordDoc.doc”
Set Doc = oWord.ActiveDocument
Set Range = oDoc.content
oRange.ParagraphFormat.Alignment = 0
oRange.insertafter vbcrlf ‘& ” ” & vbcrlf
oRange.collapse(0)
oRange.InlineShapes.AddPicture “ImagePath.bmp”, False, True
oWord.ActiveDocument.Save
oWord.Application.Quit True
Set Range = Nothing
Set Doc = Nothing
Set Word = Nothing
Query Forum
7 Votes
How to capture tool tip in QTP?
E.g.: On Amazon.com,
when you bring the mouse over the ‘A9′ search image (on the top-left side of
the page), it shows ‘A9 search’ as tool-tip. This can be captured using
following code: strToolTip=
Browser(“title:=Amazon.*”).Page(“title:=Amazon.*”).Image(“src:=.*a9search.*”).getROProperty(“alt”)
msgbox strToolTip
msgbox strToolTip
How to Maximising a Browser?
Sub MaxBrowser( ByRef Browser )
hwnd= Browser.GetROProperty(“hWnd”)
Window(“hWnd:=”&hwnd).Maximize
End SubCall MaxBrowser(Browser(“micClass:=Browser”))
hwnd= Browser.GetROProperty(“hWnd”)
Window(“hWnd:=”&hwnd).Maximize
End SubCall MaxBrowser(Browser(“micClass:=Browser”))
How to extract column from webpage ?
Dim colA(),colB()
totalRows = Browser(“<yourBrowser>”).Page(“<yourPage>”).WebTable(“<yourtable>”).RowCount
ReDim colA(totalRows), colB(totalRows)
For x = 1 to totalRows
colA(x) = Browser(“<yourBrowser>”).Page(“<yourPage>”).WebTable(“<yourtable>”).GetCellData(x,<firstcolumn>)
colB(x) = Browser(“<yourBrowser>”).Page(“<yourPage>”).WebTable(“<yourtable>”).GetCellData(x,<secondcolumn>)
Next
totalRows = Browser(“<yourBrowser>”).Page(“<yourPage>”).WebTable(“<yourtable>”).RowCount
ReDim colA(totalRows), colB(totalRows)
For x = 1 to totalRows
colA(x) = Browser(“<yourBrowser>”).Page(“<yourPage>”).WebTable(“<yourtable>”).GetCellData(x,<firstcolumn>)
colB(x) = Browser(“<yourBrowser>”).Page(“<yourPage>”).WebTable(“<yourtable>”).GetCellData(x,<secondcolumn>)
Next
How to Capture Screen shot ?
Sub captureScreenShot ()
strStoreSnapshotMode = Setting(“SnapshotReportMode”)
Setting(“SnapshotReportMode”) = 0
Browser(“name:=.*”).Page(“title:=.*”).Sync
Setting(“SnapshotReportMode”) = strStoreSnapshotMode
End Sub
strStoreSnapshotMode = Setting(“SnapshotReportMode”)
Setting(“SnapshotReportMode”) = 0
Browser(“name:=.*”).Page(“title:=.*”).Sync
Setting(“SnapshotReportMode”) = strStoreSnapshotMode
End Sub
How to Call SQL stored procedure from QTP?
Function RunStoredProcedure(StoredProcedureName)
sDatabaseName=”ABC”
sUID=”xyz”
sPWD=”ABC_xyz” ‘ Create the database object
Set cm = CreateObject(“ADODB.Command”)
sDatabaseName=”ABC”
sUID=”xyz”
sPWD=”ABC_xyz” ‘ Create the database object
Set cm = CreateObject(“ADODB.Command”)
‘ Activate the connection.
cm.ActiveConnection = “DRIVER={Microsoft ODBC for Oracle}; ” &_
“SERVER=” & sDatabaseName & “;User ID=” & sUID & “;Password=” & sPWD & ” ;”
cm.ActiveConnection = “DRIVER={Microsoft ODBC for Oracle}; ” &_
“SERVER=” & sDatabaseName & “;User ID=” & sUID & “;Password=” & sPWD & ” ;”
‘ Set the command type to Stored Procedures
cm.CommandType = 4
cm.CommandType = 4
‘ Stored Procedures
cm.CommandText = StoredProcedureName
cm.CommandText = StoredProcedureName
‘ Define Parameters for the stored procedure
cm.Parameters.Refresh
cm.Parameters.Refresh
‘ Pass input value. Assuming Stored Procedure requires 2
parameters
cm.Parameters(0).Value = “Kuldeep”
cm.Parameters(1).Value = “Kumar”
cm.Parameters(0).Value = “Kuldeep”
cm.Parameters(1).Value = “Kumar”
‘ Execute the stored procedure
cm.Execute()
Set cm = Nothing
End Function
cm.Execute()
Set cm = Nothing
End Function
How to write the test Result (Output) on Excel sheet?
Dim objexcel
Set objexcel= CreateObject(“Excel.sheet”)
objexcel.Visible = True
objexcel.Workbooks.add
With Window(“Calculator”)
.WinButton(“5″).Click
.WinButton(“*”).Click
.WinButton(“3″).Click
.WinButton(“=”).Click
End With
result= Window(“Calculator”).WinEdit(“Edit”).GetROProperty(“text”)
If result=15 Then
objexcel.ActiveSheet.Cells(1,1).Value = “test is pass”
Reporter.ReportEvent micPass,”Calculation”, result
Else
objexcel.ActiveSheet.Cells(1,1).Value = “test is Fail”
Reporter.ReportEvent micFail,”Calculation”, “Expected Result is 15” +”Acutal is “+result
End If
Set objexcel= CreateObject(“Excel.sheet”)
objexcel.Visible = True
objexcel.Workbooks.add
With Window(“Calculator”)
.WinButton(“5″).Click
.WinButton(“*”).Click
.WinButton(“3″).Click
.WinButton(“=”).Click
End With
result= Window(“Calculator”).WinEdit(“Edit”).GetROProperty(“text”)
If result=15 Then
objexcel.ActiveSheet.Cells(1,1).Value = “test is pass”
Reporter.ReportEvent micPass,”Calculation”, result
Else
objexcel.ActiveSheet.Cells(1,1).Value = “test is Fail”
Reporter.ReportEvent micFail,”Calculation”, “Expected Result is 15” +”Acutal is “+result
End If
what is the use of function GetROProperty()?
GetROProperty is
used to retrieve properties listed in Object Spy.
Example: hWnd=Browser(“browser_name”).GetROProperty(“hwnd”)
Window(“hwnd:=” & hWnd).Minimize
Window(“hwnd:=” & hWnd).Minimize
No comments:
Post a Comment