question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

touchPerform actions processed separately: could not do swipe.

See original GitHub issue

The problem

Basic test - trying to do swipe (from right to left) in Android app (React Native):

const windowSize = await driver.getWindowSize();

const right2leftSwipeOptions = {
        startX: windowSize.width * 0.9,
        startY: windowSize.height / 2,
        endX: windowSize.width * 0.1,
        endY: windowSize.height / 2
      };

await driver.touchPerform([
        {
          action: "press",
          options: {
            x: right2leftSwipeOptions.startX,
            y: right2leftSwipeOptions.startY
          }
        },
        {
          action: "moveTo",
          options: {
            x: right2leftSwipeOptions.endX,
            y: right2leftSwipeOptions.endY
          }
        },
        { action: "release" }
      ]);

All is according to your docs: sample for WebdriverIO. Only 3 actions: press, moveTo, release.

So, nothing happens - no actual swiping! See gist#1 with Appium log. In log we could see that every action processed separately! But stop, description for touchPerform clearly says that:

‘Touch Perform’ works similarly to the other singular touch interactions, except that this allows you to chain together more than one touch action as one command. This is useful because Appium commands are sent over the network and there’s latency between commands. This latency can make certain touch interactions impossible because some interactions need to be performed in one sequence.

Okay, I spent 2 days to do something useful but not invented nothing more than almost randomly add 1 new action to my touchPerform sequence - wait. Now my code looks like this:

const windowSize = await driver.getWindowSize();

const right2leftSwipeOptions = {
        startX: windowSize.width * 0.9,
        startY: windowSize.height / 2,
        endX: windowSize.width * 0.1,
        endY: windowSize.height / 2,
        delay: 0
      };

await driver.touchPerform([
        {
          action: "press",
          options: {
            x: right2leftSwipeOptions.startX,
            y: right2leftSwipeOptions.startY
          }
        },
        { action: "wait", options: { mseconds: right2leftSwipeOptions.delay } },
        {
          action: "moveTo",
          options: {
            x: right2leftSwipeOptions.endX,
            y: right2leftSwipeOptions.endY
          }
        },
        { action: "release" }
      ]);

And now swipe is working! Check gist#2 with Appium log. Now Appium works with all actions in 1 sequence! As it should be!

So, there are my questions/remarks:

  1. Why first code is not working as 1 sequence?
  2. Why in your documentation not working example?
  3. Why adding “wait” solved problem? Is it important where exactly put “wait” in sequence order?
  4. Why delay is could be any number without any difference in result: 0, 100, 1000, 5000? Actually there is no delay for 5 seconds - swipe would be done always with same time.
  5. Why in gist#1 we could see that Appium “Shutting down because we waited 60 seconds for a command” almost immediately? And in gist#2 all is good: shutting down really comes after 60 seconds?

Environment

  • Appium version: 1.10.0
  • Desktop OS/version used to run Appium: MAC OS X 10.10.5
  • Mobile platform/version under test: Android
  • Real device or emulator/simulator: Real device (Honor 8 Android 7 API 24)
  • Appium CLI or Appium.app|exe: Appium.app

Link to Appium logs

  1. Appium log with Bad reaction to performTouch
  2. Appium log with Good reaction to performTouch

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:25 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
amokmencommented, Mar 6, 2019

I can’t find a working guide on how to scroll on both platforms … all methods I’ve found are not working.

Welcome to my world of pain 😃

a proper doc that explain

There are no such docs and this is main problem 😦

Now I am using for iOS (XCUITest) this code:

await driver.executeScript("mobile: swipe", [{ direction: "left" }]);

and for Android (UiAutomator2) this one:

await driver.touchPerform([
        {
          action: "press",
          options: {
            x: startX,
            y: startY
          }
        },
        { action: "wait", options: { mseconds: 0 } },
        {
          action: "moveTo",
          options: {
            x: endX,
            y: endY
          }
        },
        { action: "release" }
      ]);

And this is rather bad… Because as I could understand - main Appium purpose should be next words: “One code for both platforms”.

0reactions
PTOBcommented, Mar 5, 2020

EDIT: Using UIAutomator2

Was having trouble with this myself, where swipe would not work at all across different widgets Adding a wait action of 0ms returned

Original error: Cannot read property ‘ms’ of undefined

but the following works for me every time.

browser.touchAction([
      { action: 'press', x: 681, y: 2300 },
      { action: "wait",  ms: 1000 },
      { action: 'moveTo', x: 681, y: 100 },
      'release'
    ]);

To answer question 4 in the Original Post

Why delay is could be any number without any difference in result: 0, 100, 1000, 5000? Actually there is no delay for 5 seconds - swipe would be done always with same time.

The wait does not act as you would expect. Rather than act like a pause, it is actually how long it takes for the swipe from point A to point B (speed of swipe)

So a wait of 0ms would be instentanious and probably why it should not be used.

Try it out with 1ms 500, 1000, 10000 and you will clearly see the difference in swiping speed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unknown command : touch/perform - Support - Appium Discuss
Hi, After some try with the php-client, I switch to the java client as I'm facing an error when using swipe. But now...
Read more >
appium/appium - Gitter
Hi all, I try to swipe fast and hold touch for a while to prevent slip. by using TouchAction with sequence [press ->...
Read more >
How to Use Touch Actions in Appium: Swipe Tap Touch
I did not have any drag method example but if you will have would you share with us with a comment? Then I...
Read more >
Appium 1.0-beta Java Client - Google Groups
You can use it mostly the same way you use the selenium WebDriver (or RemoteWebDriver) classes. I'm working right now on updating the...
Read more >
Bountysource
touchPerform actions processed separately : could not do swipe.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found