Qtp excel sheet methods
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Qtp excel sheet methods

on

  • 6,669 views

 

Statistics

Views

Total Views
6,669
Views on SlideShare
6,669
Embed Views
0

Actions

Likes
1
Downloads
191
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Qtp excel sheet methods Document Transcript

  • 1. For more QTP Scripts, www.ramupalanki.com Visit: www.ramupalanki.com for QTP Info Excel File Operations1) Create an Excel file, enter some data and save the file through VBscripting?1) Dim objexcel2) Set objExcel = createobject("Excel.application")3) objexcel.Visible = True4) objexcel.Workbooks.add5) objexcel.Cells(1, 1).Value = "Testing"6) objexcel.ActiveWorkbook.SaveAs("f:exceltest.xls")7) objexcel.Quit2) Data Driven Testing through an External Excel Sheet1) Set myExcel=Createobject("Excel.Application")2) Set myFile=myExcel.workbooks.open ("C:Documents and SettingsadminMyDocumentssdfsfsd.xls")3) Set mySheet=myFile.worksheets("Sheet1")4) Rows_Count=mySheet.usedrange.rows.count5) For i= 1 to Rows_Count6) Agent=mySheet.cells(i,"A") QTP Training 1
  • 2. For more QTP Scripts, www.ramupalanki.com7) pwd=mySheet.Cells(i,"B")8) SystemUtil.Run "C:Program FilesMercury InteractiveQuickTestProfessionalsamplesflightappflight4a.exe","","C:Program FilesMercuryInteractiveQuickTest Professionalsamplesflightapp","open"9) Dialog("Login").Activate10) Dialog("Login").WinEdit("Agent Name:").Set Agent11) Dialog("Login").WinEdit("Password:").SetSecure pwd12) Dialog("Login").WinEdit("Password:").Type micReturn13) Window("Flight Reservation").Close14) Next3) Compare two excel filesSet objExcel = CreateObject("Excel.Application")objExcel.Visible = TrueSet objWorkbook1= objExcel.Workbooks.Open("E:tester1.xls")Set objWorkbook2= objExcel.Workbooks.Open("E:tester2.xls")Set objWorksheet1= objWorkbook1.Worksheets(1)Set objWorksheet2= objWorkbook2.Worksheets(1)For Each cell In objWorksheet1.UsedRangeIf cell.Value <> objWorksheet2.Range(cell.Address).Value Thenmsgbox "value is different"Elsemsgbox "value is same"End IfNextobjWorkbook1.closeobjWorkbook2.closeobjExcel.quitset objExcel=nothing4) Data Driven Testing using Data Table methodsDatatable.AddSheet "tester"Datatable.ImportSheet "C:Documents andSettingsAdministratorDesktoptester.xls",1,3n=datatable.GetSheet (3).GetRowCountFor i= 1 to nDatatable.SetCurrentRow(i)Invokeapplication "C:Program FilesHPQuickTestProfessionalsamplesflightappflight4a.exe"Dialog("Login").ActivateDialog("Login").WinEdit("Agent Name:").Set datatable("agent",3)Dialog("Login").WinEdit("Password:").Set datatable("pwd",3)Dialog("Login").WinButton("OK").ClickWindow("Flight Reservation").CloseNextExample 2):Datatable.AddSheet "tester" QTP Training 2
  • 3. For more QTP Scripts, www.ramupalanki.comDatatable.ImportSheet "C:Documents andSettingsAdministratorDesktoptester.xls",1,3n=datatable.GetSheet (3).GetRowCountFor i= 1 to nDatatable.SetCurrentRow(i)VbWindow("Form1").ActivateVbWindow("Form1").VbEdit("val1").Set datatable("V1",3)VbWindow("Form1").VbEdit("val2").Set datatable("V2",3)VbWindow("Form1").VbButton("ADD").Clickeres= Datatable.Value ("res",3)ares=VbWindow("Form1").VbEdit("res").GetROProperty ("text")If eres=ares Thendatatable("res",3)=passelsedatatable("res",3)=failEnd IfNext5) Open an Excel SpreadsheetSet objExcel = CreateObject("Excel.Application")Set objWorkbook = objExcel.Workbooks.Open("C:Scriptstester.xls")6) Read an Excel SpreadsheetSet objExcel = CreateObject("Excel.Application")Set objWorkbook = objExcel.Workbooks.Open _("C:ScriptsNew_users.xls")intRow = 2Do Until objExcel.Cells(intRow,1).Value = ""Wscript.Echo "CN: " & objExcel.Cells(intRow, 1).ValueWscript.Echo "sAMAccountName: " & objExcel.Cells(intRow, 2).ValueWscript.Echo "GivenName: " & objExcel.Cells(intRow, 3).ValueWscript.Echo "LastName: " & objExcel.Cells(intRow, 4).ValueintRow = intRow + 1LoopobjExcel.Quit7) Add Formatted Data to a SpreadsheetSet objExcel = CreateObject("Excel.Application")objExcel.Visible = TrueobjExcel.Workbooks.AddobjExcel.Cells(1, 1).Value = "Test value"objExcel.Cells(1, 1).Font.Bold = TRUEobjExcel.Cells(1, 1).Font.Size = 24 QTP Training 3
  • 4. For more QTP Scripts, www.ramupalanki.comobjExcel.Cells(1, 1).Font.ColorIndex = 38) Sort an Excel Spreadsheet on Three Different ColumnsConst xlAscending = 1Const xlDescending = 2Const xlYes = 1Set objExcel = CreateObject("Excel.Application")objExcel.Visible = TrueSet objExcel = CreateObject("Excel.Application")objExcel.Visible = TrueSet objWorkbook = _objExcel.Workbooks.Open("C:ScriptsSort_test.xls")Set objWorksheet = objWorkbook.Worksheets(1)Set objRange = objWorksheet.UsedRangeSet objRange2 = objExcel.Range("A1")Set objRange3 = objExcel.Range("B1")Set objRange4 = objExcel.Range("C1")objRange.Sort objRange2,xlAscending,objRange3,,xlDescending, _objRange4,xlDescending,xlYes QTP Training 4