Drag and drop with Appium 1.1.0

633 views
Skip to first unread message

ytonthat

unread,
Jun 3, 2014, 4:46:31 PM6/3/14
to appium-...@googlegroups.com
To perform a drag and drop with the C# client, I tried these approaches:

1)  Calling the following methods which use 

            var action = TouchActions.DragAndDropToOffset(IWebElement, int, int);
  action.Perform();

2) Using a multitouch operation

        public static void DragAndDrop(this AppiumDriver driver, Location start, Location end)
        {
            var action = new TouchActions(driver).Down(start.X, start.Y)
                                                        .Move(end.X, end.Y)
                                              .Up(end.X, end.Y);

            var multiTouchAction = new MultiTouchAction(driver);
            multiTouchAction.Add(action);

            driver.PerformMultiTouchAction(multiTouchAction);
        }



With approach 1, I get an error server-side because the operation has not been implemented yet.

With approach 2, I get an unknown server-side error. Here are some traces from Appium 1.1.0:

debug: Appium request initiated at /wd/hub/session/c77dfdfc-92b3-41c5-ae3e-66e44
2eb3ae0/touch/multi/perform
debug: Request received with params: {"actions":[[{"action":"press","options":{"
x":380,"y":242}},{"action":"moveTo","options":{"x":1210,"y":881}},{"action":"rel
ease","options":{}}]]}
info: Pushing command to appium work queue: ["performMultiPointerGesture",{"acti
ons":[[{"touch":{"x":380,"y":242},"time":0.005},{"touch":{"x":1590,"y":1123},"ti
me":0.01}]]}]
info: [BOOTSTRAP] [info] Got data from client: {"cmd":"action","action":"perform
MultiPointerGesture","params":{"actions":[[{"touch":{"x":380,"y":242},"time":0.0
05},{"touch":{"x":1590,"y":1123},"time":0.01}]]}}
info: [BOOTSTRAP] [info] Got command of type ACTION
info: [BOOTSTRAP] [debug] Got command action: performMultiPointerGesture
info: [BOOTSTRAP] [debug] Updating class "class com.android.uiautomator.core.UiD
evice" to enable field "mUiAutomationBridge"
info: [BOOTSTRAP] [debug] Updating class "class com.android.uiautomator.core.UiA
utomatorBridge" to enable field "mInteractionController"
info: [BOOTSTRAP] [debug] Finding methods on class: class com.android.uiautomato
r.core.InteractionController
info: [BOOTSTRAP] [debug] Exception: java.lang.reflect.InvocationTargetException

info: [UIAUTOMATOR STDOUT] java.lang.reflect.InvocationTargetException
info: [UIAUTOMATOR STDOUT] at
info: [UIAUTOMATOR STDOUT] java.lang.reflect.Method.invokeNative(Native Method)
info: [UIAUTOMATOR STDOUT] at
info: [UIAUTOMATOR STDOUT] java.lang.reflect.Method.invoke(Method.java:515)
info: [UIAUTOMATOR STDOUT] at
info: [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.handler.MultiPointerGestu
re.execute(MultiPointerGesture.java:46)
info: [UIAUTOMATOR STDOUT] at
info: [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.AndroidCommandExecutor.ex
ecute(AndroidCommandExecutor.java:94)
info: [UIAUTOMATOR STDOUT] at
info: [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.SocketServer.runCommand(S
ocketServer.java:170)
info: [UIAUTOMATOR STDOUT] at
info: [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.SocketServer.handleClient
Data(SocketServer.java:91)
info: [UIAUTOMATOR STDOUT] at
info: [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.SocketServer.listenForeve
r(SocketServer.java:135)
info: [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.Bootstrap.testRunServe
r(Bootstrap.java:17)
info: [UIAUTOMATOR STDOUT] at java.lang.reflect.Method.invokeNative(Native Metho
d)
info: [UIAUTOMATOR STDOUT] at
info: [UIAUTOMATOR STDOUT] java.lang.reflect.Method.invoke(Method.java:515)
info: [UIAUTOMATOR STDOUT] at junit.framework.TestCase.runTest(TestCase.java:168
)
info: [UIAUTOMATOR STDOUT] at junit.framework.TestCase.runBare(TestCase.java:134
)
info: [UIAUTOMATOR STDOUT] at
info: [UIAUTOMATOR STDOUT] junit.framework.TestResult$1.protect(TestResult.java:
115)
info: [UIAUTOMATOR STDOUT] at junit.framework.TestResult.runProtected(TestResult
.java:133)
info: [UIAUTOMATOR STDOUT] at junit.framework.TestResult.run(TestResult.java:118
)
info: [UIAUTOMATOR STDOUT] at
info: [UIAUTOMATOR STDOUT] junit.framework.TestCase.run(TestCase.java:124)
info: [UIAUTOMATOR STDOUT] at
info: [UIAUTOMATOR STDOUT] com.android.uiautomator.testrunner.UiAutomatorTestRun
ner.start(UiAutomatorTestRunner.java:160)
info: [UIAUTOMATOR STDOUT] at
info: [UIAUTOMATOR STDOUT] com.android.uiautomator.testrunner.UiAutomatorTestRun
ner.run(UiAutomatorTestRunner.java:96)
info: [UIAUTOMATOR STDOUT] at
info: [UIAUTOMATOR STDOUT] com.android.commands.uiautomator.RunTestCommand.run(R
unTestCommand.java:91)
info: [UIAUTOMATOR STDOUT] at
info: [UIAUTOMATOR STDOUT] com.android.commands.uiautomator.Launcher.main(Launch
er.java:83)
info: [UIAUTOMATOR STDOUT] at
info: [UIAUTOMATOR STDOUT] com.android.internal.os.RuntimeInit.nativeFinishInit(
Native Method)
info: [UIAUTOMATOR STDOUT] at
info: [UIAUTOMATOR STDOUT] com.android.internal.os.RuntimeInit.main(RuntimeInit.
java:248)
info: [UIAUTOMATOR STDOUT] at dalvik.system.NativeStart.main(Native Method)
info: [UIAUTOMATOR STDOUT] Caused by:
info: [UIAUTOMATOR STDOUT] java.lang.IllegalArgumentException: Must provide coor
dinates for at least 2 pointers
info: [UIAUTOMATOR STDOUT] at com.android.uiautomator.core.InteractionController
.performMultiPointerGesture(InteractionController.java:689)
info: [UIAUTOMATOR STDOUT] ...
info: [UIAUTOMATOR STDOUT] 23
info: [UIAUTOMATOR STDOUT] more
info: [BOOTSTRAP] [info] Returning result: {"status":13}
info: Responding to client with error: {"status":13,"value":{"message":"An unkno
wn server-side error occurred while processing the command."},"sessionId":"c77df
dfc-92b3-41c5-ae3e-66e442eb3ae0"}
POST /wd/hub/session/c77dfdfc-92b3-41c5-ae3e-66e442eb3ae0/touch/multi/perform 50
0 46ms - 176b
debug: Appium request initiated at /wd/hub/session/c77dfdfc-92b3-41c5-ae3e-66e44
2eb3ae0
debug: Request received with params: {}
info: Shutting down appium session...
info: [ADB] Pressing the HOME button
debug: executing: "C:\adt-bundle-windows-x86_64-20140321\sdk\platform-tools\adb.
exe" -s 571b26df062a824b shell "input keyevent 3"
info: Stopping logcat capture
debug: Logcat terminated with code null, signal SIGTERM
info: [BOOTSTRAP] [info] Got data from client: {"cmd":"shutdown"}
info: [BOOTSTRAP] [info] Got command of type SHUTDOWN
info: [BOOTSTRAP] [info] Returning result: {"value":"OK, shutting down","status"
:0}
info: [BOOTSTRAP] [info] Closed client connection
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=.
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.boots
trap.Bootstrap
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 0
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=.
info: [UIAUTOMATOR STDOUT] Time: 386.542
info: [UIAUTOMATOR STDOUT] OK (1 test)
info: Sent shutdown command, waiting for UiAutomator to stop...
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
info: UiAutomator shut down normally
info: Cleaning up android objects
info: Cleaning up appium session
info: Responding to client with success: {"status":0,"value":null,"sessionId":"c
77dfdfc-92b3-41c5-ae3e-66e442eb3ae0"}
DELETE /wd/hub/session/c77dfdfc-92b3-41c5-ae3e-66e442eb3ae0 200 811ms - 89b


Am I not able to do a drag and drop simply because it is not available yet? Or am I doing it the wrong way?

Thanks!

Isaac Murchie

unread,
Jun 3, 2014, 6:03:20 PM6/3/14
to ytonthat, appium-...@googlegroups.com
Method 2 doesn't work because it is not a multi pointer gesture, which simulate multiple fingers doing an action. You only want a touch action, made of a long press, a move, and a release.


--
http://appium.io
---
You received this message because you are subscribed to the Google Groups "Appium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to appium-discus...@googlegroups.com.
Visit this group at http://groups.google.com/group/appium-discuss.
For more options, visit https://groups.google.com/d/optout.

ytonthat

unread,
Jun 4, 2014, 12:44:27 PM6/4/14
to appium-...@googlegroups.com, tontha...@gmail.com
I tried the following along the line of what you suggested

Method 1)

var action = new TouchActions(driver).Down(target.Location.X, target.Location.Y).LongPress(target).Move(end.X, end.Y).Up(end.X, end.Y);
action.Perform();

Method 2)

var action = new TouchActions(driver).LongPress(target).Move(end.X, end.Y).Up(end.X, end.Y);
action.Perform();


Both methods do not work because the Down and Move methods have not been implemented server side (1.1.0). I see the following traces:

Method 1)

debug: Appium request initiated at /wd/hub/session/6a53971b-c9b9-48d0-b5a3-9ecc5b72ce88/touch/down
debug: Request received with params: {"x":0,"y":162}
info: Responding to client that a method is not implemented
POST /wd/hub/session/6a53971b-c9b9-48d0-b5a3-9ecc5b72ce88/touch/down 501 1ms - 180b


Method 2)

debug: Appium request initiated at /wd/hub/session/6a53971b-c9b9-48d0-b5a3-9ecc5b72ce88/touch/move
debug: Request received with params: {"x":1210,"y":881}
info: Responding to client that a method is not implemented
POST /wd/hub/session/6a53971b-c9b9-48d0-b5a3-9ecc5b72ce88/touch/move 501 2ms - 180b


Any other suggestions? :)

ytonthat

unread,
Jun 4, 2014, 12:48:30 PM6/4/14
to appium-...@googlegroups.com, tontha...@gmail.com
I tried using a multitouch action with only one instance of touchaction because an example here: https://github.com/appium/appium/blob/master/docs/en/appium-bindings.md

I documentation might have to be updated if indeed we shouldn't add only one touchaction to a multitouch action :S


On Tuesday, 3 June 2014 18:03:20 UTC-4, Isaac Murchie wrote:

Isaac Murchie

unread,
Jun 4, 2014, 3:28:01 PM6/4/14
to ytonthat, appium-...@googlegroups.com
There might be a TouchActions and a TouchAction class. I don't know enough about the C# bindings. But there is an old API in Selenium that in most languages is implemented as TouchActions. Appium does not support that API.

Fred

unread,
Jun 6, 2014, 12:51:57 PM6/6/14
to appium-...@googlegroups.com, tontha...@gmail.com
I am encountering similar problems as ytonthat

The following...

           var action = new TouchActions(driver).Down(600, 200).Move(0, 200).Up(0, 200);
            swipeLeftAction.Add(action);

           whether or not i use swipeLeftAction.Perform(); or driver.PerformMultiTouchAction(swipeLeftAction);
             
           the error is  Additional information: Unexpected error.
   

           

Kevin Cleathero

unread,
Jun 6, 2014, 1:09:35 PM6/6/14
to appium-...@googlegroups.com, tontha...@gmail.com
I just noticed the .net driver went to version 1.0 today. Will install that and try again. 


--
http://appium.io
---
You received this message because you are subscribed to a topic in the Google Groups "Appium-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/appium-discuss/oDTwg9-rgyg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to appium-discus...@googlegroups.com.

Fred

unread,
Jun 6, 2014, 1:53:33 PM6/6/14
to appium-...@googlegroups.com, tontha...@gmail.com
So i installed .net version 1.0 and tried

            var action = new TouchAction(driver);
            action.Tap(xCoord, yCoord);
            action.Perform();

still produces an Unexpected error. Am I doing something wrong or...?



On Friday, June 6, 2014 10:09:35 AM UTC-7, Fred wrote:
I just noticed the .net driver went to version 1.0 today. Will install that and try again. 
To unsubscribe from this group and all its topics, send an email to appium-discuss+unsubscribe@googlegroups.com.

ytonthat

unread,
Jun 6, 2014, 3:38:56 PM6/6/14
to appium-...@googlegroups.com, tontha...@gmail.com
I just tried the C# client 1.0.0 and appium 1.1.0. I used this extension method for tapping and it works fine:


        public static void Tap(this AppiumDriver driver, Location location)
        {
            if (driver == null)
            {
                throw new ArgumentNullException("driver");
            }

            if (location == null)
            {
                throw new ArgumentNullException("location");
            }

            ITouchAction action = new TouchAction(driver).Tap(location.X, location.Y);
            action.Perform();
To unsubscribe from this group and all its topics, send an email to appium-discus...@googlegroups.com.

ytonthat

unread,
Jun 6, 2014, 3:39:17 PM6/6/14
to appium-...@googlegroups.com, tontha...@gmail.com
Drag and drops also works with this extension method


        public static void DragAndDrop(this AppiumDriver driver, Location start, Location end)
        {
            if (driver == null)
            {
                throw new ArgumentNullException("driver");
            }

            if (start == null)
            {
                throw new ArgumentNullException("start");
            }

            if (end == null)
            {
                throw new ArgumentNullException("end");
            }

            ITouchAction action = new TouchAction(driver).Press(start.X, start.Y)
                                                         .Wait(ms: 2000)
                                                         .MoveTo(end.X, end.Y)
                                                         .Release();
Reply all
Reply to author
Forward
0 new messages