QTP Tips and Tricks - Printable Version +- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums) +-- Forum: General (https://www.learnqtp.com/forums/Forum-General) +--- Forum: Suggestions and Feedback (https://www.learnqtp.com/forums/Forum-Suggestions-and-Feedback) +--- Thread: QTP Tips and Tricks (/Thread-QTP-Tips-and-Tricks) |
QTP Tips and Tricks - rajpes - 07-25-2011 Let us share some tips and tricks we come across when working with QTP. If you want to share a New trick,add appropriate title in the "Post Subject" after clicking on the "New Reply" link. Setting.Add trick to use run session values in next run sessions Suppose you want to save some values manipulated in the run session somewhere so that you would like use them for next run session, the only ways(i think) are to save them to some external files like excel or output the values to global sheet. I just went through the topic "Setting Testing Options During the Run Session" which explains about Setting.Add through which we can add some key value pairs more or less same like Environment variables If you change the user defined Environment variables(pre-defined or dynamically created) in run time,they are all lost when the run session ends as they are reset to their original values and it can throw error if you try to use some dynamically created Environment variables of the last run ! So,the trick which i found is, Just save your values in the form of 'key value pair' to Setting.Add "key","value" which once created can be accessed in any run session thereafter. Example of how to use it. Code: If Not Setting.Exists("IterNum") then Isn't it cool? Note:These values will not be saved with the test after you close the test or open some other test(or create a new test)l! How to open and edit multiple scripts - rajpes - 07-25-2011 As you know, at a time you can open only one test and work with it. Sometimes you may wish to see scipt of other tests along with current test to compare/modify them. For this,in the file sytem, manually navigate to test folder. Drag the "script.mts" present inside the action folder to QTP tool. Now in QTP tool, you will see a new window to view/edit&save that script. You can drag as many script files as you wish Note:You can not run tests this way!you can only change the content of script. RE: QTP Tips and Tricks - Ankur - 07-25-2011 Nice initiative rajpes. Great to find that you are helping community members not only with your knowledge but also with such ideas. To boost performance of scripts execution - rajpes - 07-26-2011 If you feel, the execution of tests has slowed down or there is need to increase the speed ,just keep these few points in mind. 1. Do not load unwanted Add-ins ! Selecting an add-in(eg: web) just because it was selected by default can only reduce performance if you are working with windows applications.Load only required add-ins 2.Run mode=Fast! Tools>options>Run mode>set it to fast! You will need to have installed Microsoft script debugger to change settings here. 3.Active Screen! This actually consumes lot of disk space and usually we don't really need active screen which is displayed by default when we open QTP.If you have noticed,while editing scripts,it takes fraction of seconds or more to update Active screen window on each step.So if you are not in need of it, just toggle it (View>Active screen) or close the window(x). When it comes to saving the tests, again if you don't need any active screens to be stored just clear the option 'save active screen files' in 'save test' dialog box. If you really need active screen,check capture level in Tools>options>active screen> minimum/partial would be sufficient 4.Images and movie capture! Tools>options>Run Uncheck 'save movie results' and 'save still images' If you really want images set it 'for errors' instead of 'always' 5.Recovery Scenario! This is very crucial as far as performance hit is concerned.Try not to use them.Try to run scripts in a separate machine where unwanted softwares are not installed (eg:printers,anti virus e.t.c).Some browser popups can be disabled manually by selecting "do not show this next time" before actually automating scripts. Prefer 'Exist' method rather than blindly using recovery scenario if you are sure of what exceptional behavior could occur at what point of time. If it is really needed, make sure in file settings>recovery scenario, you configure "activate recovery scenarios" appropriately. See if 'On error' would handle the job instead of 'on every step'. 6.Importing sheets! When you import excel sheets using datable methods, make sure you are not dumping the sheet in every iteration! Eg:If the first line of your script is Datatable.Import(filename) and you have enabled "run on all iterations", you are simply importing the sheet every time unnecessarily.In such cases, set mode to "run one iteration only" and use a loop after import method Datatable.Import(filename) for i=1 to some_count Datatable.SetCurrentRow i 'do some operation next or If Environment("ActionIteration") = 1 Then DataTable.ImportSheet "E:\......xls" ,1 ,"Global" End If 7.Lengthy test script Try to divide lengthy test scripts into appropriate actions though it is not really a big parameter in performance consideration. If i find any more tips on this, will update this post. Simplest way to open a webpage - rajpes - 07-26-2011 SystemUtil.Run "www.google.com" 'yes,it works!not a good practice though VBScript to print a pattern - rajpes - 07-27-2011 Just a puzzle here,You need print the pattern like below depending on no. of rows rows=3, **1** *212* 32123 rows=4, ***1*** **212** *32123* 4321234 Code: r=inputbox ("enter no of rows") How to check whether focus is set by default on an object - rajpes - 07-29-2011 If you need to check if an object like webedit has the focus on it as soon as the page is loaded, If browser().page().webedit().GetROProperty("focus")=true then msgbox "yes, focus is there" end if 'Interestingly object spy doesnt show this property.So this is another cool trick! weblist index tip - rajpes - 07-29-2011 Assume there is a weblist with "n" items in it and you need to select the items in it in a loop. 'To select the items always start index with 0 and to GetItem start index with 1 for i=0 to n-1 browser().page().weblist().select "#"&i next for i=1 to n msgbox browser().page().weblist().GetItem (i) next How to check if a column exists in datatable - rajpes - 07-30-2011 Code: on error resume next To copy a datatable sheet's content to new sheet in the datatable - rajpes - 07-30-2011 Sometimes you may need to compare two datasheets in run time datatable. The trick is to supply empty string in "filename" parameter of importsheet method. Fallowing code copies global sheet's data into "NewSheet" Code: DataTable.AddSheet "NewSheet" |