[eggPlant Functional] DoubleClick and Drag

A customer recently asked: “I need to be able to double-click without releasing the mouse button and drag to another point on the screen. I just need a way to tell Eggplant not to release the mouse on the double-click.”

Eggplant’s DoubleClick command makes double-clicking easy but it doesn’t have any option to keep the mouse button down at the end. For that you’ll need to “roll your own” using the low-level MouseButtonDown and MouseButtonUp commands. The trick is to get the timing right for the double click, something that DoubleClick takes care of for you. The DoubleClick command includes a built-in delay between each mouse down and mouse up, and a different delay between the first and second clicks. Fortunately those delays are available as global properties in a script, so it’s pretty easy to get the desired result.

Here is a script that will do the job. Create a script with the name DoubleClickDrag and copy this code into it:

params dragImage -- the starting image or location

moveTo dragImage -- first move the mouse
put the remoteWorkInterval into origRWI -- save RWI
set the remoteWorkInterval to 0 -- take control of timing
mouseButtonDown 1 -- put the left button down
wait the mouseClickDelay
mouseButtonUp 1 -- let it up
wait the mouseDoubleClickDelay
mouseButtonDown 1 -- leave it down this time
set the remoteWorkInterval to origRWI -- restore RWI

With this script in your suite (or in a Helper suite) you can now use a DoubleClickDrag command in your scripts exactly the same way you would use Eggplant’s built-in Drag command:

DoubleClickDrag "dragStart"
Drop "dragFinish"

Notice that the DoubleClickDrag script carefully saves and restores the setting of the RemoteWorkInterval. The RWI is an important timing parameter in Eggplant that keeps it from sending events faster than the SUT can handle them. In this case it would slow things down too much for the double click to work properly, so we set it temporarily to zero. It’s important to restore it to its original value at the end so the rest of the script will work properly.

mouseButtonDown 1 -- put the left button down 
wait the mouseClickDelay 
mouseButtonUp 1 -- let it up

with a

Click

command?

Yes, doing a simple “Click” command should achieve the same thing as those three lines in my script. I wrote it all out to make it clear exactly what actions are being sent to the SUT, but it should give the same result. (For those who aren’t aware, a “Click” command with no parameters will simply click the mouse at its current location)