Gestures
In mobile app testing, simulating user interactions like swipes, taps, and pinch-zoom gestures is crucial for validating how the app behaves. Gestures are a natural part of mobile app navigation, and Appium provides ways to automate these actions to test the app's usability and responsiveness.
Gestures let you interact with mobile apps like a real user would. Examples include:
- Tapping on buttons or icons.
- Swiping through image galleries, lists, or screens.
- Scrolling down pages or up to the top.
- Pinch and Zoom to zoom in or out on images or maps.
- Long Press for interactions that need a longer touch (e.g., dragging an item).
In the latest versions of Appium, you can also use the W3C Actions API, which provides more flexibility and compatibility with both Android and iOS.
Java
C#
Python
Javascript
Kotlin
Copy
PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger"); Sequence swipe = new Sequence(finger, 1); swipe.addAction(finger.createPointerMove(Duration.ZERO, PointerInput.Origin.viewport(), startX, startY)); swipe.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg())); swipe.addAction(finger.createPointerMove(Duration.ofMillis(1000), PointerInput.Origin.viewport(), endX, endY)); swipe.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg())); driver.perform(Arrays.asList(swipe));
C# code coming soon
Python code coming soon
Javascript code coming soon
Kotlin code coming soon
This approach is more versatile and works on both platforms without requiring separate Android or iOS-specific code.