Swipe broken on 1.3.3? ios 8.1

updated to 1.3.3 this piece of code is broken now.

public static void swipeForward(WebDriver mDriver)
{  
    JavascriptExecutor js = (JavascriptExecutor) mDriver;
    HashMap<String, Double> swipeObject = new HashMap<String, Double>();
    swipeObject.put("startX", 0.95);
    swipeObject.put("startY", 0.5);
    swipeObject.put("endX", 0.05);
    swipeObject.put("endY", 0.5);
    swipeObject.put("duration", 1.8);
    js.executeScript("mobile: swipe", swipeObject);
}

trace:

org.openqa.selenium.WebDriverException: Not yet implemented. Please help us: http://appium.io/get-involved.html (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 7 milliseconds
Build info: version: '2.42.2', revision: '6a6995d31c7c56c340d6f45a76976d43506cd6cc', time: '2014-06-03 10:52:47'
System info: host: 'MTVL11fe50b4f', ip: '172.28.22.100', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.1', java.version: '1.7.0_45'
Session ID: e386e8f1-e55d-4b5c-9b6c-cc79e48067bb
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{newCommandTimeout=600, platformVersion=8.1, app=/Users/me/Desktop/appium/myapp.app, platform=MAC, databaseEnabled=false, javascriptEnabled=true, deviceName=iPhone 6 Plus, platformName=ios, browserName=, webStorageEnabled=false, networkConnectionEnabled=false, desired={newCommandTimeout=600, platformVersion=8.1, app=/Users/me/Desktop/appium/myapp.app, platformName=ios, deviceName=iPhone 6 Plus, browserName=}, locationContextEnabled=false, warnings={}, takesScreenshot=true}]
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
  at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
  at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
  at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
  at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:508)
  at com.xxx.xxx.swipeForward(Test.java:375)
  ...

go back to 1.3.1, everything is working again?
Am I doing anything wrong?

Also, the Appium.app Inspector ‘Swipe’ functionality is also not working with 1.3.3. It worked fine with 1.3.1.

I just re-verified that swipe is working fine in the Inspector and with the “mobile: swipe…” code on 1.3.1, so it’s something on 1.3.3 for sure.

people are reporting the same thing on github Appium issues.

Gave you tried using the “swipe” TouchActions methods, instead of using “mobile: swipe” javascript executors?

I haven’t. It is something new to me.
I have been using “mobile: swipe” for a while.
I will try.

Hi fangmobile,
doesn’t the driver.swipe() method works for you?
it works on my iPhone5 however i don’t know how to swipe on the simulator any idea?

driver.swipe() has been broken for me for a while that is when I switched to mobile:swipe javascript.

If if does not work for you then try the Touchaction suggested by Jonah.

does anyone know whether driver.swipe() is working for java client?

Hi jonahss,
can you PLS elaborate how to use the TouchActions class for Swipe?
The driver.swipe() works great on devices however seems broken for simulator.
Thanks…

@menypeled
you can find usage of TouchAction in the client code, for java:

But I am having trouble make it work. There is no action, test passes, but it did not do the swipe…

somehow it works when I do swipe left.

mDriver.swipe(screenWidth-100, screenHeight/2, 50, screenHeight/2, 1800);

but does not work when I try to swipe up, either using TouchAction or driver.swipe().

mDriver.swipe(screen Width/2, screenHeight-100, screenWidth/2, 200,  1800);

or

action.press(200, 600).waitAction(2000).moveTo(200, 180).release().perform();

screenWidth is 414 and screenHeight is 736.
It does not show error or exception, but does not do anything either.
@jonahss Am I doing something wrong for the swipe up case?

Also noticed driver.swipe() is just implemented by TouchAction, so if action.press().waitAction.moveTo().release().perform() does not work then swipe won’t work.

What puzzles me is: why swipe left work but swipe up does not?

confirming swiping down also work but no swiping up.
Using the TestApp and SimpleTest.java in Appium sample code repo, just add one test to swipe on the map view down and up for three times:

@Test
  public void testSwipe() throws Exception {
    final WebElement button = driver.findElement(By.name("Test Gesture"));
    button.click();
    final Alert alert = driver.switchTo().alert();
    alert.accept();
    driver.swipe(200, 400, 200, 200, 1000);
    driver.swipe(200, 200, 200, 400, 1000);
    driver.swipe(200, 400, 200, 200, 1000);
    driver.swipe(200, 200, 200, 400, 1000);
    driver.swipe(200, 400, 200, 200, 1000);
    driver.swipe(200, 200, 200, 400, 1000);
  }

