In this video, i demonstrated about how to work with Dictionary object:
Here is the code i used for demonstration:
Set dictObj=Createobject("Scripting.Dictionary")
dictObj.Add "Name","Uday" dictObj.Add "Age",32 dictObj.Add "Loc","India" dictObj.Add "Height",5.10 dictObj.Add 1,"10" 'Observe here i am passing key as a integer
print dictObj.Count 'Count is dictionary property which retrieves number of items in the collection
print dictObj.Item("Name") 'Item property retrieves or sets the value of the key. dictObj.Item("Name")="Udaya Kumar Anem" print dictObj.Item("Name")
dictObj.Key("Loc")="Location" 'We can use key property to update the key value print dictObj.Item("Location")
aKeys=dictObj.Keys 'This method returns all the keys in the collection as an array For i=0 to ubound(aKeys) print aKeys(i) Next
For i=1 to dictObj.Count print dictObj.Item(aKeys(i-1)) 'This method retrieves the value of the key Next
aValues=dictObj.Items 'This method returns all the Values in the collection as an array For i=0 to ubound(aValues) print aValues(i) Next
dictObj.Remove(1) 'This method removes the key value pair from the collection
If dictObj.Exists(1) Then 'This method looks for the existance for a Key print "Key exists" else print "Key does not exist" End If
dictObj.RemoveAll 'This method removes all key value pairs from the collection i.e clearing the dictionary
How to execute batch of QTP Tests.
How to capture QTP Execution status.
How to send the execution status as a Outlook Mail.
Following is the AOM script for the above functionality:
Set qtpApp = CreateObject("QuickTest.Application") Set fsObj = CreateObject("Scripting.FileSystemObject") Set qtpResObj = CreateObject("QuickTest.RunResultsOptions")
sFolderPath="E:\Batch Tests"
qtpApp.Launch qtpApp.Visible = True
Set mainFolderObj = fsObj.GetFolder(sFolderPath) Set testSubFolders = mainFolderObj.SubFolders
sPath="E:\"&formatDate&"\"
For each folderObj in testSubFolders
chkfolderObj = folderObj.Path & "\Action0"
If (fsObj.FolderExists(chkfolderObj)) Then ' The folder is a QTP test folder
qtpApp.Open folderObj.Path, True, False
sResultFolderPath=sPath&folderObj.Name & "\Res" ' Set the results location
qtpResObj.ResultsLocation = sResultFolderPath
qtpApp.Test.Run qtpResObj, True
strResult=qtpApp.Test.LastRunResults.Status
'WScript.echo strResult
qtpApp.Test.Close
End If Next
'SendMail()
qtpApp.Quit
' Release the File System Objects Set testSubFolders = Nothing Set mainFolderObj = Nothing Set fsObj = Nothing set qtpResObj=nothing set qtpApp=nothing
Function formatDate() str=now() str=replace(str,"/","") str=replace(str,":","") str=replace(str," ","") formatDate= mid(str,1,len(str)-2) End Function
function SendMail() Set Outlook = CreateObject("Outlook.Application") Set Message = Outlook.CreateItem(olMailItem) With Message .Subject = "Test results for Date "&sPath .HTMLBody = "This is an automated mail for Test Results" .Recipients.Add ("udayanem@gmail.com") .attachments.add sFilePath .Send End With
Here in this video i demonstrated how to work with Excel files using QTP.
Following are the concepts are covered in this video:
•How to get a cell value
•How to set a cell value
•How to find a string
•How to add an Excel sheet
•How to set a font color
•How to set a interior color for a cell
•How to copy paste cell values
•How to insert an image
Following is the QTP Script for above functions:
o_FileName1="C:\Test1.xls" o_FileName2="C:\Test2.xls" Set xlObj=createobject("Excel.Application") Set xlWBObj=xlObj.workbooks.open(o_FileName1) Set xlWSObj=xlWBObj.worksheets(1)
xlWSObj.cells(6,"B").select Set x=xlWSObj.pictures.insert("C:\174.JPG") Set objRange=xlWSObj.range("B6:C13") With x .Top=objRange.Top .Left=objRange.Left .Width=objRange.Width .Height=objRange.Height End With
'Set o_XML=createobject("Microsoft.XMLDOM") 'DOM object of XML Parser.
' ' You can search the XML Parser ("Msxml.dll") in your system.
'o_XML.Async=false ' if it is false, then the file must be download first and the control goes back to the caller
' 'if it is true, then the control goes back to the caller before the file download
'o_XML.load(s_XMLFilePath) 'This method loads the XML File
'
'set o_ChildPath=o_XML.SelectNodes("/Cars/Make/Model/Name/text()")
'For i=0 to o_ChildPath.length-1
' print o_ChildPath(i).NodeValue
'Next
Set o_XML=XMLUtil.CreateXMLFromFile(s_XMLFilePath)
set o_ChildPath=o_XML.ChildElementsByPath("/Cars/Make/Model/Name")
For i=1 to o_ChildPath.Count
print o_ChildPath.Item(i).Value
Next
Set o_ChildPath=nothing
The content of the XML File as follows:
<Cars>
<Make name="Maruthi">
<Model>
<Name>Alto</Name>
<Release>2000</Release>
</Model>
</Make>
<Make name="Hundai">
<Model>
<Name>i10</Name>
<Release>2003</Release>
</Model>
</Make>
<Make name="Maruthi">
<Model>
<Name>Wagnor</Name>
<Release>2005</Release>
</Model>
</Make>
</Cars>
There are many ways you can compare two XML Files.
Here in this i demonstrated using XMLUtil.
'*************************************************************************************************************************************************************************************** 'Objective : Compare two XML Files 'Functionality : The below script compares two XML Files ' s_FilePath1, s_FilePath1 These two variables holds the XML Files respctively ' s_DiffFilePath will holds the difference between these two XML Files 'Author : Udaya Anem 'Scripted on : 4th Sept 'Updated by : '***************************************************************************************************************************************************************************************
Dim s_FilePath1,s_FilePath2 Dim o_XML1,o_XML2,o_XMLDiff Dim s_DiffFilePath Dim b_RetVal
s_FilePath1="E:\Programming Samples\QTP Samples\Cars.xml" 'This is XML File Path 1 s_FilePath2="E:\Programming Samples\QTP Samples\Cars1.xml" 'This is XML File Path 2 s_DiffFilePath= "E:\Diff.xml"
Set o_XML1=XMLUtil.CreateXMLFromFile(s_FilePath1) Set o_XML2=XMLUtil.CreateXMLFromFile(s_FilePath2)
'The Compare method from XMLData compares XML Files b_RetVal=o_XML1.Compare(o_XML2,o_XMLDiff)
If b_RetVal=1 Then reporter.ReportEvent micPass,"XML Comparison","XML Comparison is Successful" else reporter.ReportEvent micFail,"XML Comparison","XML Comparison is Failed" s_DiffFilePath=Environment("TestDir")&"\XML Diff File.xml" o_XMLDiff.savefile s_DiffFilePath End If
In this video i demonstrated more about how to update an XML File.
How to update XML Elements.
How to add XML attributes to an XML Element.
How to update XML attribute values.
How to add child and sub-child elements.
'***************************************************************************************************************************************************************************************
'Objective : Cover basic XML Operations
'Functionality : The below script covers the updating off XML Files
'
'Author : Udaya Anem
'Scripted on : 4th Dec
'Updated by :
'***************************************************************************************************************************************************************************************
Dim o_XML
Dim s_XMLFilePath
'Set o_XML=XMLUtil.CreateXMLFromFile(s_XMLFilePath)
Set o_XML=XMLUtil.CreateXMLFromFile(s_XMLFilePath)
'The below steps update specified XML Element value
Set o_ChildPath=o_XML.ChildElementsByPath("/Cars/Make/Model/Name")
print o_ChildPath.Item(1).Value
o_ChildPath.Item(1).SetValue("Swift")
o_XML.SaveFile s_UpdatedXMLFilePath
print o_ChildPath.Item(1).Value
'The below script adds an attribute to the XML Element
Set o_ChildPath=o_XML.ChildElementsByPath("/Cars/Make/Model/Name")
o_ChildPath.Item(1).AddAttribute "Version","Petrol"
o_XML.SaveFile s_UpdatedXMLFilePath
''
''
set o_XMLAttributes=o_ChildPath.Item(1).Attributes
print o_XMLAttributes.Item(1).Value
'to update an attribute also we have to use AddAttribute
o_ChildPath.Item(1).AddAttribute "Version","Diesel"
o_XML.SaveFile s_UpdatedXMLFilePath
set o_RootElement=o_XML.GetRootElement
o_RootElement.AddChildElementByName "Make",""
Set o_ChildPath=o_XML.ChildElementsByPath("/Cars/Make")
o_ChildPath.Item(o_ChildPath.Count).AddAttribute "name","Audi"
o_ChildPath.Item(o_ChildPath.Count).AddChildElementByName "Model",""
Set o_ChildPat=o_XML.ChildElementsByPath("/Cars/Make/Model")
o_ChildPat.Item(o_ChildPat.Count).AddChildElementByName "Name","A4"
o_ChildPat.Item(o_ChildPat.Count).AddChildElementByName "Release","2002"
o_XML.SaveFile s_UpdatedXMLFilePath
Here in this video i demonstrated how to traverse an XML file using "XMLUtil" utility object.
Following is the code i used in the above examples:
'*************************************************************************************************************************************************************************************** 'Objective : Cover basic XML Operations 'Functionality : The below script covers the updating off XML Files ' 'Author : Udaya Anem 'Scripted on : 18th Sept 'Updated by : '*************************************************************************************************************************************************************************************** Dim o_XML Dim s_XMLFilePath
'Set o_XML=XMLUtil.CreateXMLFromFile(s_XMLFilePath) Set o_XML=XMLUtil.CreateXMLFromFile(s_XMLFilePath)
'The below steps update specified XML Element value 'Set o_ChildPath=o_XML.ChildElementsByPath("/Cars/Make/Model/Name") 'print o_ChildPath.Item(1).Value 'o_ChildPath.Item(1).SetValue("Alto") 'o_XML.SaveFile s_UpdatedXMLFilePath 'print o_ChildPath.Item(1).Value
'The below script adds an attribute to the XML Element Set o_ChildPath=o_XML.ChildElementsByPath("/Cars/Make/Model/Name") o_ChildPath.Item(1).AddAttribute "Version","Petrol" o_XML.SaveFile s_UpdatedXMLFilePath ' ' 'set o_XMLAttributes=o_ChildPath.Item(1).Attributes 'print o_XMLAttributes.Item(1).Value
'to update an attribute also we have to use AddAttribute o_ChildPath.Item(1).AddAttribute "Version","Diesel" o_XML.SaveFile s_UpdatedXMLFilePath
Set o_ChildPath=nothing Set o_XML=nothing
Following is the sample XML File:
<Cars> <Make name="Maruthi"> <Model> <Name>Wagnor</Name> <Release>2000</Release> </Model> </Make> <Make name="Hundai"> <Model> <Name>i10</Name> <Release>2003</Release> </Model> </Make> <Make name="Maruthi"> <Model> <Name>Swift</Name> <Release>2005</Release> </Model> </Make> </Cars>
In this video i explained about
1. how QTP identifies object while learning and running
2. where we can configure the property values
3. General points to remember while working with QTP Object Identification.
In this video i will demonstrate how to work with Datatables.
Following topics are covered:
How to retrieve a cell value from a Data Table.
How to set a value into a Data Table.
How to import data from an Excel file.
How to export data to an Excel File.
How we can use Excel formulas in Data Table.
What are the general guidelines and few other concepts.
Here is the sample code used in the above video:
'The statement is mandatory to set/get any value, because setCurrentRow is not associated with any row we use GetSheet to make sure that we are pointing to the the right sheet.
Datatable.GetSheet(1)
'GetCurrentRow retrieves the number of rows existing in the Data Table. RowCount=Datatable.GetRowCount For i=1 to RowCount
'setCurrentRow points to the row in a Datatable before we get/set value. Datatable.SetCurrentRow(i)
'Value method is used to get/set value where first parameter is "ColumnName/ColumnId" and the second parameter is "SheetId/SheetName/dtGlobalSheet" ip1=Datatable.Value(1,1) ip2=Datatable.Value(2,1) Datatable.Value(3,1)=cint(ip1)+cint(ip2) Next
'Export method exports the data in Excel sheet to the Excel file specified. Datatable.Export("E:\TempData.xls")