Sei sulla pagina 1di 8

QTP Script to find number of Checkboxes, Text boxes Etc... the Web page. Set a=Description.Create a("html tag").

value="input" a("type").value="checkbox" Set b=Browser("name:=XYZ").Page("title:=XYZ").childobjects(a) c=b.count msgbox c Copy a file From C drive to D Drive Dim f Set f = CreateObject ("Scripting.FileSystemObject") f.CopyFile "C:\lakshmi.txt", "D:\" Msgbox "File Copied" Copy a folder From C drive to D Drive Dim f Set f = CreateObject("Scripting.FileSystemObject") f.CopyFolder "D:\Test2", "C:\" Msgbox "Folder Copied" QTP Script to get the value from TextBox: X=Browser("Browser").Page("Pagename").Webedit("Webeditboxname").GetROProperty("value") msgbox x QTP Script to find number of lines in text file. Const ForReading = 1 Set fso = CreateObject( "Scripting.FileSystemObject" ) Set textFile = fso.OpenTextFile( "C:\Damu\A.txt", ForReading ) textFile.ReadAll Print "Number of lines: " & textFile.Line textFile.Close QTP Script to Encrypt the String: str="ExpertQTP" var=Crypt.Encrypt(str) msgbox var QTP Script to Upload Attachment To QC

Dim ObjCurrentTest,ObjAttch Set ObjCurrentTest = QCUtil.CurrentTest.Attachments Set ObjAttch = ObjCurrentTest.AddItem(Null) ObjAttch.FileName = "C:\...\SampleTestResults.xls" ObjAttch.Type = 1 ObjAttch.Post ObjAttch.Refresh QTP script to Add defect in QC Set TDConnection = CreateObject(TDApiOle.TDConnection) TDConnection.InitConnection http://yovav/tdbin DB URL TDConnection.ConnectProject TD76,bella,pino Valid login information If TDConnection.Connected Then MsgBox(Connected to + chr (13) + Server + TDConnection.ServerName _+ chr (13) +Project + TDConnection.ProjectName ) Else MsgBox(Not Connected) End If Get the IBugFactory Set BugFactory = TDConnection.BugFactory Add a new empty bug Set Bug = BugFactory.AddItem (Nothing) fill the bug with relevant parametersBug.Status = New Bug.Summary = Connecting to TD Bug.Priority = 4-Very High depends on the DB Bug.AssignedTo = admin user that must exist in the DBs users list Bug.DetectedBy = admin user that must exist in the DBs users list Post the bug to DB ( commit ) Bug.Post Creating MS Word document using QTP Dim obj_MSWord Set obj_MSWord = CreateObject("Word.Application")obj_MSWord.Documents.Add obj_MSWord.Selection.TypeText "This is a simple text" obj_MSWord.ActiveDocument.SaveAs "D:\qtpkingblogspot.doc" obj_MSWord.Quit Set obj_MSWord=Nothing QTP Script for Highlighting the Objects systemutil.Run "http://www.qtpking.blogspot.com/" Dim obj Set obj=Description.Create obj("micclass").value="Link"

