We all know that “analog” is widely considered a dirty word when it comes to QTP scripting. It is very sensitive to changes in the environment in which the script is executed, such as objects that were moved in the window, changes to screen resolution or changes to window size & position. We can’t do much when it comes to the first problem, but there is a simple trick that should eliminate the problems caused by changes to the window size and position, and in some cases screen resolution;
When you start recording in analog mode, select the option to record relative to the window. This will eliminate some of the window position problems but is still prone to failure. To (mostly) eliminate these problems, record a “Move” step and a “Resize” step for the window, e.g.:
Window(“Paint”).Move 0,0 Window(“Paint”).Resize 859,632
This is good and well if we are working with Windows applications, but what about web browsers? There are no “Move” or “Resize” methods for the Browser class. In this case you can invoke the “Move” and “Resize” methods using the browser’s native Window class:
1 2 3
pagetitle = Browser("YourBrowser").GetROProperty("title") Window("regexpwndclass:=IEFrame","title:=" & pagetitle).Move 0,0 Window("regexpwndclass:=IEFrame","title:=" & pagetitle).Resize 859,632
This will ensure that the window has a constant size and position every time the script is executed, and in some cases this may even eliminate issues caused by differences in screen resolution. When pop-up windows or dialogs appear it’s probably a good idea to exit out of analog mode and record a resize and/or move of the window / dialog before continuing in the analog mode. Having said that, analog mode should only be used in cases when normal or low level recording does not work, and a pop-up window should not have this problem.