I got a call today, from none other than one of the top security testing firms in the world. And they are leveraging Eggplant to unobtrusively test devices and systems leveraging VNC enabled KVM switches. This gives a level of abstraction which with todayās fast computers can cause the KVM interpretation of events to get out of sync with the remote SUT. Most of the higher quality KVM manufactures, Adder, Raritan have syncronization features forcing the mapping of events before continuing (much like an event queue āflushā command). In most cases this works well. However in some limited cases its best to allow the KVM time to catch up as if a real world person were using the system under test.
To do so, our friends were using a handler aptly called MyClick, and of course a replacement for the venerable Eggplant Click command. MyClick was a simulation of the Click command, moving the cursor first on the SUT, then waiting a period of time (0.7 seconds in their case worked well), and then clicking where the mouse was located.
to MyClick anImage
MoveTo anImage
Wait 0.7
Click -- at the cursor location
end MyClick
This works well, yet requires a script developer to rename all automated scripting performed in the capture/script sequence of auto script, from Click to MyClick. We can do this simple enough with Eggplantās script window find and replace features, while introducing potential for errors, incompleteness and forgetfulness in performing the chore, or myspelling or typos. Any way you slice this task, settling for faulty and error prone test suites is not proper practice.
To help solve this challenge, there are some powerful message passing features which can be used within SenseTalk which allow you to take control where messages are sent or even passed. One way to intercept commands is by using the āstart using scriptNameā in SenseTalk placing the scriptName.script in the backscripts of the message path. The backscripts allow messages to be handled prior to their arrival at the SenseTalk runtime. This gives us the power to override and act upon a message we feel needs to be replaced in the SenseTalk system, or having it globally changes/altered.
There are other means to do this same thing, like the very powerful and often misunderstood 'to handle ā handler, for instance. In our case, we want to supplant the Click Command across the board injecting a time delay for the Adder switch box.
(** A handler to add a bit of delay in between the move and click of the Eggplant Click
command. We basically are replacing the Eggplant Click Command
@param n optional delay value in seconds
@param images the image list to find and click
**)
params n, images...
-- if a delay is provided, use it, otherwise assume an image
-- and insert it into the images list for use in a loop
if n is a positive number then
set omtcd to universal MoveToClickDelay -- store univ delay if n is provided.
set universal MoveToClickDelay to n
else
insert n before images
end if
-- for each image, move, delay and click at it.
repeat with each item image in images
MoveTo image
Wait universal MoveToClickDelay
send Click FoundImageLocation() to SenseTalk -- send to ST runtime, avoid recursion.
end repeat
if omtcd is a number then set universal MoveToClickDelay to omtcd
Naming the above Click.script (its in the provided project suite), we can use it in any script by issuing the āstart using clickā where the click script is in a helper suite our main suite, or is part of the main suite itself.
-- set a delay here, you can set it at any point, our replacement script will
-- use this value to delay xyz seconds.
start using Click -- put our click handler into backscripts.
set universal MoveToClickDelay to 5.0 second -- time to wait from move to click
Click TextEdit -- Click with delay using the universal MoveToClickDelay
TypeCommand "q" -- quit TextEdit program
Click 1, TextEdit -- Click using our override handler with a delay parameter.
TypeCommand "q"
send Click TextEdit to SenseTalk -- bypass our handler, go directly to ST runtime.
TypeCommand "q"
In this case, we see 3 different ways to get various results with move, delay and click transparently (or mostly) from our system without renaming handlers or calls that we have in older or legacy scripts. You can see we set up the universal MoveToClickDelay to a suitable delay time for the KVM switch to clear out the event queue. Then just as we have before, we make calls to the Click (our handler) which is used by issuing the āstart using Clickā command.
The astute Eggplant test developer will also notice in the 2nd invocation there is an override value of 1 being used for the delay value. This will override the universal MoveToClickDelay, without changing the value permanently when called. You can set your universal MovetoClickDelay value and in some special cases where delay times can or should be changed for tuning purposes. You could also just call your Click command with an initial parameter value less or more as needed. Maybe finding the right value is a matter of using a repeat loop and issuing a few commands, leveraging the new delay value override of this Click command.
Finally, the last Click example command is sent directly to SenseTalk in which no override handler traps the message. Direct sends are powerful in this context, as you may not want your own handler most of the time, yet at times Eggplantās native or direct handlers are necessary for performance and speed tuning when the KVM is bogged down or the added functionality of the override command are not desired.