FEATURE REQUEST: WebDocument.WaitForComplete()

Bug reports.
krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

FEATURE REQUEST: WebDocument.WaitForComplete()

Post by krstcs » Fri Jul 12, 2013 1:32 pm

It would be nice if we could have a "WaitForComplete()" type method on WebDocument types.

Ranorex does not automatically wait for a page to reload before it goes to the next test step. It would be nice if there was either a test step method or a property in the test suite that would force Ranorex to wait for page loading to finish.

I tried using the PopupWatcher to do it, but since it runs in another thread it doesn't pause the test script.

It would need to be robust enough to handle pages that change from loading to complete to loading to complete very quickly, like when a page loads a cross-site element and needs to complete the main body before it can run the script to get the other elements.

Problem is that if you don't wait for that Ranorex sometimes fails to find elements on the page because it doesn't always find the objects if they aren't there when the search first starts.


I currently have a module in my tests that is named "WAIT_FOR_PAGE_RELOAD" that looks like:

1. 1s Delay
2. Wait For Not Exist -> WebDocument(/dom[@state!='complete'])
3. 0.5s Delay
4. Wait For Not Exist -> WebDocument(/dom[@state!='complete'])
Shortcuts usually aren't...

sergii
Posts: 30
Joined: Fri Jun 07, 2013 11:07 pm

Re: FEATURE REQUEST: WebDocument.WaitForComplete()

Post by sergii » Fri Jul 12, 2013 2:41 pm

In our projects we have been using similar solution, but we are rather focused on special elements to be present.
We don't need to wait until actually the full page to load if we want to click on something.
We just check in loop every 200ms if the element is present using Host.Local.TryFindSingle until maximum timeout. This will save us a lot of time waiting for some heavy images to be fully loaded, that we don't need to use in the step.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: FEATURE REQUEST: WebDocument.WaitForComplete()

Post by Support Team » Mon Jul 15, 2013 4:58 pm

Hello,

There is a method called "WaitForDocumentLoaded()" in our API, which can be used to wait until the document is loaded.
Please try if you can solve your issue using this method.
You can find an example in the section "Web Testing" in our user guide, which describes how to use this method.
Thank you!

Regards,
Bernhard

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: FEATURE REQUEST: WebDocument.WaitForComplete()

Post by krstcs » Mon Jul 15, 2013 7:52 pm

Thank you for the information. I have tried it, but unfortunately it doesn't always catch the loads, especially if the page does a small load and then process a script and does another small load. It will only catch the first one and then continue with the script.

Also, it would be nice if it could be used in a test recording directly without going into user code, like "Wait For Not Exists" is currently. Having to go into user code to manage this type of thing becomes cumbersome quickly.
Shortcuts usually aren't...

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: FEATURE REQUEST: WebDocument.WaitForComplete()

Post by Support Team » Wed Jul 17, 2013 3:33 pm

Hi,

The method also just checks if the state attribute is set to "complete" and when the attribute will be set to complete the method "returns".
You can therefore also do the same without the need of "user code". You just need to add the specific "state" attribute to the corresponding repository item and after you added it you just need to drag it to your recording (action table) and select Validate.Exists.
Another easy way would be validating if a specific web element exists as explained in the following forum post.

Regards,
Markus

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: FEATURE REQUEST: WebDocument.WaitForComplete()

Post by krstcs » Wed Jul 17, 2013 3:58 pm

Thank you Markus.

I think the issue here is that I would have to do this in every module, and therefore if I needed to change something in the logic I would have to do it in every module this is in.

I have decided to do the same thing but in a separate module due to how I structure my tests.



In working with this I have found another issue. Ranorex only checks a given XPath one time. So if my path is invalidated WHILE the search for a child object is happening it will fail, even if the object is valid.

Here is my scenario:

1. Our SUT loads a page and completes but runs a page script.
2. Ranorex finds the page as complete (my XPath includes the @state='complete') and tries to find the next child I am looking for.
3. WHILE the search above is happening, the SUT finishes running the page script and then loads a new element, invalidating the whole child tree for the object in the repository, including the one that Ranorex is searching for.
4. This causes Ranorex to time-out and fail.

I have to do 2 checks in order to get around this. So, some of this is an issue with our SUT reporting complete when it really isn't, but I don't think there is anything that we can do about that.

The thing I think COULD be done is for Ranorex to refresh the search if any parent object becomes invalid during a search. Have a property that we could set to say how many times to allow a reset and default to 2, just so it doesn't do an infinite loop on a page that has an issue.

Or allow a re-search on fail for a specified number of attempts, instead of just failing on the first try. Again, you could set a default number of attempts to 1 or 2 and allow us to change it as needed.
Shortcuts usually aren't...

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: FEATURE REQUEST: WebDocument.WaitForComplete()

Post by Support Team » Thu Jul 18, 2013 5:15 pm

Hi,

About the state attribute:
We receive the value of that attribute from the browser and it can happen that the browser sets the state attribute to complete even if not all parts of the page are successfully loaded so this state is unfortunately not really meaningful as your example shows.

Instead of using that attribute it is suggested to validate (Validate.Exists) if an specific element of your web page exists, could be an element which takes the longest to be loaded.

In order to avoid such messages you could also use the repository items directly without assigning them to a variable. This ensures that the live elements are always used instead of the saved ones.
For instance use:
repo.TestAutomationToolsRanorexAutomati.SUPPORT.Click()
instead of:
ATag support = repo.TestAutomationToolsRanorexAutomati.SUPPORT;
//...
support.Click();
I hope this makes sense for you :).

Regards,
Markus