Saturday, December 29, 2012

How to schedule a batch execution

In this video, i covered following concepts:

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

    set Outlook=nothing
end function

How to schedule a QTP Test

In this video i explained about how to schedule a QTP Test.

Covered an overview of AOM(Automation Object Model).
How to schedule a task in Win XP and Win 7 machine.



Here is the AOM Code for launching QTP and running a QTP Test.

sFilePath="E:\Test1"
Set qtApp = CreateObject("QuickTest.Application") 'creates an instance of QTP Object

qtApp.Launch ' Launches QTP
qtApp.Visible = True 'Making QTP Visible during execution

qtApp.open sFilePath, True 'Opens the QTP Test

set qtTest=qtApp.Test

qtTest.Run   'Runs the QTP Test

WScript.sleep 10000

qtTest.close 'Closes the QTP Test
qtApp.quit  'Closes QTP

set qtTest=nothing
set qtApp=nothing

Saturday, December 15, 2012

How to work with Excel using QTP

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)

print xlWSObj.cells(2,1).value
'
xlWSObj.cells(3,2).value="IJK"

Set Cell=xlWSObj.range("A:Z").find("XYZ")
print Cell.Address



Set xlWSLastSheetObj=xlWBObj.worksheets( xlWBObj.Sheets.count)
xlWBObj.worksheets.add(,xlWSLastSheetObj).name="TestSheet3"


xlWSObj.cells(2,1).Font.Color=vbRed
xlWSObj.cells(2,1).Font.Name="Verdana"
xlWSObj.cells(2,2).Interior.Color=vbBlue

xlWSObj.range("A2").select
xlWSObj.range("A2:B2").select
xlObj.selection.copy
xlWSObj.range("E5").select
xlWSObj.paste

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

xlWBObj.SaveAs o_FileName2
xlWBObj.close
xlObj.application.quit

Set xlWBObj=nothing
Set xlObj=nothing

Thursday, December 6, 2012

How to retrieve content from XML using MS XML DOM

Here in this video i demonstrated how to retrieve XML content using MS XML DOM.

The sample code for above demonstration:

Dim o_XML
Dim s_XMLFilePath

s_XMLFilePath="E:\Programming Samples\QTP Samples\Cars.xml"

'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>

Wednesday, December 5, 2012

How to compare two XML files using QTP

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.CreateXML()
'o_XML1.loadfile(s_FilePath1)
'
'Set o_XML2=XMLUtil.CreateXML()
'o_XML2.loadfile(s_FilePath2)

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

Set o_XML1=nothing
Set o_XML2=nothing

XMLUtil - Part 2

I request people watch XMLUtil - Part 1, before watching this video.

http://qtpftvideos.blogspot.in/2012/12/how-to-work-with-xml-files-part-1.html

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

s_XMLFilePath="E:\Programming Samples\QTP Samples\Cars.xml"
s_UpdatedXMLFilePath="E:\Programming Samples\QTP Samples\Cars2.xml"

'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

Set o_ChildPath=nothing
Set o_XML=nothing

Monday, December 3, 2012

How to work with XML Files - Part 1

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

s_XMLFilePath="E:\Programming Samples\QTP Samples\Cars.xml"
s_UpdatedXMLFilePath="E:\Programming Samples\QTP Samples\Cars2.xml"

'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>

Sunday, December 2, 2012

How Smart Identification is used in QTP

The below video explains about how QTP identifies the Smart Identification mechanism to identify and object.


Thursday, November 29, 2012

QTP Object Identification - Part 2

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.


Sunday, November 4, 2012

QTP Object Identification - An Example

In this video i am demonstrating how as humans we identify any object, because QTP follows the same approach to identify any object in AUT.

Once you understand this example it is easy to understand how QTP identifies the objects.


Saturday, November 3, 2012

How to work with Datatables - Part 2

In this video i will demonstrate the following two concepts:

1. Run configuration - Run on all rows.
2. How to parametrize values using Data - Driver.

How to work with Datatables - Part1

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")