swipe
Swipe in a specific direction within viewport or element for Desktop/Mobile Web AND Mobile Native Apps.
info
Swiping for Mobile Native Apps is based on the W3C-actions protocol, simulating a finger press and movement.
This is different from the mobile: scrollGesture
for Android
or mobile: scroll
for iOS command which is based on the Appium Driver protocol and is
only available for mobile platforms in the NATIVE context.
Swiping based on coordinates
Avoid using from
and to
options unless absolutely necessary. These are device-specific and may not work consistently across devices.
Use the scrollableElement
option for reliable swipes within an element.
Parameters
Name | Type | Details |
---|---|---|
options | object , boolean | options for Element.scrollIntoView() . Default for desktop/mobile web: { block: 'start', inline: 'nearest' } Default for Mobile Native App { maxScrolls: 10, scrollDirection: 'down' } |
options.direction optional | string | Can be one of down , up , left or right , default is up . MOBILE-NATIVE-APP-ONLY |
Down Starting Point: You place your finger towards the top of the screen. Movement: You slide your finger downwards towards the bottom of the screen. Action: This also varies by context: - On the home screen or in applications, it typically scrolls the content upwards. - From the top edge, it often opens the notifications panel or quick settings. - In browsers or reading apps, it can be used to scroll through content. | ||
Left Starting Point: You place your finger on the right side of the screen. Movement: You slide your finger horizontally to the left.> Action: The response to this gesture depends on the application: - It can move to the next item in a carousel or a set of images. - In a navigation context, it might go back to the previous page or close the current view. - On the home screen, it usually switches to the next virtual desktop or screen. | ||
Right Starting Point: You place your finger on the left side of the screen. Movement: You slide your finger horizontally to the right. Action: Similar to swiping left, but in the opposite direction: -- It often moves to the previous item in a carousel or gallery. - Can be used to open side menus or navigation drawers in apps. - On the home screen, it typically switches to the previous virtual desktop. | ||
Up Starting Point: You place your finger towards the bottom of the screen. Movement: You slide your finger upwards towards the top of the screen.> Action: Depending on the context, different actions can occur: - On the home screen or in a list, this usually scrolls the content downwards. - In a full-screen app, it might open additional options or the app drawer. - On certain interfaces, it could trigger a 'refresh' action or open a search bar. | ||
options.duration optional | number | The duration in milliseconds for the swipe. Default is 1500 ms. The lower the value, the faster the swipe. |
options.scrollableElement optional | Element | Element that is used to swipe within. If no element is provided it will use the following selector for iOS -ios predicate string:type == "XCUIElementTypeApplication" and the following for Android //android.widget.ScrollView' . If more elements match the default selector, then by default it will pick the first matching element. MOBILE-NATIVE-APP-ONLY |
options.percent optional | number | The percentage of the (default) scrollable element to swipe. This is a value between 0 and 1. Default is 0.95 .NEVER swipe from the exact top|bottom|left|right of the screen, you might trigger for example the notification bar or other OS/App features which can lead to unexpected results. This has no effect if from and to are provided. |
The below values ONLY have an effect if the scrollableElement is NOT provided, otherwise they are ignored. | ||
options.from optional | object | The x and y coordinates of the start of the swipe. If a scrollableElement is provided, then these coordinates have no effect. |
options.from.x optional | number | The x-coordinate of the start of the swipe. |
options.from.y optional | number | The y-coordinate of the start of the swipe. |
options.to optional | object | The x and y coordinates of the end of the swipe. If a scrollableElement is provided, then these coordinates have no effect. |
options.to.x optional | number | The x-coordinate of the end of the swipe. |
options.to.y optional | number | The y-coordinate of the end of the swipe. |
Examples
swipe.js
it('should execute a default swipe', async () => {
// Default will be a swipe from the bottom to the top, meaning it will swipe UP
await browser.swipe();
});
swipe.with.options.js
it('should execute a swipe with options', async () => {
await browser.swipe({
direction: 'left', // Swipe from right to left
duration: 5000, // Last for 5 seconds
percent: 0.5, // Swipe 50% of the scrollableElement
scrollableElement: $('~carousel'), // The element to swipe within
})
});