How to make your qtp script execution more efficient?

Source: Internet
Author: User

On learnqtp, I saw two articles about how to improve the qtp script execution efficiency:

Make your qtp scripts perform better

Http://www.learnqtp.com/make-your-qtp-scripts-perform-better/

A quick qtp tip that may improve the performance of your scripts (for a Web based app)

Http://www.learnqtp.com/qtp-tip-to-load-web-page-faster-remove-images/

 

  • Launch qtp using a. vbs file and not the qtp desktop icon. You will notice a substantial increase in speed. (use the vbs file to start qtp .)
  • For large tests, always define variables, function in an external. vbs file and not inside a reusable action. attach these files with your test scripts. if you define a variable or a function in an action, on every iteration of your test run, memory (RAM) will be allocated to those variables/functions and wocould not be released. now as your script starts consuming more and more RAM, your system under Test (SUT) will tend to become slower. (put the variables and function definitions in the external vbs file instead of in the action file .)
  • While running, qtp consumes a lot of memory by itself. it is always advisable to have lots of available RAM (much more than what is recommended by HP) and good processor speed on a system where you intend to install qtp. when you have tests (and hence qtp) running for a prolonged period if time, there are chances of memory leaks. to avoid Memory leakage always restart qtp at some intervals of time. Using AOM you can automate this process. (qtp restart is controlled through AOM to solve the qtp Memory leakage problem .)
  • Avoid using hard coded wait (x) Statement. wait statement waits for full X seconds, even if the event has already occurred. instead use. sync or exist statement. while using exist statement always have a value inside it. (Do not use wait whenever possible. sync or exist statement .)

For ex:. Exist (10)Here qtp will wait Max till 10 seconds and if it finds the object at (say) 3 secs, it will resume the execution immediately thereby saving your precious time. on the other hand if you leave the parenthesis blank, qtp wowould wait for Object synchronization timeout You have mentioned under File> test Settings> RUN tab.

  • Make full use of what HP-QTP has provided you in the tool ide. Use"Automatically generate "with" statements after recording"Option present under tools> Options> General tab. this will not only make your code look neater but also make your scripts perform better. (using the with statement can make the code clearer and more efficient .)
  • Make your own judgement whether you want to go for descriptive programming or object repository or mixed approach. each approach has it own pros and cons that in turn is related to qtp performance. (using or is faster than DP .)
  • Unless absolutely required, uncheck the Options"Save still image capture to results"And"Save Movie to results"Present under tools> Options> RUN tab. These options definitely have some bearing on qtp run time performance. (do not save the image and movie to the test results .)
  • Make the run mode as "fast". This setting is present under tool> Options> RUN tab.Note:If you intend to run your scripts from QC no need to worry about this option, as the scripts will run in fast mode whether you want or not. (set the running mode to fast .)
  • If you are new to automation or qtp. read this beginner article on Automation Object Model (AOM ). AOM simplifies extends aspects of qtp scripting. it can help you in controlling qtp from an external file. (use AOM to control qtp .)
  • Make use of relative paths while calling reusable actions in your script. Using Relative Path wocould make your script portable and easy to manage. (use the relative path when calling action .)

 

You can use the following code to test the code efficiency difference between using and not using with statements:

Dim starttime, endtime, starttime1, endtime1

 

Systemutil. Run "C:/program files/HP/quicktest professional/samples/Flight/APP/flight4a.exe"

 

With Dialog ("login ")

. Winedit ("agent name:"). Set "Mercury"

. Winedit ("agent name:"). Type mictab

. Winedit ("Password:"). setsecure "4864ede3f3f8f30757cf694e3e100d29bf1ea9b9"

. Winedit ("Password:"). Type micreturn

End

 

Starttime = Timer

For 1 to 100

Window ("flight reservation"). winedit ("name:"). Set "Ankur"

Next

'With window ("flight reservation ")

'For I = 1 to 100

'. Winedit ("name:"). Set "Ankur"

'Next

'End

Endtime = Timer

Print endtime-starttime

 

When testing web applications, we often see that qtp runs much faster than the tested applications, and often qtp is waiting for page loading to complete.

While working on a Web applications using qtp, you may have noticed most of the time qtp runs too fast in comparison to the application. MoreoverQtp wocould not perform any operation on a participant page unless that page has loaded completely (100%). You may wonder in bewilderment about what to do to make the application (web page) Load faster.

 

How can we make the page Load faster? The key lies in image loading.

Here I wowould like to give you a simple tip to alleviate your pain (and waiting time) a bit.

If you will notice carefully, most of the times text on a web page renders very quickly. it is the images that creates problem and increases the web page loading time. what if we can stop the images from loading altogether?

All browsers provides this facility whereby you can stop pictures from showing. To do this in IE6, go to tools> Internet Options> Advanced Tab. scroll down to 'multimedia 'section and uncheck'Show pictures'.

To do this in Firefox, go to tools> Options> content. uncheck'Load images automatically'

 

Run your script now and let us know if this tip helped you. [for obvious reasons, this tip won't be of any use when you have to work on image/bitmap checkpoints.]

Of course, this technique is useless if you consider image checkpoints.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.