Your SlideShare is downloading. ×
Qtp  realtime scripts tutorial
Qtp  realtime scripts tutorial
Qtp  realtime scripts tutorial
Qtp  realtime scripts tutorial
Qtp  realtime scripts tutorial
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Qtp realtime scripts tutorial

946

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
946
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
56
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. for more QTP scripts, www.ramupalanki.comQTP Script 33 - How to compare two excel sheets of the same excel workbook and highlight thecells with different values in the first sheet?Excel object is being created hereSet Exl_Obj = CreateObject("Excel.Application")Exl_Obj.Visible = TrueFile sac1 is being openedSet WB_Obj_1= Exl_Obj.Workbooks.Open("C:sac1.xls")Cells in the first and second sheet of sac1 are comparedSet WS_Obj_1= WB_Obj_1.Worksheets(1)Set WS_Obj_2= WB_Obj_1.Worksheets(2) For Each cell In WS_Obj_1.UsedRangeIf cell.Value <> WS_Obj_2.Range(cell.Address).Value Thencell.Interior.ColorIndex = 6Elsecell.Interior.ColorIndex = 0End IfNextExl_Obj.workbooks("sac1.xls").saveExl_Obj.workbooks("sac1.xls").closeExl_Obj.Application.Quitset Exl_Obj=nothingQTP Script 32 - How to compare two excel files and highlight the cells with different values in thefirst file?Excel object is being created hereSet Exl_Obj = CreateObject("Excel.Application")Exl_Obj.Visible = TrueTwo files sac1 and sac2 are openedSet WB_Obj_1= Exl_Obj.Workbooks.Open("C:sac1.xls")Set WB_Obj_2= Exl_Obj.Workbooks.Open("C:sac2.xls")Cells in the first sheet of both the files are comparedSet WS_Obj_1= WB_Obj_1.Worksheets(1)Set WS_Obj_2= WB_Obj_2.Worksheets(1) For Each cell In WS_Obj_1.UsedRangeIf cell.Value <> WS_Obj_2.Range(cell.Address).Value Thencell.Interior.ColorIndex = 6Elsecell.Interior.ColorIndex = 0End IfNextExl_Obj.workbooks("sac1.xls").saveExl_Obj.workbooks("sac1.xls").closeExl_Obj.workbooks("sac2.xls").saveExl_Obj.workbooks("sac2.xls").close
  • 2. for more QTP scripts, www.ramupalanki.comExl_Obj.Application.Quitset Exl_Obj=nothingQTP Script 31 - How to compare range of cells in two excel files and highlight the cells withdifferent values in the first file?myrange=inputbox("enter range of cells e.g. A1:A5")Excel object is being created hereSet Exl_Obj = CreateObject("Excel.Application")Exl_Obj.Visible = TrueTwo files sac1 and sac2 are openedSet WB_Obj_1= Exl_Obj.Workbooks.Open("C:sac1.xls")Set WB_Obj_2= Exl_Obj.Workbooks.Open("C:sac2.xls")Cells in the first sheet of both the files are comparedSet WS_Obj_1= WB_Obj_1.Worksheets(1)Set WS_Obj_2= WB_Obj_2.Worksheets(1)For Each cell In WS_Obj_1.Range(myrange)If cell.Value <> WS_Obj_2.Range(cell.Address).Value Thencell.Interior.ColorIndex = 6Elsecell.Interior.ColorIndex = 0End IfNextExl_Obj.workbooks("sac1.xls").saveExl_Obj.workbooks("sac1.xls").closeExl_Obj.workbooks("sac2.xls").saveExl_Obj.workbooks("sac2.xls").closeExl_Obj.Application.Quitset Exl_Obj=nothingQTP Script 30 - How to rename all files in a folder and its subfolder?At the end of the root procedure, it shows “path and names of fileswhich are renamed”. This msgbox is useful if the number of files isvery small. If files are in huge numbers then modify this code if youwant to see the names and path of all the files renamed or if youdon’t want this you can simply convert that msgbox into a comment.Write this code on a notepad and save it with .vbs extension. It asksyou the path of the folder and the string to be replaced in eachfilename and the new string by which the old string is to bereplaced.Set fso = CreateObject ("Scripting.FileSystemObject")Dim uu, uu1total_files_renamed = 0total_files_skipped = 0root
  • 3. for more QTP scripts, www.ramupalanki.comset fso = nothingSub rootpath = inputbox ("enter path")old_string=inputbox ("enter string to be replaced")new_string=inputbox ("enter new string")Set folder_path = fso.GetFolder(path)msgbox "Warning: All files within the Folder """ &_folder_path.Path &""" will be renamed."procedure_sub_folders folder_path , old_string, new_stringMsgbox "Total Files Renamed :" &total_files_renamedMsgbox "Total Files Skipped :" &total_files_skippedmsgbox "Path and names of files which are renamed" &uu1End SubSub procedure_sub_folders (ByVal curr_folder, ByVal old_val, ByValnew_val) Set Folders = curr_folder.SubFoldersprocedure_folder curr_folder , old_val, new_valFor Each Folder in Foldersprocedure_sub_folders Folder , old_val, new_valnextend SubSub procedure_folder (ByVal folder, ByVal old_val, ByVal new_val) Set Files = folder.FilesFor Each File In FilesIf inStr(1,File.Name,old_val) > 0 Thenuu= Replace(File.Path, old_val, new_val)uu1= uu1 &vbcrlf &uuFile.Move Replace(File.Path,old_val,new_val)total_files_renamed = total_files_renamed + 1elsetotal_files_skipped = total_files_skipped + 1End IfNextEnd SubQTP Script 29 - How to rename all the files in a folder?Type the below code in a notepad, save it with .vbs extension and runit from command prompt. You have to change the folder name (C:abc)and the strname to suit your requirements.Below code renames all the files in a given folder to Sac 1, Sac2....and so on.strComputer = "."Set objWMIService = GetObject ("winmgmts:" &strComputer
  • 4. for more QTP scripts, www.ramupalanki.com&"rootcimv2")Set colFileList = objWMIService.ExecQuery ("ASSOCIATORS OF{Win32_Directory.Name=C:abc} Where " &"ResultClass =CIM_DataFile")x=1For Each objFile In colFileListstrname = "Sac " &xstrNewName = objFile.Drive &objFile.Path &strname &"."&objFile.ExtensionerrResult = objFile.Rename(strNewName)x=x+1Nextsource:http://www.microsoft.com/technet/scriptcenter/resources/qanda/nov04/hey1109.mspxTo know more about Windows Management Instrumentation go here.http://msdn.microsoft.com/en-us/library/aa394582(VS.85).aspxQTP Script 28 - How to rename all subfolders within a given folder?Type the below code in a notepad, save it with .vbs extension and runit from command prompt.In case nothing is entered for main_folder or search_string orreplace_string, the script will quit.main_folder = inputbox ("Enter the main folder whose subfolders needto be renamed" &vbcrlf &"e.g. C:Folder")if main_folder="" then quit_functionsearch_string = inputbox ("Enter the string to be searched")If search_string = "" then quit_functionreplace_string = inputbox ("Enter the string to be replaced")If replace_string = "" then quit_functionSet object_FSO= CreateObject ("Scripting.FileSystemObject")rename_function main_folderSub rename_function (byval Folder) GetFolder method is used to get the Folder object for the paththat you specify. You can then use the new variable containing thefolder object to access its various methods and properties.Set object_folder = object_FSO.GetFolder (Folder)SubFolder property returns a Folders collection consisting of allthe subfolders in a given folder.Set sub_folders = object_folder.SubfoldersFor each subfolder in sub_foldersnew_foldername = (Replace (subfolder.name, search_string,replace_string))
  • 5. for more QTP scripts, www.ramupalanki.comIf new_foldername <> subfolder.Name Thensubfolder.Name = new_foldernameEnd Ifrename_function subfolder.pathNextEnd SubSub quit_functionwscript.echo "Script quit_function"wscript.quitEnd subQTP Scripts 27 - How to add any path in the Search List (Tools -> Options -> Folders tab)through a script.How to add any path in the Search List (Tools -> Options-> Folders tab) through a script.We are opening a test called "call twra" and adding a pathC:Program FilesMercury InteractiveQuickTest ProfessionalTests inthe Search List (Tools -> Options -> Folders tab)Dim qtp_appDim str_pathSet qtp_app = CreateObject ("QuickTest.Application")qtp_app.Launchqtp_app.Visible = Trueqtp_app.Open "C:Program FilesMercury InteractiveQuickTestProfessionalTestscall twra", True, FalseIf the folder C:Program FilesMercury InteractiveQuickTestProfessionalTests is not there just add it.str_path = qtp_app.Folders.Locate ("C:Program FilesMercuryInteractiveQuickTest ProfessionalTests")‘If the folder is not found in the collection, add itIf qtp_app.Folders.Find (str_path) = -1 Thenqtp_app.Folders.Add str_path, 1 Add the folder to the collectionEnd IfIf you have moved "<current test>" downwards in the list, bring itback to first position.If qtp_app.Folders.Item (2) = "<current test>" Then qtp_app.Folders.MoveToPos 1, 2End If

×