One Testing Center

QTP - Keyword Driven Framework. QTP Learning Book - Learn By Questions. QTP Learning Book - Made Easy - Part1. QTP Learning Book - Made Easy - Part2. QTP Quality Center - QC.

QTP - Frameworks

QTP - Frameworks. Record and Play back Framework. Action Driven Framework. Data Driven Framework. Functional Decomposition Framework. Keyword Driven Framework. Hybrid Framework. Test Driven Framework.

QTP - Automation

QTP - Basics. QTP - Intermediate. QTP - Advanced. QTP - Frameworks.

QTP - Training

Friends, Welcome to OneTestingCenter. I am HP Functional Test ExportOne. I am HP Automation Functional Test Certified Professional. I am certified for HP Functional Test 11.x. Happy to share my knowledge.

QTP - Books

QTP - Keyword Driven Framework. QTP Learning Book - Learn By Questions. QTP Learning Book - Made Easy - Part1. QTP Learning Book - Made Easy - Part2. QTP Quality Center.

Recent Post

QTP - Files - Files Comparison

QTP - Files - Files Comparison


'************************************************************************
' GAReddy @ OneTestingCenter @ QTP @ Files Comparison
'************************************************************************
FilePath="D:\TestData\"
MyFile1="OnlineScriptLog.txt"
MyFile2="OnlineScriptLog1.txt"
ResultFile="D:\TestData\ResultFile.txt"

Call CompareFiles(FilePath, MyFile1, MyFile2)

Public Function CompareFiles(FilePath, MyFile1, MyFile2)

Const ForReading = 1
Const ForWriting = 2
Const BinaryCompare = 0

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set File1 = oFSO.OpenTextFile(FilePath & MyFile1, ForReading)
Set File2 = oFSO.OpenTextFile(FilePath & MyFile2, ForReading)

Set DiffFile=oFSO.CreateTextFile(ResultFile)
' *************************************************
' ****** To Count the number of lines in File1 ***********
'*************************************************
                                i=0
                                While File1.AtEndOfStream <> True
                                Line1 = File1.ReadLine
                                i=i+1
                                Wend

' *************************************************
' ****** To Count the number of lines in File2 ***********
'*************************************************
                                j=0
                                While File2.AtEndOfStream <> True
                                ln2 = File2.ReadLine
                                j=j+1
                                Wend

' *************************************************
' To Check if  number of lines in File1 and File 2 are equal
'*************************************************
                                If i<>j Then
                                                 Reporter.ReportEvent 1, "Line Count ", "Line Count is not equal."
                                 else
                                 Reporter.ReportEvent 0, "Line Count ", "Line Count is equal."
                                End If
                                File1.Close
                                File2.Close

' *************************************************
' To Read text from both files to compare
'*************************************************
                Set File1 = oFSO.OpenTextFile(FilePath&MyFile1, ForReading)
                Set File2 = oFSO.OpenTextFile(FilePath&MyFile2, ForReading)
               
                Do While ((File1.AtEndOfStream <> True) AND (File2.AtEndOfStream <> True))
'               Do While ((File1.AtEndOfStream <> True))
                File1Line=File1.Line
                File2Line=File2.Line
                File1ReadLine = File1.ReadLine
                File2ReadLine = File2.ReadLine
               
                Comp = StrComp( CStr(File1ReadLine),CStr( File2ReadLine), BinaryCompare)
                ' *************************************************
                ' To wrtie the comparison results on DiffFile
                '*************************************************
                If (Comp <> 0) then
                 DiffFile.WriteLine   "Contents are different" &vbtab& File1Line &vbtab&  CStr(File1ReadLine) &"***"& File2Line &vbtab&  CStr(File2ReadLine)
                 Else
                 DiffFile.WriteLine  "Contents are same" &vbtab & File1Line &vbtab& CStr(File1ReadLine)
                End if
                Loop
               
                File1.Close
                File2.Close
                DiffFile.Close
               
                End Function

'************************************************************************



QTP - Excel - Excel Comparison

QTP - Excel - Excel Comparison
How to compare two excel sheets (Expected and Actual Sheets)


'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
' GAReddy @ OneTestingCenter @ QTP @ Excel Comparison                   
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

ExcelFilePath="D:\GAReddy\OneTestingCenter\QTP\TestData\"
ExpectedExcelBook=" D:\GAReddy\OneTestingCenter\QTP\TestData\QACompleteLearningReferense@AllOne.xls"
ActualExcelBook=" D:\GAReddy\OneTestingCenter\QTP\TestData\QACompleteLearningReferense@AllOne1.xls"
DifferenseSheet="MyExcelSheet.xls"
ActualSheet="Automation Testing"
ExpectedSheet="Automation Testing"

Call ExcelCompare(ExcelFilePath,ExpectedExcelBook,ActualExcelBook,DifferenseSheet,ActualSheet,ExpectedSheet)

Function ExcelCompare(ExcelFilePath,ExpectedExcelBook,ActualExcelBook,DifferenseSheet,ActualSheet,ExpectedSheet)

                                Set oExcel=Createobject("Excel.Application")
                                Set oExpExcel=Createobject("Excel.Application")
                                Set oActExcel=Createobject("Excel.Application")

                                Set NewSheet = oExcel.Application.Workbooks.Add
                                Set MySheet=oExcel.Application.Activeworkbook.Worksheets("sheet1")
                                               
                                oActExcel.Workbooks.Open ActualExcelBook,2
                                oExpExcel.Workbooks.Open ExpectedExcelBook,2

                Set oExpSheet=oExpExcel.Application.Activeworkbook.Worksheets(ExpectedSheet)
                Set oActSheet=oActExcel.Application.Activeworkbook.Worksheets(ActualSheet)
                                                               
                                RowsCount =  oExpSheet.UsedRange.Rows.count
                                ColsCount =           oExpSheet.UsedRange.Columns.count
                                RowsCount1=  oActSheet.UsedRange.Rows.count
                                ColsCount1=         oActSheet.UsedRange.Columns.count

                                For i=1 to RowsCount
                                                For j=1 to ColsCount
                                                 If  Trim(oExpSheet.Cells(i,j))<>Trim(oActSheet.Cells(i,j))Then
                                MySheet.Cells(i,j)=oExpSheet.cells(i,j) &"***"& vbtab & oActSheet.cells(i,j)
                                                                MySheet.Cells(i,j).Interior.Colorindex=34
                                                                else
                                                                MySheet.Cells(i,j)=oExpSheet.Cells(i,j)
                                                                End If
                                                Next
                                Next
                                MySheet.SaveAs ExcelFilePath&DifferenseSheet

                                oExcel.Quit
                                oExpExcel.Quit
                                oActExcel.Quit
                                Set oExcel=Nothing
                                Set oExpExcel=Nothing
                                Set oActExcel=Nothing

End Function


GAReddy @ OneTestingCenter @ All Articles