0

I'm trying to write a test for a graphical component in Dyalog APL which will simulate button clicks which open new windows and keystrokes for filling in form fields. My first approach was to simply write a sequence of ⎕NQ statements for enqueuing events:

⎕NQ '#.foo.barButton' 'Select'   ⍝ open window
⎕NQ '#.foo.bar.bazTab' 'Select'  ⍝ select tab in opened window
....

The problem, however, is that ⎕NQ fails if the target object has not yet been displayed (for instance when opening a window):

VALUE ERROR: The event contains an invalid object or event name

I tried inserting a pause of a few seconds between the ⎕NQ statements but that didn't make any difference as the execution is synchronous.

What approach should I take?

August Karlstrom
  • 10,773
  • 7
  • 38
  • 60
  • Do you use ⎕DQ in the code being tested? ⎕DQ is the enemy of automated GUI testing. Especially if you want to trace through your test code. It is imperative that you have a test mode, and that ⎕DQ is by-passed in test mode. – Paul Mansour Nov 05 '18 at 15:12

2 Answers2

2

The problem here is that a monadic ⎕NQ "posts" a message to the internal queue. The first message hasn't been processed when you "NQ" the second message, so the target object has not yet been created. Use a left argument of 1 to ⎕NQ, which will "send" the message to the object rather than "post" it.

⎕NQ documentation

On my machine I've done the following:

'⎕se.mb.jd' ⎕wc 'MenuItem' 'jd' ('event' 'select' 'jd')

and I have a function jd:

∇jd a
[1]   'f'⎕WC'form'
∇

and a function foo:

∇foo
[1]   1 ⎕NQ'⎕se.mb.jd' 'select'
[2]    ⎕DL 5
[3]   'done'
∇

When I run foo, the window pops up immediately and then there is a 5 second delay before I see done in the session.

Can you try that? We'll then look at what you are doing differently.

  • Thanks for the answer. However this does not work as I would expect: If I run only the two statements 1 ⎕NQ '#.foo.barButton' 'Select' and then ⎕DL 5, nothing happens for five seconds and then the window is opened. – August Karlstrom Oct 22 '18 at 12:47
0

If the test function is called asynchronously (using the spawn operator "&"), the delays will work as expected:

∇ Test dummy
    ⎕NQ '#.foo.barButton' 'Select'   ⍝ open window
    :While 0=⎕NC '#.foo.bar.bazTab'
        ⎕DL 1
    :EndWhile
    ⎕NQ '#.foo.bar.bazTab' 'Select'  ⍝ select tab in opened window
    ....
∇

Test& 0

Update 2022-02-18: Inserted a loop which waits until the window is displayed.

August Karlstrom
  • 10,773
  • 7
  • 38
  • 60