如何讓你的QTP腳本執行效率更高?

Launch QTP using a .vbs file and not the QTP desktop icon. You will notice a substantial increase in speed. (使用VBS文件來啓動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 would not be released. Now as your script starts consuming more and more RAM, your System Under Test (SUT) will tend to become slower. (把變量和函數定義放到外部VBS文件,而不要放在Action中。)
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. (通過AOM控制QTP重啓來解決QTP內存泄漏問題。)
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. (儘量不要使用wait,而使用.sync或exist語句。)
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 would 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. (使用With語句可以讓代碼更清晰,而且效率更好。)
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.(使用OR要比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.(不要保存image和movie到測試結果中。)
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. (把運行模式設置爲fast。)
If you are new to automation or QTP. Read this beginner article on Automation Object Model (AOM). AOM simplifies many aspects of QTP scripting. It can help you in controlling QTP from an external file. (通過AOM控制QTP。)
Make use of relative paths while calling reusable actions in your script. Using relative path would make your script portable and easy to manage. (在調用Action時使用相對路徑。)
 

可以使用下面的代碼測試一下使用與不使用With語句在代碼效率上的差異 :

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 With

 

StartTime = Timer

For i=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 With

EndTime = Timer

Print  EndTime - StartTime

 

 

 


在測試WEB應用程序時,往往看到QTP運行速度比被測試的應用程序要快很多,往往都是QTP在等待頁面加載完成。


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. Moreover QTP would not perform any operation on a particular 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.

如何讓頁面加載得更快呢?關鍵在於圖片的加載。

Here I would 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.]

當然,如果考慮到圖片檢查點的話,這個技巧就沒用了。

 

本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/Testing_is_believing/archive/2009/12/19/5040174.aspx

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章