How does QTP wait for a page to load dynamic data?

I have a scenario where the browser status = completed, but still the page is not loaded. Is there a general procedure in which qtp can wait for the page to load? I tried with objBrowzer.sync, objPage.Sync, objPage.waitproperty "readyState", "completed", 50. But it does not always work.

I can’t even expect a wait statement to wait for this object to appear. Because in different cases, there are different objects. Is there any general statement that will work in all scenarios?

Thanks in advance.

+5
source share
6 answers

You have just discovered that QTP does not offer explicit support for synchronization with asynchronous browser script execution , as well as websites with AJAX support. When QTP considers the page to be fully loaded, the JavaScript handlers still actually work, possibly updating the HTML code used for that page, and QTP accesses the GUI at an early stage.

readyState is a good idea, but it's usually easy to find cases where it doesn't work well enough.

1. The best solution is to synchronize the busy indicator of the application , for example, a progress bar or an activity indicator.

Unfortunately, waiting for a busy indicator means that the busy indicator is always displayed, but many applications only show it if the process takes a lot of time (more than 2 seconds, etc.). Then it quickly becomes a little messier than expected.

2. If the application does not have anything like this, you can often help yourself by synchronizing on some “ready-made” indicator , for example, “expected field appeared” or “OK button is disabled.” This often requires a specific solution for each context, if not real “ready-made” indicator (which usually does not exist).

3. In many projects, automation users can get a busy indicator, which is built into the application only for them. . Although this does not create a lot of effort for developers (since modern applications have a centralized message manager, so switching to busy is inactive and vv can be easily monitored centrally), this greatly simplifies the amount of work required for synchronization.

Therefore, if possible, try contacting the developers and get them a representation of the property (a variable, a memory-mapped file, a semaphore, whatever they wish), which can easily be tested by the "synchronization" routine of the test robot. (Hint. To be able to distinguish between two “ready” states even after the “no” state is “busy” between them, it may be useful to get a consistent “busy state account” in addition to the “busy state icon”, so you can request this in in the same case.) Then, all synchronization problems are a defect in the application, since it obviously does not support the correct signal.

Update For applications based on the de facto "standard" structure, you can find ways to implement synchronization in a general way.

For example, for JavaScript applications, I was able to create test equipment that transparently reports the flow of events in QTP, which is used there to wait "long enough", allowing you to set up special calls, similar to the control points that are waiting for certain events (especially "click", and for applications running AJAX roundtripls a la Java Server Pages, "ajaxstop" events) that must be executed before continuing.

This turned out to be extremely useful, because it is often very difficult to get the developer to implement any support for test automation, and synchronization based on the graphical interface (only through the state of the test object / existance) is sometimes not enough if the application performs asynchronous requests in the background. It also eliminates the need to examine synchronization parameters for each GUI context, which can be extremely time-consuming and / or unreliable.

+9
source

There is no easy answer for you. I am afraid, as usual "it depends"

Here is a basic example, let's say you expect a button or text to appear on the screen:

 If Browser("user90site").Page("page1").WebButton("Button1").Exist(30) Then Browser("user90site").Page("page1").WebButton("Button1").Click Else Reporter.ReportEvent micFail,"button missing", "button missing" End If 

The above will wait 30 seconds for the web element to appear, however, if the button appears before 30 seconds, it will continue and click the button, otherwise it will report an error. Given that you have several scenarios, you will need to make different options to get the desired result.

Do you have unsuccessful tests because you are trying to work on elements that do not yet exist?

+2
source

This is not easy, especially for sites with AJAX. The best way is to write a simple function like

function WaitForObject(obj) WaitForObject = false Setting("DefaultTimeout") = 500 for i = 0 to 30 'or more If obj.Exist Then WaitForObject = true Exit For End If next Setting("DefaultTimeout") = 20000 ' or other value end function

And use this for objects that load at the end

+1
source

You may try. I know this is a very late answer, but it will help you achieve results more accurately. You can call this function many times if your browser loads longer, as shown below:

 Call AppBusyStatus(0) if Browser("Browsername").Exist Then Call AppBusyStatus(0) End If Call AppBusyStatus(0) Sub AppBusyStatus(intBrowserCreationTime) Do While Browser(CreationTime:intBrowserCreationTime).Object.Busy Wait 0,500 Loop End Sub 
0
source

Start the image upload and add to the repository,

 Set obj = Browser().Page().Image() wait() While (obj.Exist) 'Do Nothing //commented Wend 

This may increase the execution time of the script, but will give a solution to your problem.

0
source
 while Browser("user90site").Page("page1").WebButton("Button1").Exist(2)=false wait 2 wend Browser("user90site").Page("page1").WebButton("Button1").Click 

While the operator will be in a loop until the object is identified. Using while rather than if is more accurate.

-1
source

Source: https://habr.com/ru/post/1201297/


All Articles