You can see the map is swiped down three times but never swiped up.
Then I thought SimpleTest.java might be outdated so I clone the java client repo and paste above test into

/java-client/src/test/java/io/appium/java_client/ios/iOSGestureTest.java

And I saw the same behavior.

I have looked & tried to use the various TouchAction’s methods but there is no swipe ability as far as i can see.
Sounds very weird that Appium developers can’t swipe on simulator on the latest ios 8.x & latest appium client libraries…

On @menypeled point, at least on 1.3.1 (I haven’t tried going to 1.3.4 yet) I am not seeing a “swipe” method appear. So, I looked at the TouchAction class to see how “swipe” is supposed to be implemented, and just used a press.wait.move_to.release.perform

So I had this:

     self.driver.execute_script("mobile: swipe", {"touchCount": 1, "startX": 312, "startY": 374, "endX": 69, "endY": 379, "duration": 0.6241016})

Now I have this, and it works with TouchAction

    action = TouchAction(self.driver)
    action.press(x=312, y=374).wait(600).move_to(x=69, y=379).release().perform() 

Time to upgrade to 1.3.4 and see if it works on that.

My question, where the heck is the swipe method as it’s documented at: https://github.com/appium/python-client/blob/master/appium/webdriver/webdriver.py

OK. Both swipe and TouchAction work for me. 1.3.1 or 1.3.3.
Add these tests to

https://github.com/appium/java-client/blob/master/src/test/java/io/appium/java_client/ios/iOSGestureTest.java

@Test
  public void testSwipe() throws Exception {
  //click "Test Gesture" button
    final WebElement button = driver.findElementByName("Test Gesture");
    button.click();
  //dismiss alert
    final Alert alert = driver.switchTo().alert();
    alert.accept();
  //swipe gesture using driver.swipe
    driver.swipe(200, 200, 200, 400, 500);
    driver.swipe(200, 330, 200, 100, 500);
    driver.swipe(200, 200, 200, 400, 500);
    driver.swipe(200, 330, 200, 50, 500);
    driver.swipe(200, 200, 200, 400, 500);
    driver.swipe(200, 330, 200, 30, 500);
  }
  
  @Test
  public void testTouchAction() throws Exception {
    //click "Test Gesture" button
    final WebElement button = driver.findElementByName("Test Gesture");
    button.click();
    //dismiss alert
    final Alert alert = driver.switchTo().alert();
    alert.accept();
    //swipe gesture using TouchAction
    TouchAction action = new TouchAction(driver);
    action.press(200, 200).waitAction(500).moveTo(200, 400).release().perform();
    action.press(200, 330).waitAction(500).moveTo(200, 100).release().perform();
    action.press(200, 200).waitAction(500).moveTo(200, 400).release().perform();
    action.press(200, 330).waitAction(500).moveTo(200, 50).release().perform();
    action.press(200, 200).waitAction(500).moveTo(200, 400).release().perform();
    action.press(200, 330).waitAction(500).moveTo(200, 30).release().perform();
  }

Swiping up did not work for me, because the starting point somehow was not correct. I had to play with that point then everything is working.

@fangmobile,
does the swipe work on Simulator?
The followin swipe code works for me on iphone 5 but not on the Simulator:

TouchAction action = new TouchAction(driver);
action.press(270, 265).waitAction(500).moveTo(130, 265).release().perform();

	driver.swipe(270, 265, 130, 265, 500);
1 Like

@menypeled Yes. works on simulator.

very strange,
no swipe in my Simulator when using simulator…
I give up, will hope it will work on future versions…

hi @menypeled,

I have the same issue as yours: the swipe action works fine on real device but on simulator it doesn’t work. I have tried with many Appium versions and still got no luck.

My latest stack is: Appium 1.3.4, java client 2.1.0, xcode 6 and ios 8.1

My current workaround is to use AppleScript to calculate the coordinate of the simulator window, then move the cursor to the center of that window and drag from there. I hate this solution because I have to create another thread to do that and of course it cannot run on a remote hub ( like SauceLab) but it’s the only way that works for me.

I really hope that we can find a better solution for this