Set x=browser("QTP for you ...").Page("QTP for you ...").ChildObjects(obj) For i=0 to x.count-1 x(i).highlight Next QTP Script to find Folder Size: dim fso foldername="Sreekanth" Set fso = CreateObject( "Scripting.FileSystemObject" ) Set folder1 = fso.GetFolder( "D:\Documents and Settings\Sree\Desktop\"&foldername) msgbox "Size of Folder "&foldername&" :- "&folder1.Size&" bytes" Set fso=Nothing QTP Script to find File Size: Set fso = CreateObject( "Scripting.FileSystemObject" ) fname="qtpinf" Set folder1 = fso.Getfile("D:\Documents and Settings\Sree\Desktop\"&fname&".doc") msgbox "Size of File "&fname&" :- "&folder1.Size&" bytes" Set fso=Nothing QTP script to Capture Tool Tips in Text msgbox browser("Google").Page("Google").WebElement("India").Object.title QTP script to Capture Tool Tips in Images msgbox Browser("Yahoo! India").Page("Yahoo! India").Image("Click here").GetROProperty("alt") QTP script to Capture Tool Tips in Links x=Browser("Yahoo! India").Page("Yahoo! India").Link("All Yahoo! Services").GetROProperty("OuterHtml") temp=split(x,chr("34")) ToolTip=temp(1) msgbox ToolTip

QTP Script to find Number of Files in Folder: Set objFileSysOb = CreateObject("Scripting.FileSystemObject") Set colFolderName = objFileSysOb.GetFolder("give entire folder path here") Set vFiles =colFolderName.Files Sno=0 For each i in vFiles d=Split(i,"\") FileName=d(ubound(d)) Sno=Sno+1 msgbox "File "&Sno&" : "&FileName Next msgbox "Number of files in Current Folder : "&vFiles.count To Retrieve the Column count Data Table : Col_count= Datatable.GetSheet("Action1").GetParameterCount msgbox "No. of columns used in "&Environment("ActionName")&" are : " &Col_count To Retrieve the Column Names of Data Table : 'Col_Name=Datatable.GetSheet("Action1").GetParameter(1).Name msgbox " Column name is : "&Col_Name Deselect All Radio Buttons: Set Obj = Browser("Google").Page("Google").object.getElementsByTagName("INPUT") For each RadioBtn in Obj If lcase(RadioBtn.type) = "radio" Then RadioBtn.checked = False Next Open QTP by using Command Prompt: Paste the below mention code in notepad and save it as LaunchQTP.vbs.Call the file in Command prompt it will automatically opens the QTP Dim A As QuickTest,Application Set A = CreateObject(QuickTest.Application) A.Launch

A.New A.Visible = True Bring a Data From Text File to DataTable Const ForReading = 1 Row =1 Set D = CreateObject ("Scripting.FileSystemObject") Set B= D.OpenTextFile("C:\Sample.txt",ForReading) Dim C () i=0 Do Until B.AtEndofStream Redim Preserve C(i) C(i) = B.ReadLine i=i+1 Loop B.Close For Each strLine in C MyArray = Split (strLine," ",-1,1) For each sline in MyArray DataTable.SetCurrentRow (row) datatable("A",dtglobalsheet)=sline row=row+1 Next Next Datatable.ExportSheet "C:\Damu.xls",1 ExitRun Get All Link and URL Names in Web Page: Set A = Description.Create A(micclass).value=Link Set B=Browser(BrowserName).Page(PageName).ChildObjects(A) C=B.count For i=0 to a-1 tag=B(i).GetROProperty(Name) href=B(i).GetROProperty(url) msgbox tag & & href

Next To Find number of mails in Outlook: Set A= CreateObject(Outlook.Application) Set B= A.GetNameSpace(MAPI) Set C= B.GetDefaultFolder(5) Msgbox C.Items.count Create an XML File: Set A=XMLUtil.CreateXML() A.CreateDocument "BookStore" Set B= A.GetRootElement() For i=0 to 1 st="Book - " & i sa="Author -" & i B.AddChildElementByName "Book","" Set C = B.ChildElements() Set C = C.item(C.count) C.AddChildElementByName "Name",st C.AddChildElementByName "Author",sa A.SaveFile "C:\Damu\Hi.xml" Next

Copy the data from XML File to QTP Datatable Set A=xmlutil.CreateXML A.LoadFile "C:\Damu\Hi.xml" Set B=A.GetRootElement() Set D=B.ChildElementsByPath ("/BookStore/Book") For i=1 to D.count For j=1 to D.item(i).childelements.count datatable.GlobalSheet.AddParameter D.item(i).childelements.item(j).elementname,"" E=D.item(i).childelements.item(j).elementname F=D.item(i).childelements.item(j).value

datatable.GlobalSheet.GetParameter(E).value=F Next Datatable.GlobalSheet.SetCurrentRow i+1 Next Compare two XML Files: Set A = XMLUtil.CreateXML A.LoadFile "C:\Damu\Damu.xml" Set B = XMLUtil.CreateXML B.LoadFile "C:\Damu\Hi.xml" Res=B.Compare(A,resultDoc,micXMLValues+micXMLCDataSections) Msgbox resultDoc If res=1 then msgbox "Documents Match" Else msgbox "Do not Match" End If Data Driven Code for Drop Down: Basic Select Code: Browser ("Browser Name").Page ("Page Name").WebList ("WebListName").Select "Value" If the web list contains some x no. of values and if we want to select only 5 out of it then A=Browser (Browser Name).Page (Page name).Weblist (WebListname) .Getitemscount () For i=0 to A If i<5 then Browser (Browser Name).Page (Page name).Weblist (WebListname).Select i End if Next

Gmail Login Page: datatable.Import "F:\Damu\Hi.xls" datatable.ImportSheet "F:\Damu\Hi.xls",1,"Sheet2" Browser("Gmail: Email from Google").page("Gmail: Email from Google").WebEdit("Email").Set datatable ("Username",dtglobalsheet) Browser("Gmail: Email from Google").page("Gmail: Email from Google").WebEdit("Passwd").Set datatable ("Password",dtlocalsheet) Browser("Gmail: Email from Google").page("Gmail: Email from Google").WebButton("Sign in").Click Descriptive Program for Recovery Scenario Manager Dim A Set A= CreateObject("QuickTest.Application") A.Test.Settings.Recovery.Enabled = True A.Test.Settings.Recovery.SetActivationMode "OnError" A.Test.Settings.Recovery.Add "C:\qtp\recovery.qrs", "Recovery", 1 A.Test.Settings.Recovery.Item(1).Enabled = True Above statement will enable recovery file for specific test. Select all the Checkboxes Set A= Description.Create A("micclass").Value = "WebCheckBox" A("visible").Value = True Set B = Browser().Page().ChildObjects(A) msgbox B.Count For i = 0 To B.Count -1 colCheckboxes(i).Set "ON" Next Select a Particular Checkbox in Webtable: Dep_Time="9:45PM" rc= Browser("title:=ARC Travels").Page("title:=ARC Travels").WebTable("name:=Forward").RowCount For i=1 to rc DepTime_Table=Browser("title:=ARC Travels").Page("title:=ARC Travels").WebTable("name:=Forward").GetCellData(i,3) If (Dep_Time=DepTime_Table) then Browser("title:=ARC Travels").Page("title:=ARC Travels").WebTable("name:=Forward").ChildItem(i,1,"WebCheckBox",0).Set "ON" Exit For End if Next

Potrebbero piacerti anche