Dragg and Drop on Winapp driver and Appium

Scenario

The basic scenario here is having a windows desktop application with the drag and drop capability.
Testing this application, you are using Appium over Winappdriver.
The test I am attending to perform is a simple drag and drop.

The above setting and scenario, isn't rare! actually it is a common case in desktop apps, that it is why it is so troubling to find that drag and drop is an issue.

Searching the web, I found many ways of accomplishing the D&D, which basically I can split to two groups, the first one is using the driver.Mouse actions, where I will use a mouseDown, mouseMove and MouseUp, the second method will use the Actions object and will consist of actions.dragAndDrop() (Yes, there is such a function), or will do it the long way of Actions.ClickAndHold().MoveTo().Release().

But it seems that in some cases, both approaches just don't work.
Let me be clear, this is a HUGE bug!
There is a workaround, but it is a huge bug (especially when having a non working actions.dragAndDrop()).

Outline

I will write here 7 options to write drag and drop, which will be split to the above 2 methods, then i will give a link to the problem as it is outlined by a frustrated stackoverflow user, and will finish with the working workaround.

First way - Using the session.Mouse

        public void dragAndDropMouse1(WindowsElement source, WindowsElement destination) {
            session.Mouse.MouseMove(source.Coordinates);
            session.Mouse.MouseDown(null);
            session.Mouse.MouseMove(destination.Coordinates);
            session.Mouse.MouseUp(null);
        }

        public void dragAndDropMouse2(WindowsElement source, WindowsElement destination) {
            session.Mouse.MouseDown(source.Coordinates);
            session.Mouse.MouseUp(destination.Coordinates);
        }

        public void dragAndDropMouse3(WindowsElement source, WindowsElement destination) {
            session.Mouse.MouseMove(source.Coordinates, 2, 2);
            session.Mouse.MouseDown(null);
            session.Mouse.MouseMove(destination.Coordinates, 2, 2);
            session.Mouse.MouseUp(null);
        }

Second way - Using the Actions

        public void dragAndDropAction1(WindowsElement source, WindowsElement destination) {
            actions.DragAndDrop(source, destination).Build().Perform();
        }

        public void dragAndDropAction2(WindowsElement source, WindowsElement destination) {
            new Actions(session).DragAndDrop(source, destination).Build().Perform();
        }

        public void dragAndDropAction3(WindowsElement source, WindowsElement destination) {
            new Actions(session).ClickAndHold(source).MoveToElement(destination).Release().Perform();
        }

        public void dragAndDropAction4(WindowsElement source, WindowsElement destination) {
            actions.MoveToElement(source).Perform();
            actions.ClickAndHold().Perform();
            actions.MoveToElement(destination).Perform();
            actions.Release().Perform();
        }

The actual problem can be found here in this stackoverflow thread

The Solution

    public void dragAndDropWorkaround(WindowsElement source, WindowsElement destination) {
            new Actions(session)
                .ClickAndHold(source)
                .MoveByOffset(1, 1)
                .MoveToElement(destination)
                .Release().Perform();
     }

The solution uses a slight move of the mouse cursor before completing the drop, this is a huge bug in Appium's code somewhere, and for now this workaround works

Comments

Popular posts from this blog

Profiling Java @ 2019

Shared/Pro/Managed Hosting for your site - which to choose ? (NO AFFILIATE LINKS!)

ZVR converter