Thursday 15 May, 2008

Comparing two Excel Files

1.
Create 2 excel file test and test1 and 1 columns FirstSheetColumn. It checks first columns data only.

TrueOrFalse = "Same"
DataTable.Import("C:\test.xls")
FirstTableCount = DataTable.GetRowCount
DataTable.Import("C:\test1.xls")
SecondTableCount = DataTable.GetRowCount

if (FirstTableCount <> SecondTableCount) then
msgbox "Both files are not Equal"
else
For I = 1 To FirstTableCount
DataTable.Import("C:\test.xls")
Datatable.SetCurrentRow(I)
value1 = DataTable.Value("FirstSheetColumn")
DataTable.Import("C:\test1.xls")
Datatable.SetCurrentRow(I)
value2 = DataTable.Value("SecondSheetColumn")
if(value1 <> value2) then
TrueOrFalse = "Different"
Exit For
end if
Next
end if
msgbox(TrueOrFalse)

Set ExpObjectExcelApp = CreateObject("Excel.Application")
ExpObjectExcelApp.Workbooks.open ("C:/Test1.xls")
ExpSheet = "Sheet1"

2.
Set ActObjectExcelApp = CreateObject("Excel.Application")
ActObjectExcelApp.Workbooks.open ("C:/Test2.xls")
ActSheet = "Sheet1"

Set ExpectedDataSheet = ExpObjectExcelApp.Worksheets(1).UsedRange
Set ActualDataSheet = ActObjectExcelApp.Worksheets(1).UsedRange

ExpObjectExcelApp.Worksheets(1).UsedRange.Font.Color = vbBlack
ActObjectExcelApp.Worksheets(1).UsedRange.Font.Color = vbBlack

For Each Cell In ExpectedDataSheet.Cells
RowIndex = Cell.Row
ColumnIndex = Cell.Column
If Cell.Value <> ActualDataSheet.Cells(RowIndex, ColumnIndex).Value Then
Cell.Font.Color = vbRed
ActualDataSheet.Cells(RowIndex, ColumnIndex).Font.Color = vbRed
Reporter.ReportEvent micFail,"miss match", "row = " & RowIndex &" Column = "& ColumnIndex
Else
Cell.Font.Color = vbGreen
ActualDataSheet.Cells(RowIndex, ColumnIndex).Font.Color = vbGreen
End If
Next

ExpObjectExcelApp.ActiveWorkbook.Save
ActObjectExcelApp.ActiveWorkbook.Save

ExpObjectExcelApp.Quit
ActObjectExcelApp.Quit

Connecting Excel and Checking values

Filename = "c:\sample.xls"
MyWorkSheet = "[Sheet1$]" 'special syntax, sheet name is test

ActiveCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
ActiveCon = ActiveCon & Filename
ActiveCon = ActiveCon & ";Extended Properties=""Excel 8.0;HDR=NO;IMEX=1;"""

set rsExcel = CreateObject("ADODB.Recordset")
rsExcel.LockType = 1
rsExcel.ActiveConnection = ActiveCon

rsExcel.Open "Select * from " & MyWorkSheet

msg = ""

for j = 0 to rsExcel.fields.count -1
msg = msg & rsExcel.fields(j).name & " "
next

msg = msg & vbcrlf
msg = msg & vbcrlf

do while not rsExcel.eof
for j = 0 to rsExcel.fields.count -1
msg = msg & rsExcel.fields(j) & " "
next
msg = msg & vbcrlf
rsExcel.movenext
loop
rsExcel.close
msgbox msg

Saturday 2 June, 2007

Getting Test Name from QC

Hi Friends,

Below post is useful to get test name from quality center.

Set td=createobject("TDApiOle80.TDConnection.1")
td.InitConnectionEx "http://qc/qcbin"
td.ConnectProjectEx "DOMAIN", "PROJECT","USERNAME", "PASSWORD"
Set tstMgr = td.TreeManager
Set tsttr = tstMgr.NodeByPath("subject\functionality\SUB FOLDER NAME")
Set tsetFact = tsttr.TestFactory
Set tsetList = tsetFact.NewList("")
For Each tset in tsetList
Msgbox ("Test Name = " & tset.Name)
Next

Monday 28 May, 2007

Computer Resolution

This function is used to get computer resolution

Public Function get_res()
Set progman = Description.Create
progman("Object Class").Value = "Progman"
progman("Text").Value = "Program Manager"
get_res = Window(progman).GetROProperty ("width") & "*" & Window(progman). GetROProperty ("height")
Msgbox ""&get_res
End Function

Thanks,
Jitesh Sojitra.

Mercury Timers

Hi Friends,

Using below method you can use timer method in QTP9.2,

StartTime = MercuryTimers("Timer").Start / 1000
' Operation 1
' Operation 2
EndTime = MercuryTimers("Timer").Stop() / 1000
TotalTime = EndTime - StartTime
Msgbox ""&TotalTime

Regards,
Jitesh Sojitra.

Sunday 27 May, 2007

Connecting QC with QTP using scripting

Hi Friends,

Using below method you can connect QC with QTP,

Set qtApp = CreateObject("QuickTest.Application")
qtApp.Launch
qtApp.Visible = True
qtApp.TDConnection. Connect "URL", "DOMAIN", "PROJECT", "USERNAME", "PASSWORD", False

Regards,
Jitesh Sojitra.

SendKeys Method in QTP

Hi Friends,

Use Sendkeys method using below help,

Reference - http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/4b032417-ebda-4d30-88a4-2b56c24affdd.asp
set WshShell = CreateObject("WScript.Shell")
WshShell.AppActivate "Brand Names"wait 2
WshShell.SendKeys "NUM"

Thanks,
Jitesh Sojitra.