How to use TouchActions on iOS simulator?

I have Selenium WebDriver tests that work fine on desktop chrome and firefox. I run them using Saucelabs. To start the browsers I just instantiate a new RemoteWebDriver.
Now I also want to test my website against Android/iOS. So I use Saucelabs to run on both Android and iOS(ipad) simulators. For both Android and iOS I use Appium.

In my tests I have some advanced user interactions, like drag and drop:

	new Actions(driver).dragAndDrop(entity, webElement)
		.build()
		.perform();

Executing the above code on desktop AND on Appium Android simulator works perfectly fine. However, running the same on Appium iOS simulator gives me the ‘Not yet implemented’ error.
I tried searching the Appium documentation and these forums to find a solution. I changed the code above into the following:

	IOSDriver iosDriver = (IOSDriver)driver;
	iosDriver.context("NATIVE_APP");
	
	new TouchAction(iosDriver)
		.press(entity.getLocation().x, entity.getLocation().y)
		.waitAction(500)
		.moveTo(webElement.getLocation().x, webElement.getLocation().y)
		.waitAction(500)
		.release()
		.perform();
	
	iosDriver.context("WEBVIEW_1");

These coordinates might be off, because of the offset problems I read about, but at least it should run without problems.
Next to the above I also instantiate my WebDriver by using the IOSDriver instead of the RemoteWebDriver.

        WebDriver driver = new IOSDriver(url, caps);

This now gives me the following error: ‘Not implemented in this context, try switching into or out of a web view’.

I am out of ideas on how to get this to work.

Yes in WebContext, I don’t think you can use touch action yet, it relies on Chromedriver.

Try to pass elements instead of coordinate.

1 Like

I also tried with webelements. Didn’t work.
Like I said, we are using saucelabs. I made a little example code:

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test;

public class TestExampleDnD {
 
public final static String SAUCE_USER_NAME = "xxx";
public final static String SAUCE_API_KEY = "xxx";

	@Test
	public void dragAndDrop() throws MalformedURLException {
		URL url = new URL("http://" + SAUCE_USER_NAME + ":" + SAUCE_API_KEY + "@ondemand.saucelabs.com:80/wd/hub");
		DesiredCapabilities caps = null;
		WebDriver driver = null;
		
		String[] browsers = {"chrome", "android", "ios"};
		for (String browser: browsers) {
			switch(browser) {
			case "chrome": 
				caps = DesiredCapabilities.chrome();
				caps.setCapability("platform", "Windows 8.1");
				caps.setCapability("version", "43.0");
				caps.setCapability("screenResolution", "1280x1024");
				driver = new RemoteWebDriver(url, caps);
				break;
			case "android": 
				caps = DesiredCapabilities.android();
				caps.setCapability("appiumVersion", "1.4.0");
				caps.setCapability("deviceName","android");
				caps.setCapability("deviceOrientation", "portrait");
				caps.setCapability("browserName", "browser");
				caps.setCapability("platformName", "android");
				caps.setCapability("platformVersion", "5.1");
				driver = new RemoteWebDriver(url, caps);
				break;
			case "ios":
				caps = DesiredCapabilities.iphone();
				caps.setCapability("appiumVersion", "1.4.0");
				caps.setCapability("deviceName","iPad Simulator");
				caps.setCapability("deviceOrientation", "portrait");
				caps.setCapability("platformVersion","8.2");
				caps.setCapability("platformName", "iOS");
				caps.setCapability("browserName", "Safari");
				driver = new RemoteWebDriver(url, caps);
				break;
			}
		
			//Actual test
			driver.get("http://jqueryui.com/droppable/");
			WebElement iFrame = driver.findElement(By.cssSelector(".demo-frame"));
			driver.switchTo().frame(iFrame);
			WebElement draggable = driver.findElement(By.id("draggable"));
			WebElement droppable = driver.findElement(By.id("droppable"));
			
			new Actions(driver)
				.dragAndDrop(draggable, droppable)
				.build()
				.perform();
			
			driver.quit();
		}
	}
}

Running this, both chrome and android pass, but ios fails with not yet implemented. Can someone please tell me if it is possible (and what code I have to use) to make this example work?

Hey there
It’s been mentioned here that swipes in general break on the iOS simulator due to apples ui automation framework, so touch actions won’t work on the simiulator either.

I have had success however calling out this program in my tests as a workaround.

Hope you find it helpful. Maybe you could set this up somehow with sauce labs?

Good luck!
Eric

So, there is no proper/easy way to get drag and drop actions working on Safari on an iOS simulator?

HI @arson,
I can’t speak for Safari, but for native apps, Apple’s UI Automation Instrumentation swipes are broken in the simulator.