Working with pop-up menus

Best practices, code snippets for common functionality, examples, and guidelines.
HansSchl
Posts: 143
Joined: Wed Sep 19, 2018 10:05 am

Working with pop-up menus

Post by HansSchl » Thu Jul 16, 2020 11:11 am

Hi all,
my AUT is a Windows desktop application using MFC and lots of handwritten legacy code. When I click "File" in the menu bar, a drop-down menu opens with the stuff that you will usually find in a "File" menu.
My automated test should verify the position of the menu drop-down. Using the "instant tracking" feature, I was able to capture its RanorexPath:

Code: Select all

/form[@title='']/?/?/toolbar[@accessiblename='']
I'd like to add some attributes like class name to make the expression more specific, but I cannot use Ranorex Spy to inspect the drop-down because the drop-down is closed when input focus is moved. Finally I resorted to this expression:

Code: Select all

/form[@title='']/?/?/toolbar[@accessiblename='']/menuitem[@accessiblename>'Open']/..
...which ensures that the toolbar contains a menuitem starting with "Open". Works for me, but do you a better way to handle this problem?

Cheers
Hans

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

Re: Working with pop-up menus

Post by odklizec » Thu Jul 16, 2020 11:29 am

Hi,

You can use instant tracking, to capture elements in popup menu. Eventually, you can start standard tracking in Spy, press and hold F12, to pause tracking, then open the dopdown, move mouse over the item you want to get, and release F12 button. This should do the trick ;)
And another possibility is to save Ranorex snapshot of given popup directly from recording. Simply add the whole popup to repository and then add Create Snapshot action (pointing to popup repo element) to recording of your choice. 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

HansSchl
Posts: 143
Joined: Wed Sep 19, 2018 10:05 am

Re: Working with pop-up menus

Post by HansSchl » Thu Jul 16, 2020 12:05 pm

@odklizec, thank you for our reply. Actually instant tracking as well as F12 tracking result in the unspecific RanorexPath from my original posting. The "Create Snapshot" action however was new to me, and it gave me the information I wanted. Unfortunately, there seems to be no more specific bit of information which I could use to identify the menu drop-down...

User avatar
Stub
Posts: 515
Joined: Fri Jul 15, 2016 1:35 pm

Re: Working with pop-up menus

Post by Stub » Fri Jul 17, 2020 8:18 am

Legacy MFC app here and we had 'fun' with our context menus too. We use CodeJock so we get a class name from that, but in other cases it's just

Code: Select all

contextmenu[@accessiblerole='MenuPopup']
in the main. Ours just hang off the root form.

HansSchl
Posts: 143
Joined: Wed Sep 19, 2018 10:05 am

Re: Working with pop-up menus

Post by HansSchl » Fri Jul 17, 2020 9:59 am

@Stub, thanks for your input. I stepped through the MFC code and also found "@accessiblerole='MenuPopup'" as the best I can do to identify the menu. It seems to be rooted in thin air, so I gave it a separate application folder in Ranorex.

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

Re: Working with pop-up menus

Post by odklizec » Fri Jul 17, 2020 10:24 am

Hi,

It should be possible to improve the xpath with processname of the application under test. Then the xpath will be even more failproof 😉
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

User avatar
Stub
Posts: 515
Joined: Fri Jul 15, 2016 1:35 pm

Re: Working with pop-up menus

Post by Stub » Fri Jul 17, 2020 3:42 pm

Yes, we use process name too, so our RxPath looks something like:

Code: Select all

/form[@processname='YourThing']/contextmenu[@accessiblerole='MenuPopup']
I'll also use @accessiblename if the menu happens to have a distinctive value there. Some of ours are just labelled "Context" but most are probably blank :D It's worked for years and we can obviously whitelist nowadays too, which helps.

HansSchl
Posts: 143
Joined: Wed Sep 19, 2018 10:05 am

Re: Working with pop-up menus

Post by HansSchl » Fri Jul 17, 2020 5:38 pm

The @processname makes the thing a bit safer, indeed. What a pity the MFC menu implementation did not care more about accessibility...