1

I have a menu with a submenu and would like to simulate a user interaction where the user clicks on the menu and then on a submenu using ⎕NQ. However, I can only simulate one event; the subsequent ones are not handled unless I intervene by clicking manually somewhere with the mouse.

Here is an example:

CreateMenu
'f' ⎕WC 'Form' ('Caption' 'Menu Test')
'f.menuBar' ⎕WC 'MenuBar'
'f.menuBar.menu' ⎕WC 'Menu' '&One'
'f.menuBar.menu.miA' ⎕WC 'MenuItem' ('Caption' 'Choice A')
'f.menuBar.menu.miB' ⎕WC 'Menu' ('Caption' 'Choice B')
'f.menuBar.menu.miB.miX' ⎕WC 'MenuItem' ('Caption' 'Choice X')
'f.menuBar.menu.miB.miY' ⎕WC 'MenuItem' ('Caption' 'Choice Y')

And here are the events I have tried:

⎕NQ 'f.menuBar.menu' 'Select' ⋄ ⎕DL 0.5 ⋄ ⎕NQ 'f.menuBar.menu.miB' 'Select'

Any clues?

(Remark: in this particular example, if we wanted to simulate a click on, say, "Choice Y", it isn't actually necessary to first ⎕NQ "One" and "Choice B", but ideally, we'd like to see choices being made in the GUI as if an actual user made them.)

August Karlstrom
  • 10,773
  • 7
  • 38
  • 60
  • Try 1 as a left arg to ⎕NQ. Also try putting your test code in a function, not interactively in the session. – Paul Mansour Feb 15 '22 at 15:20
  • @PaulMansour Thanks for the suggestion. It makes no difference unfortunately. – August Karlstrom Feb 15 '22 at 15:34
  • I think this may not work because the menu and the menubar objects do not really support the Select event the same way a menu item does. For example I don't think you can attach a callback. You might try firing keystrokes instead of select. – Paul Mansour Feb 15 '22 at 15:39
  • If you examine the event viewer, it looks like only the dropdown and expose events are being recorded, so keypress event is probably a nonstarter. Maybe it can be done with those two events. – Paul Mansour Feb 15 '22 at 15:56

1 Answers1

0

I asked John Daintree, the implementer and maintainer of ⎕WC, ⎕NQ etc. if it is possible to automate user interaction using ⎕NQ. His response was:

Not completely. You can do some things, but not everything. So it's not really viable as a way of testing [progressive selection from menus].
(…)
The next problem that you'll hit is that the interpreter won't process the next event (…), because the interpreter can't do anything while the menu is down.

Maybe have a look at Microsoft Power Automate or AutoHotKey instead?

Adám
  • 6,573
  • 20
  • 37
  • You can go a very, very long way testing the GUI with ⎕NQ. You will run into some issues like this menu problem, but precisely because there is really no interaction between the interpreter and the menu, until you hit a menu item, there is nothing really there to test. You will get much, much farther and faster testing GUI directly in Dyalog with ⎕NQ than you will by a third party tool. They ability to fire events and immediately see if the result is as expected right in your own APL test function is invaluable. Yes there will be gotchas but many less than any other approach. – Paul Mansour Feb 15 '22 at 16:30
  • I bow to no one in my admiration of Daintree, but when he says "So it's not really viable as a way of testing things" its not true! – Paul Mansour Feb 15 '22 at 16:31
  • @PaulMansour Thank you for that comment. Indeed, John was only talking about menu bar interactions. I'll edit my post to make that clear. Indeed, per OP's final remark, it doesn't sound like he wants to test things, but rather wants to "play a movie" of simulated user interaction with the menu. And for that, `⎕NQ` won't do the job. – Adám Feb 15 '22 at 16:33