Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

Automating a smooth drag and drop action

Automating a smooth drag and drop action

In some instances an application may require that a smooth drag and drop action be performed to allow events such as  "mouse leave" to fire successfully within the application under test. Generally when using Silk Test, a drag and drop action is perform in the following way:

wWin.PressMouse(1)
wWin2.ReleaseMouse(1)

When using the above approach, the "ReleaseMouse" action may potentially prevent events such as "mouse leave" from firing successfully within the application under test. This is caused as the mouse pointer is directly transported to a particular coordinate on screen, rather than being moved in a user like fashion to the desired location. In instances such as these we must create a user defined function to perform a "smooth" drag and drop action.

The example below highlights how this can be achieved in Silk Test Classic:

[-] void SmoothDrag_n_Drop(window wToBeDragged, window wDragTo)
     [ ] RECT rDragToPos = wDragTo.GetRect(TRUE)
     [ ]
     [ ] int iXPos = rDragToPos.xPos + (rDragToPos.xSize/2)
     [ ] int iYPos = rDragToPos.yPos + (rDragToPos.ySize/2)
     [ ]
     [ ] wToBeDragged.PressMouse(1)
     [ ]
     [ ] int iCurXPos = Cursor.GetPosition().x
     [ ] int iCurYPos = Cursor.GetPosition().y
     [ ]
     [-] while(iCurXPos != iXPos || iCurYPos != iYPos)
          [ ]
          [-] if(iXPos > iCurXPos)
               [ ] iCurXPos++
          [-] else
               [-] if(iXPos < iCurXPos)
                    [ ] iCurXPos--
          [ ]
          [-] if(iYPos > iCurYPos)
               [ ] iCurYPos++
          [-] else
               [-] if(iYPos < iCurYPos)
                    [ ] iCurYPos--
          [ ]
          [ ] Desktop.MoveMouse(iCurXPos, iCurYPos)
     [ ]
     [ ] Desktop.ReleaseMouse(1, iCurXPos, iCurYPos)

In the above example function, the window wToBeDragged is dragged incrementally to the centre of wDragTo, which successfully allows the application to invoke/fire mouse events such as "mouse leave".

smoothDnD.zip

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2014-11-05 15:39
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.