свайп
Свайп у певному напрямку в області перегляду або елементі для десктопних/мобільних веб-додатків І нативних мобільних додатків.
Свайп для нативних мобільних додатків базується на протоколі W3C-actions, що імітує натискання пальцем та рух.
Це відрізняється від команд mobile: scrollGesture
для Android
або mobile: scroll
для iOS, які базуються на протоколі Appium Driver і доступні
лише для мобільних платформ у контексті NATIVE.
Ця команда працює лише з такими оновленими компонентами:
- Appium сервер (версія 2.0.0 або вище)
appium-uiautomator2-driver
(для Android)appium-xcuitest-driver
(для iOS)
Переконайтеся, що ваше локальне або хмарне середовище Appium регулярно оновлюється, щоб уникнути проблем із сумісністю.
Уникайте використання опцій from
та to
, якщо це не є абсолютно необхідним. Вони залежать від пристрою і можуть працювати непослідовно на різних пристроях.
Використовуйте опцію scrollableElement
для надійних свайпів всередині елемента.
Parameters
Name | Type | Details |
---|---|---|
options optional | object, boolean | options for browser.swipe() . Default for desktop/mobile web: { direction: 'up', duration: 1500, percent: 0.95, scrollableElement: WebdriverIO.Element } |
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
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();
});
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
})
});