need help to impliment VB PopupWatcher

Class library usage, coding and language questions.
fester13579
Posts: 30
Joined: Thu Feb 13, 2014 10:29 pm

need help to impliment VB PopupWatcher

Post by fester13579 » Mon Mar 17, 2014 10:30 pm

Hi,

I have read several threads and the help about the popup watcher and i'm still just scratching my head trying to figure out how to get started using it. I have a limited vb6 background :? so I am using a VB project for my recordings under 5.0.0. I understand the basic concept of a separate thread that keeps monitoring for an object in the repository and then does an action on it. I am still unclear on where the code goes and the syntax and could really use a good example of a working project to study.

Could I get someone to post a complete VB solution using notepad.exe in the recording as the app to run where the popup watcher is looking for the HELP|ABOUT window as the 'popup' to close via the OK button so I could get a feel for this?

Something like:

1. run notepad
2. click on help
3. click on about
(4). popup watcher sees the OK and clicks it

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

Re: need help to impliment VB PopupWatcher

Post by odklizec » Tue Mar 18, 2014 9:34 am

Hi,

In the attached zip you can find a very simple VB demo project, showing the usage of PopupWatcher with the scenario you described. The project is converted from C# project, but it should work just fine.

This is a great thing about Ranorex. Even if you are not familiar with C#, you can always convert C# code to VB code (and vice versa).
TestPopUpWatch_VB.zip
(51.82 KiB) Downloaded 236 times
Hope this helps? ;)
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

fester13579
Posts: 30
Joined: Thu Feb 13, 2014 10:29 pm

Re: need help to impliment VB PopupWatcher

Post by fester13579 » Wed Mar 19, 2014 6:48 pm

After some trial and error I was finally able to adapt your example. Thank you for your help.

I have a follow-up question now...

Suppose your AUT has a common error dialog 'popup' which has a static title string (same repo parrent object) but dynamic error messages.

As I understand it, your example is looking for a particular window (repo object) and then clicking on the OK button to close it. 'repo.Notepad_About'.

Using the notepad Help/about example, on the about screen there is a string containing the current Windows build eg. 'Version 6.1 ( Build 7601: Service Pack 1)'

Let's say I only want to click OK if the words 'service pack 1' is in the about dialog box.

In your Sub ClosePopUpDialog there is an IF statement:

Code: Select all

"If myRepoElement Is repo.Notepad_About.SelfInfo Then"
How would I go about adding something like

Code: Select all

AND text ~"service pack 1"

Thanks again

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

Re: need help to impliment VB PopupWatcher

Post by odklizec » Thu Mar 20, 2014 9:55 am

Hi,

In my example, I've used the title bar to identify the popup window. But of course, you can use anything you like from the popup window to identify the popup window. Simply track the window element inside the popup window and add it to the repository. Then instead of using the title bar repo item, use the repo item from inside of the popup window.

If you want to check the combination of the title and dynamic text from inside of the popup window you can use something like this:

Code: Select all

If myRepoElement Is repo.Notepad_About.SelfInfo andalso repo.Notepad_About.DynamicText.Caption.Contains("service pack 1") Then
Where repo.Notepad_About.DynamicText is the repo element containing the dynamic text inside the popup window. I'm not sure you can use the reg. exp. operator ~ in If..Then statement, like in your example?

There may be better ways to achieve what you want, maybe even without using the repository element (e.g. using xpaths), but I'm not that skilled in Ranorex & .net programming yet ;)

Below is attached the updated sample project. Just one additional note about it. The DynamicText repo element in this example uses instance number to identify itself. But instance numbers are not a very good to identify the GUI elements, because they often change! Unfortunately, because the Text and AccessibleName attributes contains the same string, which is not unique enough (and which will definitely change on different systems), instance number is probably the only way to identify this element. Just ask your developers to use meaningful and unique AccessibleName attributes for each GUI element in your app. Hope this helps a bit? ;)
Attachments
TestPopUpWatch_VB2.zip
(58.82 KiB) Downloaded 150 times
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