Page 1 of 1

Issue Dragging and Dropping 2 objects one after another

Posted: Tue Feb 26, 2019 1:20 pm
by JimLin
Hi,

Ranorex version: 8.2.1 (We are not yet in a position to move to version 9)
Ranorex Automation Helpers version: 1.5.1
Windows 10

I have just discovered an issue with the DragAndDrop Ranorex Automation Helper.

My application is an Excel 2016 addin and in this test I am interacting with a WPF popup which allows me to repivot items between axes. In my test I have a module in which:
In step one I drag and drop an object from field 1 to field 2
In step two I drag and drop a second object from field 2 to field 1

What happens more often than not is that the first D&D from field 1 to field 2 completes successfully, but the second drag and drop from field 2 to field 1 straight after is not fully actioned. Ranorex appears to locate and press 'ButtonDown', but then the mouse move doesn't happen and the test doesn't continue (but does't really hang and the test doesn't fail). However, the moment you manually move the mouse, the 'move' action happens and the step completes successfully.

What I have done as a workround that seems to work every time, is based on Marcus' reply to a different problem in this thread: getting-mouseposition-t3689.html, in which he suggests storing the current mouse x/y coordinates and then moving the pointer 10 pixels. This is enough to replicate the manual mouse move and the test step completes successfully.

My updated code looks like this:

Code: Select all

 [UserCodeCollection]
    public static class DragNDropLibrary
    {
        /// <summary>
        /// Picks the source element, drags it to the target element and drops it there.
        /// <param name="source">The element which should be dragged.</param>
        /// <param name="target">The element where the source element will be dropped.</param>
        /// </summary>
        [UserCodeMethod]
        public static void DragAndDrop(Adapter source, Adapter target)
        {
            Report.Info(string.Format("Drag from {0}", source));
            source.Focus();
            source.MoveTo();
            Mouse.ButtonDown(System.Windows.Forms.MouseButtons.Left);
            
            // Workround for issue where second drag and drop isn't actioned when
            // two DragNDrops are used one after another
            int x,y;  
			x = Mouse.Position.X;  
			y = Mouse.Position.Y;  
			Point point = new Point((x+5),y);  
			Mouse.MoveTo(point);  
            
            // fix issue if moving to an inactive window.
            Point currentPoint = Mouse.Position;
            currentPoint.X += 5;
            Mouse.MoveTo(currentPoint);

            Report.Info(string.Format("Drop at {0}", target));
            target.Focus();
            target.MoveTo();
            Mouse.ButtonUp(System.Windows.Forms.MouseButtons.Left);
        }
    }
Step 1 DragNDrop object from field 1 to field 2.png

Re: Issue Dragging and Dropping 2 objects one after another

Posted: Tue Feb 26, 2019 1:24 pm
by JimLin
I was unable to post the second and third images to the initial post:
First object dragged and dropped in field 2.png

Re: Issue Dragging and Dropping 2 objects one after another

Posted: Tue Feb 26, 2019 1:24 pm
by JimLin
Step 2 DragNDrop second object from field 2 to field 1.png

Re: Issue Dragging and Dropping 2 objects one after another

Posted: Fri Mar 01, 2019 1:32 pm
by qwertzu
Hi,

Do you execute your tests remotely over rdp?
I also faced strange mouse behaviors, but when releaseing the focus of the rdp window (by clicking on the local desktop next to the RDP window after starting the test) everything works fine. Seems to be some kind of rdp related.

However, in the release notes I saw that Ranorex 9 comes with some mouse action improvements.
So, it could be that your issue won't appear after an update anymore.

regards, qwertzu