Forum Xamarin Test Cloud (Read Only)

DragCoordinates, DragAndDrop or SwipeLeftToRight to move an element in iOS - UITest

I have been struggling with creating a method to move an object past another in iOS. The test works in Android and this is a Xamarin.Forms app.

Using code similar to this:
_app.DragCoordinates(object1centerX, object1centerY, (object2centerX + 5), object2centerY);

_app.DragAndDrop(x => x.Marked(object1styleId), x => x.Marked(object2styleId));

In my iOS test, it is resizing which ever object has focus at the time of the DragCoordinates call. If I tap object1 first, it resizes larger. If I leave focus on object2, it resizes smaller from the left edge. The two samples above have the same results.

Best Answer


  • Glenn.WilsonGlenn.Wilson USXamarin Team Xamurai

    @JimmyHarden.7567 Xamarin.UITest 1.3.2 added a configurable DragAndDrop to iOSApp that allows you to specify a duration. There is also a DragCoordinates method that takes a duration parameter on iOSApp. Maybe one of those would help?

    You'll need to cast your _app to an iOSApp to get the version that includes duration.

    Add simple DragAndDrop() to IApp and a configurable version to iOSApp (AndroidApp already has a configurable version).

  • @Glenn.Wilson The duration paramater is definitely helpful. I can get object1 to move without resizing, but when the drag stops, it goes back to its original position. Any ideas here?

    var dragDuration = new TimeSpan(0, 0, 0, 5, 0);

            if (_platform == Platform.iOS)
                ((Xamarin.UITest.iOS.iOSApp)_app).DragCoordinates((object1centerX), object1centerY, (object2centerX + 5), object2centerY, dragDuration);
  • @Glenn.Wilson - have you had any chance to look into this? Any ideas why the object is not being dropped into its new position?

  • Glenn.WilsonGlenn.Wilson USXamarin Team Xamurai


    when the drag stops, it goes back to its original position

    What happens if you do an equivalent drag manually?

    I would try different drag durations and different drag distances. If I couldn't get that to work I would consider implementing a backdoor if the point is to change state and not test dragging, per se: Backdoors

  • @Glenn.Wilson
    With a manual drag, the object is dropped into the new location and the two objects swap places.

Sign In or Register to comment.