Best practices, code snippets for common functionality, examples, and guidelines.
Posts: 8
Joined: Sun Oct 26, 2014 8:02 am


Post by mumu » Wed Nov 26, 2014 7:47 am

Window 8 Pro x64

Code: Select all

InputTag GoogleSearch = "/dom[@domain~'www.google.com']//input[@name='q']";
WebDocument WebVE = Host.Local.FindSingle("/dom[@domain~'www.google.com']");
//Since original search page domain is the same 'www.google.com', will Ranorex confused the page/web loaded completely ?
//If i change to @Caption='asdasdas' , Ranorex will throw exception if the result page havent loaded in seconds.
or using other method like .WaitForExists() / EnsureVisible(). If using WaitForExists() / EnsureVisible(), we need to wait for the particular object/element to exists/visible. if the loading time exceed, Ranorex will throw exception....Either way if the page show error, Ranorex will still waiting untill duration finish and then only throw exception. (waste of time).

which is the best practice for Ranorex?

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

Re: WebDocument.WaitForDocumentLoaded()

Post by krstcs » Wed Nov 26, 2014 2:35 pm

First, Ranorex waiting for the full duration is only a waste of time if someone is sitting and watching the test run, which you should not need to do. It is how Ranorex works. Ranorex continues to try to find the item for that whole time, it's not just sitting there waiting for the timeout and not doing anything. On top of that, automated testing is not about speed as much as it is about consistency. Humans are not consistent. Computers will always do things the same way. This is the purpose and priority of automation. Speed is a secondary benefit.

Second, Ranorex throws exceptions when it doesn't find an item. That's just the mechanism they decided to use for this. (In my opinion it is the correct way to do it.) You could catch the exception and do something with it if you don't want to see it.

Third, if you know that the system under test will throw an error, you should be testing for the presence of the error directly, given the appropriate inputs. This will make the test faster and more precise. You should know every time that the error is going to appear. If you don't know there will be an error then you either need to learn more about the system under test, or you need to talk to your developers about the circumstances under which the error will occur so you know what to test for. You might be able to implement a PopupWatcher that would handle the error.

Finally, as for which is better, it all depends on what you are trying to do. I typically go with WaitFor(Exists/NotExists) because you can specify the timeout directly. And if you setup your RXPath correctly you can even use it as a validation step.
Shortcuts usually aren't...

Posts: 8
Joined: Sun Oct 26, 2014 8:02 am

Re: WebDocument.WaitForDocumentLoaded()

Post by mumu » Fri Nov 28, 2014 8:13 am

thanks krstcs for reply
.WaitForDocumentLoaded() method seem no functioning correctly, sometime page still loading and .WaitForDocumentLoaded() finish and proceed to the next command. It is related to webdocument ?
How to implement this method correctly?

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

Re: WebDocument.WaitForDocumentLoaded()

Post by Support Team » Mon Dec 01, 2014 1:53 pm

Hello mumu,

The WaitForDocumentLoaded() method checks the state of a webpage. If the webpage contains dynamic elements it’s possible that the page is fully loaded but the elements within aren’t. I would also recommend using the WaitFor() method in that case.