Page 1 of 2

Best way to validate URL in browser address bar?

Posted: Fri May 22, 2015 11:14 am
by Fergal
[Ranorex 5.2.2, Windows 7, testing website on Google Chrome.]

The test step below validates that a given URL is displayed in the Browser address bar.

Image


The XPath for the AddressAndSearchBar repository item looks like this:
/form[@title~'^{REMOVED}']/container/container[@accessiblerole='Client' and @accessiblehelp='BrowserView']/container[@accessiblerole='Client' and @accessiblehelp='TopContainerView']/toolbar[@accessiblename='main']/container[@accessiblerole='Grouping' and @accessiblehelp='LocationBarView']/text[@accessiblename='Address and search bar']
My issue is that the repository item above is not always found when the test runs. Is there an easier, simpler or standard way to validate that a particular URL, is the one displayed in the browser address bar?

Thanks!

Re: Best way to validate URL in browser address bar?

Posted: Fri May 22, 2015 12:22 pm
by odklizec
Hi,

I would suggest to use the PageUrl attribute of DOM element. And maybe it would be a good idea to add
WaitForDocumentLoaded() action before accessing the DOM element? You see, some attributes may not be filled until the page is not fully loaded.
PageUrl.png

Re: Best way to validate URL in browser address bar?

Posted: Tue May 26, 2015 9:37 am
by Fergal
Thanks Pavel, that looks great and I will try using it.

Re: Best way to validate URL in browser address bar?

Posted: Mon Jun 29, 2015 12:55 pm
by rastek
Hi odklizec,

I have two questions for your answer for this post

I am using Text attribute to get url, using PageUrl has more advantage ?

My second question is;

When I insert InvokeAction in Ranorex I only see EnsureVisible and Focus method, I can not see WaitFotDocumentLoaded ??

Thanks,
Rastek

Re: Best way to validate URL in browser address bar?

Posted: Mon Jun 29, 2015 1:06 pm
by odklizec
Hi,

As far as I know, there is no Text attribute available for DOM element? This is why you have to use PageUrl.

And you don't see WaitFotDocumentLoaded because you most probably not inserted DOM element to action table? WaitFotDocumentLoaded is only available for DOM element.

Re: Best way to validate URL in browser address bar?

Posted: Tue Jun 30, 2015 8:30 am
by rastek
I am not getting Text for a DOM element, what I am saying is that, I can get Url from the object below using Text property

container[@accessiblename='Google Chrome']//toolbar[@accessiblename='main']/?/?/text[@accessiblename='Address and search bar']

So How will I add DOM element to action table ? And what is the point here ? Accessing objects without repository as in the case Descriptive Programming ?

Thanks,
Rastek.

Re: Best way to validate URL in browser address bar?

Posted: Tue Jun 30, 2015 10:26 am
by odklizec
Hi,

In my opinion, validating url from the address bar is much less reliable than using PegeUrl attribute of DOM element, not to mention that the xpath of address bar may vary between browsers? You asked for best way of validating actual page url, so I suggested doing it via PageUrl attribute :)

Re: Best way to validate URL in browser address bar?

Posted: Tue Jun 30, 2015 1:51 pm
by rastek
Hi odklizec
Thanks for the reply, and it will be fine if you can also reply to my second question, How will I add DOM element to action table ? and where is that action table actually ?

Thanks,
Rastek.

Re: Best way to validate URL in browser address bar?

Posted: Tue Jun 30, 2015 4:06 pm
by odklizec
Hi,

DOM is a top level element of each web page displayed in browser. If you start recording and click an element on page, its root level element should be DOM (automatically added to repository along with selected element).
DOM.png
By "actions table" I mean the table in Recording module, where you can find and edit all recorded or manually added actions...
http://www.ranorex.com/support/user-gui ... tions.html
Hope this helps? ;)

Re: Best way to validate URL in browser address bar?

Posted: Wed Jul 01, 2015 12:15 pm
by rastek
Thanks but I still can not add WaitForDocumentLoaded there is no option when I add InvokeAction, how do you do that ?

Thanks,
Rastek

Re: Best way to validate URL in browser address bar?

Posted: Wed Jul 01, 2015 2:18 pm
by odklizec
Hi,

If you don't see WaitForDocumentLoaded in the InvokeAction, then you most probably don't access DOM element? WaitForDocumentLoaded is only available for DOM elements. But if you can access PageUrl and, for the same element, you don't see WaitForDocumentLoaded, that's definitely weird ;)

Anyway, I think you can easily try your test without WaitForDocumentLoaded. Just try to validate PageUrl.

Re: Best way to validate URL in browser address bar?

Posted: Thu Jul 02, 2015 9:05 am
by rastek
I still can not understand something here, you write

then you most probably don't access DOM element? WaitForDocumentLoaded is only available for DOM elements.

How will access Dom element ? I just record , you do something different ? How you work with DOM element I do not ??

I record and my root element is /dom, but I can not see that Invoke Action and I wonder why..

I want to use WaitForDocumentLoaded in order to wait wap page fullt loaded, dont you also use it for that ?

Thanks.

Re: Best way to validate URL in browser address bar?

Posted: Thu Jul 02, 2015 9:31 am
by odklizec
Hi,

You need to Drag&Drop DOM element to recording table and then you should be able to access WaitForDocumentLoaded from InvokeAction menu...
DragDropDom.png
InvokeActions cannot be recorded, they are only accessible after drag&drop of repo element to recording table and the list of accessible InvokeAction commands depends of repo element. Not all elements have the same actions. As mentioned before, WaitForDocumentLoaded is only available for DOM element. Hope this helps?

Re: Best way to validate URL in browser address bar?

Posted: Thu Jul 02, 2015 9:39 am
by CookieMonster
Hi Rastek,

If you want to wait, until the web page is loaded, then you have to create an function in the user code and use the Ranorex API, it is the easiest way.

The Repository Item has to be a dom object.

Here an example how you can implement it.

Code: Select all

public void WaitTilMyPageIsLoaded(RepoItemInfo myDomRepoInfo)
{
      WebDocument webDocument = (WebDocument) myDomRepoInfo.CreateAdapter<Unknown>(true).Element;

      while(webDocument.State != "complete")
      {
         webDocument.WaitForDocumentLoaded()
      }

}
But keep in mind, if your webpage uses a lot of of Ajax, then this way is not going to work.


Cheers
Dan

Re: Best way to validate URL in browser address bar?

Posted: Thu Jul 02, 2015 9:48 am
by CookieMonster
Hi Pavel,

Cool, now I have learned something. Because I seldom drag and drop the repository item first, especial a DOM object, hence I have never seen this actions.

Regards
Dan