iOS Actions
IOSActions provides native iOS gestures via Appium XCUITest.
Ellithium exposes these methods (signatures from the framework):
Swipe
// Swipe on element in direction: up, down, left, right
void swipe(String direction, WebElement element);
// Swipe from start to end with duration (seconds)
void swipe(float startX, float startY, float endX, float endY, float duration);
Scroll
// Scroll element in direction
void scroll(WebElement element, String direction);
// Scroll from start to end with duration (seconds)
void scroll(float startX, float startY, float endX, float endY, float duration);
// Scroll to element using predicate string and direction
void scrollToElement(WebElement element, String predicateString, String direction);
Pinch
// Pinch with scale and velocity on element (overload with double also exists)
void pinch(WebElement element, float scale, float velocity);
void pinch(WebElement element, double scale, double velocity);
// Pinch at coordinates with scale/velocity
void pinch(float x, float y, double scale, double velocity);
Tap / Double Tap
// Tap
void tap(float x, float y);
void tap(WebElement element);
// Double tap
void doubleTap(WebElement element);
void doubleTap(float x, float y);
void doubleTap(float x, float y, float duration);
void doubleTap(WebElement element, float duration);
Touch and Hold (Long Press)
void touchAndHold(WebElement element, float duration);
void touchAndHold(float x, float y, float duration);
void touchAndHold(float x, float y);
void touchAndHold(WebElement element);
Drag
// Drag on element for duration
void dragFromToForDuration(WebElement element, float fromX, float fromY, float toX, float toY, float duration);
// Drag from coordinates for duration
void dragFromToForDuration(float fromX, float fromY, float toX, float toY, float duration);
Two-Finger Tap
void twoFingerTap(WebElement element);
Alerts
// Perform alert action, optionally pass a button label
void alert(String action, String buttonLabel);
Multi-touch
void multiTouchGesture(Map<String, Object>[] actions);
Examples
Initialize
DriverActions actions = new DriverActions(driver);
IOSActions<?> ios = actions.iosActions();
Scroll within element and tap target
WebElement scrollable = driver.findElement(By.id("scrollable"));
ios.scroll(scrollable, "down");
WebElement target = driver.findElement(By.id("target"));
ios.tap(target);
Scroll to element using predicate
WebElement container = driver.findElement(By.id("container"));
ios.scrollToElement(container, "type == 'XCUIElementTypeButton' AND name CONTAINS 'Save'", "up");
Pinch to zoom in on element
WebElement map = driver.findElement(By.id("map"));
ios.pinch(map, 1.5, 1.0);
Double tap with duration at coordinates
ios.doubleTap(150f, 250f, 0.2f);
Drag for 1.5s from one point to another
ios.dragFromToForDuration(50f, 600f, 50f, 200f, 1.5f);
Touch and hold on element for 1s
WebElement pin = driver.findElement(By.id("pin"));
ios.touchAndHold(pin, 1.0f);
Handle alert (accept)
ios.alert("accept", null);
Per-method demos
Below are minimal demos for every method. Assume:
DriverActions actions = new DriverActions(driver);
IOSActions<?> ios = actions.iosActions();
WebElement el = driver.findElement(By.id("target"));
swipe(String direction, WebElement element)
ios.swipe("left", el);
swipe(float startX, float startY, float endX, float endY, float duration)
ios.swipe(300f, 600f, 50f, 600f, 0.25f);
scroll(WebElement element, String direction)
ios.scroll(el, "down");
scroll(float startX, float startY, float endX, float endY, float duration)
ios.scroll(200f, 700f, 200f, 200f, 0.4f);
scrollToElement(WebElement element, String predicateString, String direction)
WebElement container = driver.findElement(By.id("list"));
ios.scrollToElement(container, "name CONTAINS 'Save'", "up");
pinch(WebElement element, float scale, float velocity)
ios.pinch(el, 1.4f, 1.0f); // zoom in
pinch(WebElement element, double scale, double velocity)
ios.pinch(el, 0.7, 1.2); // zoom out
pinch(float x, float y, double scale, double velocity)
ios.pinch(160f, 320f, 1.3, 0.9);
doubleTap(WebElement element)
ios.doubleTap(el);
doubleTap(float x, float y)
ios.doubleTap(150f, 250f);
touchAndHold(WebElement element, float duration)
ios.touchAndHold(el, 1.0f);
touchAndHold(float x, float y, float duration)
ios.touchAndHold(140f, 260f, 1.2f);
twoFingerTap(WebElement element)
ios.twoFingerTap(el);
dragFromToForDuration(WebElement element, float fromX, float fromY, float toX, float toY, float duration)
ios.dragFromToForDuration(el, 0f, 0f, 0f, -300f, 1.5f);
alert(String action, String buttonLabel)
ios.alert("accept", null); // or ios.alert("dismiss", "Cancel")
swipe (coordinates variant)
ios.swipe(300f, 600f, 50f, 600f, 0.25f);
scroll (coordinates variant)
ios.scroll(200f, 700f, 200f, 200f, 0.4f);
pinch at coordinates
ios.pinch(160f, 320f, 1.3, 0.9);
tap at coordinates
ios.tap(120f, 220f);
pinch (coords overload)
ios.pinch(200f, 400f, 0.8, 1.1);
dragFromToForDuration (coordinates variant)
ios.dragFromToForDuration(50f, 600f, 50f, 200f, 1.0f);
touchAndHold at coordinates
ios.touchAndHold(100f, 180f);
doubleTap at coordinates with duration
ios.doubleTap(180f, 240f, 0.15f);