Popup Watcher Class Implementation

Best practices, code snippets for common functionality, examples, and guidelines.
AndyS
Posts: 14
Joined: Wed Jan 07, 2015 10:01 pm

Popup Watcher Class Implementation

Post by AndyS » Wed Apr 08, 2015 6:43 pm

I need a little help determining what to use to identify a pop-up properly using the example given in the user guide for Pop Up Watcher class. Example below:

Code: Select all

public static void CloseUpdateCheckDialog(Ranorex.Core.Repository.RepoItemInfo myInfo, Ranorex.Core.Element myElement)  
{  
 myElement.As<Ranorex.Button>().Click();  
} 
Can you provide an example of how this might be applied to a web application that I can reference? The PopupHandler demo seems to be a different implementation than what was provided in the user guide.

What I am having the most trouble with is identifying what repository names/ID's etc need to be placed into the above code. For example the code snippet

Code: Select all

myElement.As<Ranorex.Button>().Click();
I am not certain what I need to enter in place of myElement. Is this the name of the window that identifies the pop-up or the element I need to click? Any suggestions/tips you can provide to help me apply the user guides example to my own web application would be greatly appreciated.

Thanks,
Andy

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3945
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Popup Watcher Class Implementation

Post by odklizec » Wed Apr 08, 2015 9:14 pm

Hi,

All you need to do is to add both watched and clicked element to repository (using Track button). Then you just need to reference their info object in provided popupwatcher method like this...
// Add a Watch using the info object of the dialog and the info object of the button to click  
myPopupWatcher.WatchAndClick(repo.WatchedRepositoryElementName.SelfInfo, repo.WatchedRepositoryElementName.btnToClickRepoElementInfo);
Where the "Info" object is a special kind of object for accessing the repository elements, preventing Ranorex from throwing an exception. Info object should be available for each repository element or folder. When you start typing in code (starting with repo. ) you should get the info objects in the list of available code-completion items (methods, parameters, etc, including available repo elements). If you don't see the info object (in the code-completion list) use selfinfo instead.

Hope this helps? In case yous still need some more help, I can post you a simple sample project tomorrow.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

AndyS
Posts: 14
Joined: Wed Jan 07, 2015 10:01 pm

Re: Popup Watcher Class Implementation

Post by AndyS » Wed Apr 08, 2015 9:49 pm

A sample project might help actually so if you can provide that it would be great. I am in the Main method under program.cs and when I begin typing repo. it autocompletes and chooses the Report class.

All of my tests are recorded (autogenerated), would I need to create a custom code solution for this? I thought I read somewhere that the popup watcher class needed to be in the Main method?

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3945
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Popup Watcher Class Implementation

Post by odklizec » Wed Apr 08, 2015 10:12 pm

Hi,

If you don't want to wait to tomorrow (I'm not behind my computer right now), you can check the sample project I created some time ago. It's a VB project, but it should be possible to convert it back to C#. Here it is...
http://www.ranorex.com/forum/need-help- ... pup#p24733
And yes, you will have to add the popupwatcher code to main method in program.cs.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

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

Re: Popup Watcher Class Implementation

Post by krstcs » Thu Apr 09, 2015 2:36 pm

The repo is available in Program, but you will have to type out the whole name of the actual repository class.

For example, if your project is name "MyTestProject", the repo would be "MyTestProjectRepository".

To get the current instance of the repo you would add the following to your Program.cs (before you try to use the 'repo' variable):

Code: Select all

MyTestProjectRepository repo = MyTestProjectRepository.Instance;
Shortcuts usually aren't...

AndyS
Posts: 14
Joined: Wed Jan 07, 2015 10:01 pm

Re: Popup Watcher Class Implementation

Post by AndyS » Thu Apr 09, 2015 4:14 pm

Thanks krstcs and Pavel, I will give it a go with the information you have provided so far and get back to you with my results. I really appreciate your help!

Andy