Get TooTip text from Java Table
JavaWindow(“abc”).JavaTable(“xyz”).Object.setColumnSelectionAllowed=False
JavaWindow(“abc”).JavaTable(“xyz”).Object.setRowSelectionAllowed=False
JavaWindow(“abc”).JavaTable(“xyz”).ClickCell”#1″,”#0″
set obj=JavaWindow(“abc”).JavaTable(“xyz”).Object.getCellRect(1,0,True)
JavaWindow(“abc”).JavaTable(“xyz”).FireEvent micMouseMove,0, “BUTTON1_MASK”, obj.x, obj.y, 1, “OFF”
msgbox JavaWindow(“abc”).JavaObject(“toolkit class:=javax\.swing\.JToolTip
“).Object.tipText
Close Opened Browsers Except QC
Dim intIndex
Set oDesc=Description.Create
oDesc(“micclass”).Value=”Browser”
intIndex=0
While Browser(“micclass:=Browser”,”index:=”&intIndex).exist(0) and intIndex<Desktop.ChildObjects(oDesc).count
If instr(1, Browser("micclass:=Browser","index:="&intIndex).getRoProperty("name"),"Quality Center") = 0 Then
SystemUtil.CloseProcessByHwnd( Browser("micclass:=Browser","index:="&intIndex).getRoProperty("hwnd"))
else
intIndex=intIndex+1
End if
wend
How to Download a file using VbScript
Following is the code to download a file using Vbscript, without using QTP
This code uses the HTMLDom and URLDownloadToFile method from urlmon API.
Since VBScript does support calling Native API methods directly, here I am using Excel macro to declare a function for the urlmon API and running the macro by Excel API from VBscript
Step1: Create a new excel and open the visual basic editor, Insert Module and paste the following code the Module, save the excel file
Private Declare Function URLDownloadToFile Lib “urlmon” Alias _
“URLDownloadToFileA” ( _
ByVal pCaller As Long, ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Sub FileSave(strUrl, Des)
r = URLDownloadToFile(0, strUrl, Des, 0, a)
End Sub
Step2: Create a VBS and copy the below code and change the file paths
Set ie = CreateObject(“InternetExplorer.Application”)
ie.navigate “www.google.com”
ie.Visible = True
WScript.Sleep 3000
ie.document.all.q.Value = “Testing + doc”
ie.document.all.btnG.Click
WScript.Sleep 1000
Set obj = ie.document.getElementsByTagName(“A”)
For i = 0 To obj.Length
If obj(i).innerText = “Testing Document” Then
hr = obj(i).href
Exit For
End If
Next
arrhr = Split(hr, “/”)
fname = arrhr(UBound(arrhr))
If hr <> “” Then
strUrl = hr
Des = “C:\Documents and Settings\Desktop\” & fname
Set objXL = CreateObject(“Excel.Application”)
With objXL.Application
.Visible = False
‘Open the Workbook
.Workbooks.Open “C:\Documents and Settings\Desktop\Download.xls”
‘Include CARMA in menu, run AutoOpen
objXL.Application.DisplayAlerts = False
x = .Run(“FileSave”, strUrl, Des)
End With
Set objXL = Nothing
MsgBox “Download Completed , the location of the saved file is->” & Des
End If
Set ie = Nothing
‘Special Thanks to Chandan Ray
How To open Password Protected Excel sheets
Function UnprotectXL(filePath,fileName,pwd,writeresPwd)
Set objExcel=CreateObject(“Excel.Application”)
objExcel.Visible=false
testData=filePath&”\”&fileName
Set oWorkbook=objExcel.Workbooks
Set myWkbook=objExcel.Workbooks.open (testData,0,False,5,pwd,writeresPwd)
objExcel.DisplayAlerts=False
oWorkbook(fileName).Activate
For Each w in objExcel.Workbooks
w.SaveAs testData,,””,””
Next
objExcel.Workbooks.Close
objExcel.Quit
Set oWorkbook=Nothing
Set objExcel=Nothing
End Function
Function ProtectXL(filePath,fileName,pwd,writeresPwd)
On Error Resume Next
Set objExcel=CreateObject(“Excel.Application”)
objExcel.Visible=False
testData=filePath&”\”&fileName
Set oWorkbook=objExcel.Workbooks
Set outputWkbook=objExcel.Workbooks.open (testData,0,False)
oWorkbook(testData).Activate
objExcel.DisplayAlerts=False
outputWkbook.SaveAs testData,,pwd,writeresPwd
outputWkbook.Close
objExcel.Workbooks.Close
objExcel.Quit
Set outputWkbook=Nothing
Set objExcel=Nothing
End Function
‘Call ProtectXL(“C:\Documents and Settings\kmohankumar\Desktop”,”4.xls”,”test123″,”test123″)
‘Call UnprotectXL(“C:\Documents and Settings\kmohankumar\Desktop”,”4.xls”,”test123″,”test123″)
Author: Mohan Kakarla
Merge 2 XML using Dotnet Factory
Dim objReader1,objReader2,objds1,objds2
Set objReader1 = DotNetFactory.CreateInstance(“System.Xml.XmlTextReader”, “System.Xml”,”C:\Documents and Settings\kmohankumar\Desktop\11.xml”)’ Creates the instance for the XMLWriter
Set objReader2 = DotNetFactory.CreateInstance(“System.Xml.XmlTextReader”, “System.Xml”,”C:\Documents and Settings\kmohankumar\Desktop\12.xml”)’
Set objds1 = DotNetFactory.CreateInstance(“System.Data.DataSet”, “System.Data”)
Set objds2 = DotNetFactory.CreateInstance(“System.Data.DataSet”, “System.Data”)
objds1.ReadXml(objReader1)
objds2.ReadXml(objReader2)
objds1.Merge(objds2)
objds1.WriteXml(“C:\Documents and Settings\kmohankumar\Desktop\13.xml”)
objReader1.close
objReader2.close
Set objReader1=Nothing
Set objReader2=Nothing
Set objds1=nothing
Set objds2=nothing
Author:Mohan Kakarla
Create XML using Dotnet Factory
Dim objWriter,XmlWriter
Set objWriter = DotNetFactory.CreateInstance(“System.Xml.XmlWriter”, “System.Xml”)’ Creates the instance for the XMLWriter
set XmlWriter=objWriter.Create(“C:\Documents and Settings\kmohankumar\Desktop\1234.xml”)’ creates xml document
XmlWriter.WriteStartElement(“Books”)’ start writing the element
XmlWriter.WriteStartElement(“Author”)
XmlWriter.WriteAttributeString “Name”, “Mohan”‘ writes attributes and its values to the element
XmlWriter.WriteEndElement()’ ends writing the element
XmlWriter.WriteStartElement(“Title”)
XmlWriter.WriteAttributeString “Title1”, “QTP”‘
XmlWriter.WriteEndElement()
XmlWriter.WriteFullEndElement()
XmlWriter.close()
Set objWriter =Nothing
Author:Mohan kakarla
Read XML using Dotnet Factory
Set objReader = DotNetFactory.CreateInstance(“System.Xml.XmlReader”, “System.Xml”)
set XmlReader=objReader.Create(“C:\Documents and Settings\kmohankumar\Desktop\3.xml”)
while (XmlReader.Read())
If XmlReader.NodeType = “XmlDeclaration” or XmlReader.NodeType = “Element”Then
Reporter.ReportEvent micPass, “NodeType:”&XmlReader.NodeType &” Name :”& XmlReader.Name& ” is at Depth:”& XmlReader.Depth,””
If XmlReader.HasValue Then
Reporter.ReportEvent micPass, ” Value: “& XmlReader.Value,””
End If
Reporter.ReportEvent micPass, “Element:”& XmlReader.Name&” has attribute(s)”&”:”& XmlReader.AttributeCount,””
If XmlReader.AttributeCount > 0 Then
while XmlReader.MoveToNextAttribute()
fn = XmlReader.Name
ns = XmlReader.NamespaceURI
Reporter.ReportEvent micPass,” Attribute:”&fn &” Value: “& ns&” Attribute:”& XmlReader.GetAttribute(fn, ns),””
wend
End If
End If
wend
XmlReader.Close()
Author: Mohan Kakarla
Search for a particular value in Excel
Set appExcel = CreateObject(“Excel.Application”)
appExcel.visible=true
Set objWorkBook = appExcel.Workbooks.Open (filepath)’opens the sheet
Set objSheet = appExcel.Sheets(“Sheet1”)’ To select particular sheet
With objSheet.UsedRange ‘ select the used range in particular sheet
Set c = .Find (“nn”)’ data to find
For each c in objSheet.UsedRange’ Loop through the used range
If c=”nn” then’ compare with the expected data
c.Interior.ColorIndex = 40′ make the gary color if it finds the data
End If
Set c = .FindNext(c)’ next search
next
End With
objWorkBook.save
objWorkBook.close
set appExcel=nothing
Author:Mohan Kakarla
Upload Attachments To QC
Function UpLoadAttachmentToQC(FilePath)
Set ObjCurrentTest = QCUtil.CurrentTest.Attachments
Set ObjAttch = ObjCurrentTest.AddItem(Null)
ObjAttch.FileName = FilePath
ObjAttch.Type = 1
ObjAttch.Post
ObjAttch.Refresh
End Function
FilePath=”C:\abc.vbs”
Call UpLoadAttachmentToQC(FilePath)
Author: Mohan Kakarla
Source: QC-OTA
-
Archives
- July 2011 (1)
- March 2011 (1)
- November 2010 (1)
- November 2008 (4)
- October 2008 (2)
- September 2008 (2)
- June 2008 (1)
- March 2008 (4)
- February 2008 (44)
-
Categories
- Automated Test Script Creation Process
- Automating MS Word
- Automating QC
- Automation Object Model For QTP
- Backward compatability in QTP
- Browser Scripts
- COM and QTP
- compare 2 text files
- Descriptive programming
- Descriptive Programming and Child Objetcs
- Dictonary Object
- DotNetFactory
- Excel Automation
- Extra Topics
- Files and Folders
- General Standards to be followed in Test scripts
- New Features In QTP9.5
- QC-OTA
- QTP Additional Faqs
- QTP Faqs
- QTP Naming Convention
- QTP Tips and Faqs
- Running stored procedures from QTP
- Send keyboard keys
- Uncategorized
- Uninstall a software using QTP
- Uninstall a software using vbscript
- Update data in a database
- VBScript and IE Automation
- VBScript Faqs and Useful resources
- What’s New in Quick Test Pro 9.0
- Whats New in QTP 9.5
- XML Scripting
-
RSS
Entries RSS
Comments RSS