tristaanogre's avatar
Esteemed Contributor
7 years ago
New Idea

Implement and Object-To-Object Mouse Drag capability for both script and keyword tests.

Currently, the mouse "Drag" method drags from a starting co-ordinate a set X distance and Y distance from that starting co-ordinate.  For most "normal" drag functionalities, this is sufficient.  I even wrote some code with help from folks up here that, given a starting object and a destitination object, will drag from one to the other.


function dragCalculatedDistance(startObject, destinationObject) {
    var startPoint, targetPoint, dragX, dragY;
    // Drag from the center of object A to the center of object B

    startPoint = startObject.WindowToScreen(startObject.Width/2, startObject.Height/2);
    targetPoint = destinationObject.WindowToScreen(destinationObject.Width/2, destinationObject.Height/2);

    dragX = targetPoint.X - startPoint.X;
    dragY = targetPoint.Y - startPoint.Y;

    startObject.Drag(-1, -1, dragX, dragY); 

The problem is this...  We have a situation where we need to drag an object that is present below a table in our application to a particular cell in the table.  In that process, when we cross the lower border of the table, the table may auto-scroll down to reveal other rows.  Because the above function just drags to a calculated set of co-ordinates, the end result is that we end up dropping the object on the wrong row in the table.


Proposed Solution: A drag functionality for TestComplete where, instead of dragging based upon a co-ordinate distance, actually drag from one object to another... something like



where the two objects are identified onscreen objects.  This would resolve the auto-scroll because it would actually drag to the particular cell we want and not to just a set of on-screen co-ordinates.


Low priority change to make... and I'm open to other code that would make this work better for us.  But I think this would be "cool" as it would mean that my custom code above wouldn't be necessary any more and we could have "smart" drag-and-drop functionality.




  • jferreira's avatar
    Occasional Contributor

    I've had a similar problem and solved it by first clicking the destination cell, then determining the mouse position on screen and use those coordinates for the drag operation.

    Something like this:


    function informedTreeDrag(tree,destinationTbl,dragobject,row,col)
      tree.ClickItem(dragobject, skNoShift);
      var a = tree.get_MousePosition();
      a.set_X(a.X - tree.ScreenLeft);
      a.set_Y(a.Y - tree.ScreenTop);

      var b = destinationTbl.get_MousePosition();
      b.set_X(b.X - tree.ScreenLeft);
      b.set_Y(b.Y - tree.ScreenTop);

  • tristaanogre's avatar
    Esteemed Contributor

    That is what my code above does... however, the problem is the auto-scroll... when the table scrolls, the co-ordinates of the cell are changed and the destination values are no longer current.  Thanks for the suggestion but my code above already does it and, currently, is insufficient for this particular problem.


    I'm looking into using a LLPlayer methods to do a bit more of a checking...   I'd do a click and drag using LLPlayer MouseDown and MouseMove... and then, before doing MouseUp, I'd check the position of the destination object again, adjust the X,Y co-ordinates, do another MouseMove if necessary, and then do MouseUp.


    If I get it to work, I'll post the code... but it would be nice to have a DragTo method as described so I wouldn't have to.

  • tristaanogre's avatar
    Esteemed Contributor

    FYI, please upvote if you like the idea... the more votes, the more likelihood that this will get implemented.

  • In my opinion, this is a very important feature. I am surprised that this feature does not exist yet.

  • mfremont-smith's avatar
    Occasional Contributor

    tristaanogre - I like this idea. As a workaround, if you do an explicit scrollIntoView before calculating the coordinates for the start and destination objects, you should be good. The fn below works for me.

    DragAndDrop(dragObject, droppableObject) {
    //Wait for drag and drop objects to be enabled
    dragObject.WaitProperty("Enabled", true);
    droppableObject.WaitProperty("Enabled", true);
    //Scroll dragObject into view before coordinates are calculated
    let dragX = dragObject.Width/2;
    let dragY = dragObject.Height/2;
    let dragObjectLeft = dragObject.Left;
    let dragObjectTop = dragObject.Top;
    //Scroll droppableObject into view before coordinates are calculated
    let dropX = droppableObject.Left - dragObjectLeft + droppableObject.Width/2;
    let dropY = droppableObject.Top - dragObjectTop + droppableObject.Height/2;
    dragObject.Drag(dragX, dragY, dropX, dropY);