How to Write Test Cases for Swipe Gestures (With Examples)

How to Write Test Cases for Swipe Gestures (With Examples)

February 05, 2026 · 17 min read · How-To Guides

How to Write Test Cases for Swipe Gestures (With Examples)

Swipe gestures are a core interaction pattern in mobile and web applications, yet they are often under‑tested because they appear simple. A swipe can trigger navigation, reveal hidden controls, start a drag‑and‑drop flow, or dismiss a notification, and each of those outcomes must be verified under a variety of device states, screen sizes, and user contexts. Writing effective test cases for swipe gestures means moving beyond “swipe left” and defining precise preconditions, step‑by‑step actions, observable results, and cleanup logic that together expose functional bugs, performance hiccups, and accessibility gaps. This guide walks you through the anatomy of a swipe test case, shows how to categorize them, provides a concrete matrix of 20+ examples, explains how to prioritize and trace them to requirements, and demonstrates how manual execution, automated scripts, and autonomous exploration tools like SUSA can be combined for real‑world coverage.

1. Understanding Swipe Gesture Testing

1.1 What Constitutes a Swipe

A swipe is a touch‑or‑pointer input where the user places a finger (or stylus) on the screen, moves it a minimum distance in a dominant direction, and lifts it within a time window that distinguishes it from a tap or a long press. Platforms differ in the thresholds they apply: Android’s ViewConfiguration.getScaledTouchSlop() typically requires ~8 dp of movement, while iOS uses a system‑defined tolerance of ~10 points. On the web, the Pointer Events spec defines a swipe when the pointermove sequence yields a net displacement exceeding a configurable threshold (often 40 px) and the pointerup occurs within ~300 ms of the first pointerdown. Recognizing these platform‑specific nuances is essential because a test that passes on one device may fail on another if the gesture is mis‑interpreted.

1.2 Why Swipe Tests Matter

Swipes frequently control high‑value user flows: navigating between tabs in a bottom navigation bar, revealing action menus in a list item, advancing a carousel, or dismissing a modal. A missed swipe can leave users stranded, cause data loss (e.g., unintended delete), or hide critical UI (e.g., a promo banner). Moreover, swipe gestures intersect with other system behaviors—scrolling, edge‑panels, accessibility services—creating edge cases that only surface under specific combinations of OS version, screen density, or assistive technology. By treating swipe interactions as first‑class test targets, you gain early visibility into crashes, ANRs, dead zones, and WCAG violations that would otherwise be discovered only in production.

2. Anatomy of a Test Case for Swipe Gestures

2.1 Test ID and Naming Conventions

Each test case should carry a unique identifier that encodes the feature area, gesture type, and scenario intent. A readable pattern such as SWIPE-LIST-001-NAV-NEXT tells a reviewer at a glance that the test validates swiping left on a list to navigate to the next item. Prefixes (SWIPE) keep the suite searchable, while suffixes (-NAV-, -DEL-, -EXP-) indicate the expected outcome (navigation, deletion, expansion). Consistency in naming reduces duplication and simplifies traceability to requirements or user stories.

2.2 Preconditions

Preconditions describe the exact state the application must be in before the swipe is performed. For a list‑item swipe‑to‑delete, preconditions might include:

Writing preconditions as bullet‑pointed, verifiable conditions enables testers to reproduce the setup reliably and helps automation scripts assert the same state before execution.

2.3 Test Steps (Action Sequences)

Steps should be atomic, platform‑agnostic where possible, and detailed enough to eliminate ambiguity. A typical swipe step list looks like:

  1. Ensure the target element (e.g., the second list item) is fully visible within the viewport.
  2. Place a finger on the element’s start edge (leftmost 10 % of its width).
  3. Move the finger horizontally to the opposite edge (rightmost 10 % of its width) at a velocity of ~300 dp/s.
  4. Lift the finger.
  5. Wait for the UI to settle (e.g., 500 ms) before asserting the expected result.

If the test targets a specific gesture recognizer (e.g., a SwipeRefreshLayout), include the exact direction and distance that the recognizer expects. For web tests, substitute touch actions with Pointer Events or the appropriate driver API (e.g., page.touchscreen.swipe() in Playwright).

2.4 Expected Results

The expected result must be observable and measurable. For a swipe‑to‑delete, the expected result could be:

Avoid vague phrasing like “the UI updates correctly.” Instead, specify the exact UI element, its new state, and any side‑effects (network calls, analytics events, accessibility announcements).

2.5 Postconditions and Cleanup

After verification, the test should leave the system in a known state for the next test or for manual exploration. Postconditions may involve:

If cleanup fails, flag the test as “flaky” and investigate whether the swipe left residual state (e.g., a half‑dismissed modal) that interferes with subsequent runs.

3. Categorizing Swipe Test Cases

3.1 Positive (Happy Path) Cases

Positive cases verify that the swipe performs its intended function under normal conditions. Examples include swiping a card to reveal a hidden action button, swiping a carousel to the next slide, or pulling down to refresh a feed. These tests form the baseline confidence that the feature validation.

3.2 Negative Cases

Negative cases confirm that the system correctly rejects or ignores invalid input may include:

3.3 Boundary and Edge Cases

Boundary cases push the gesture recognition. Examples include:

3.4 Performance and Timing Cases

Swipe gestures can expose performance problems when the UI thread is blocked during the animation or when the gesture recognizer delays its decision. Performance‑focused tests might:

3.5 Accessibility and Multi‑Modal Cases

Accessibility services often synthesize or intercept gestures. Test cases should verify that:

4. Building a Swipe Test Matrix (20+ Examples)

Below is a practical test matrix that you can copy into a test‑management tool. Each row includes an ID, preconditions, step‑by‑step actions, and the expected result. Feel free to adapt the wording to your domain (e‑commerce, social media, banking, etc.).

IDPreconditionsStepsExpected Result
SWIPE-LIST-001User on Inbox screen, ≥3 emails visible, no modals1. Locate second email item.
2. Place finger on its left edge (10% width).
3. Swipe right to 90% width at 300 dp/s.
4. Lift finger.
Email slides right, reveals “Archive” and “Delete” buttons; no crash.
SWIPE-LIST-002Same as 001, first email not archived1. Swipe left on first email (right‑to‑left).
2. Lift finger.
Email slides left, moves to Archive folder; Undo snackbar appears.
SWIPE-LIST-003List with variable‑height items, third item tallest1. Scroll to make third item fully visible.
2. Swipe up on item (bottom‑to‑top) 70% height.
3. Lift.
Item expands to show full content; no clipping.
SWIPE-CAROUSEL-001Carousel on Home screen, auto‑rotate disabled1. Tap to ensure carousel has focus.
2. Swipe left on carousel (right‑to‑left).
3. Wait 300 ms.
Carousel advances to next slide; indicator dot updates.
SWIPE-CAROUSEL-002Carousel displaying promotional banner, user has dismissed banner earlier1. Swipe right on carousel.
2. Lift.
Carousel moves to previous slide; banner remains dismissed.
SWIPE-REFRESH-001Feed screen showing at least 5 posts, pull‑to‑refresh enabled1. Place finger on top of list.
2. Drag down 120 dp.
3. Release.
Refresh spinner appears, new data fetched, list updates; no duplicate items.
SWIPE-REFRESH-002Feed with empty state, no network1. Attempt pull‑to‑refresh.
2. Release.
Refresh spinner shows, then error toast “No internet connection”; UI returns to idle.
SWIPE-MENU-001Detail view with overflow menu hidden behind left edge1. Swipe from left edge inward 40% width.
2. Lift.
Navigation drawer slides in; menu items selectable.
SWIPE-MENU-002Drawer already open1. Swipe from left edge outward.
2. Lift.
Drawer closes; focus returns to previous view.
SWIPE-DELETE-001Chat conversation list, swipe‑to‑delete enabled1. Swipe left on a conversation.
2. Lift.
Conversation dims, delete confirmation appears; tapping “Delete” removes item.
SWIPE-DELETE-002Same as 001, user taps Undo within snackbar1. Swipe left → delete.
2. Tap Undo on snackbar within 5 s.
Conversation restored to original position; no data loss.
SWIPE-SLIDER-001Volume slider at 50%, discrete steps of 5%1. Place finger on slider thumb.
2. Swipe right to increase to 80%.
3. Lift.
Slider thumb moves to 80%; system volume updates accordingly; accessibility announces new level.
SWIPE-SLIDER-002Slider at minimum (0%)1. Attempt to swipe left beyond bounds.
2. Lift.
Slider remains at 0%; no visual jitter; no error announced.
SWIPE-MAP-001Map view showing user location pin, gesture‑enabled pan1. Two‑finger swipe up on map.
2. Lift.
Map pans upward, revealing new area; pins reposition correctly; no tile‑loading errors.
SWIPE-MAP-002Map in 3D tilt mode1. Swipe down with two fingers.
2. Lift.
Map tilt angle decreases; transition smooth; no flicker.
SWIPE-VIDEO-001Full‑screen video player, swipe to dismiss1. Swipe down from top edge 30% height.
2. Lift.
Video player dismisses; returns to previous screen; video pauses.
SWIPE-VIDEO-002Video playing, user swipes left/right to seek 10 s1. Swipe right on video surface.
3. Lift.
Video seek forward 10 s; playback continues; seek bar updates.
SWIPE-NAV-BAR-001Bottom navigation with 4 tabs, current tab = Home1. Swipe left on Home tab icon.
2. Lift.
Active tab changes to Search; corresponding fragment loads; no duplicate tab creation.
SWIPE-NAV-BAR-002Same as 001, user rapidly swipes left‑right twice1. Swipe left, lift.
2. Immediately swipe right, lift.
Tab returns to Home; no intermediate tab stays highlighted; no UI glitch.
SWIPE-EDIT-001Text field with visible clear‑button on right edge1. Tap field to focus.
2. Swipe left on clear‑button area (rightmost 20%).
3. Lift.
Field text cleared; keyboard remains; focus stays in field.
SWIPE-EDIT-002Same field, user swipes right outside clear‑button area1. Swipe right from middle of field.
2. Lift.
No clear action; cursor moves according to typical text selection (if any).
SWIPE-SETTINGS-001Settings list with switch toggles1. Locate Wi‑Fi toggle row.
2. Swipe left on toggle (off → on).
3. Lift.
Switch animates to ON; Wi‑Fi enables; system status bar updates.
SWIPE-SETTINGS-002Same toggle currently ON1. Swipe right on toggle (on → off).
2. Lift.
Switch animates to OFF; Wi‑Fi disables; no rebound animation.
SWIPE-ACCESS-001TalkBack enabled, list item with swipe‑to‑archive1. Focus on item via TalkBack.
2. Perform swipe left gesture (TalkBack reads “swipe left to archive”).
3. Lift.
TalkBack announces “Item archived”; item moves to archive folder; no extra announcements.
SWIPE-ACCESS-002VoiceOver enabled, carousel with accessibility label1. Focus on carousel.
2. Swipe right (VoiceOver reads “next slide”).
3. Lift.
VoiceOver announces new slide label; carousel updates; no loss of focus.

*Notes:*

5. Data Setup and Test Environment Preparation

5.1 Device/Emulator Configurations

To capture device‑specific behavior, run the swipe matrix on a matrix of:

Maintain a device‑pool spreadsheet that logs the exact build, SDK level, and any custom OEM gesture overrides (e.g., Samsung’s Edge Panel). Automation scripts should read this spreadsheet to select the appropriate capability set.

5.2 Test Data (Lists, Carousels, etc.)

Swipe tests depend on having predictable, deterministic data:

Automate data seeding via CLI commands or API calls that your app exposes for testing (e.g., /test/reset-state). If such endpoints do not exist, consider using UI‑driven setup that navigates to a “debug” screen where you can inject test fixtures.

5.3 State Reset Strategies

After each swipe test, the system must return to a known baseline:

Implement these steps in an @After hook (JUnit/TestNG) or afterEach block (Mocha/Jest) so that failures do not cascade.

6. Prioritization and Traceability

6.1 Risk‑Based Prioritization

Not all swipe cases carry equal weight. Use a simple risk score = (Impact × Likelihood).

Assign scores 1‑5 for each dimension, multiply, and sort descending. High‑risk cases (score ≥ 15) become mandatory for every release; medium (8‑14) are run nightly; low (≤ 7) can be executed weekly or on demand.

6.2 Linking Tests to Requirements (Traceability Matrix)

Create a two‑column table that maps each test ID to the requirement(s) it validates. Example:

Test IDRequirement IDRequirement Description
SWIPE-LIST-001REQ-UI-07User can reveal secondary actions on list items via swipe.
SWIPE-REFRESH-001REQ-FEED-03Pull‑to‑refresh updates the feed with latest content.
SWIPE-ACCESS-001REQ-ACC-022 announces swipe‑ result.

Keep this matrix | TalkBack provides appropriate feedback for swipe actions. |

Maintain this matrix in a living document (e.g., Confluence page) and update it whenever a requirement changes. When a test fails, you can instantly see which requirement is impacted, facilitating root‑cause analysis and stakeholder communication.

7. Manual vs Automated Approaches

7.1 Manual Execution Tips

When executing swipe tests manually:

7.2 Automation Frameworks

#### 7.2.1 Appium (Android/iOS)

Appium’s TouchAction or the newer W3C Actions API lets you define precise swipe coordinates. Example in Java:


TouchAction touch = new TouchAction(driver);
touch.press(PointOption.point(startX, startY))
     .waitAction(WaitOptions.waitOptions(Duration.ofMillis(150)))
     .moveTo(PointOption.point(endX, endY))
     .release()
     .perform();

For Android, you can also use UiAutomator’s UiObject2.swipe() which automatically handles velocity scaling:


UiObject2 item = device.findObject(By.desc("Email item 2"));
item.swipe(Direction.LEFT, 0.5f); // 0.5 = 50% width swipe

#### 7.2.2 Espresso / XCTest

Espresso provides the swipeLeft() and swipeRight() ViewActions:


onView(withId(R.id.recyclerView))
    .perform(RecyclerViewActions.actionOnItemAtPosition(1, swipeLeft()));

In XCTest (Swift), use XCUICoordinate:


let start = item.coordinate(withNormalizedOffset: CGVector(dx: 0.0, dy: 0.5))
let finish = item.coordinate(withNormalizedOffset: CGVector(dx: 0.8, dy: 0.5))
start.press(forDuration: 0.1, thenDragTo: finish)

#### 7.2.3 Playwright for Web Swipes

Playwright’s touchscreen API works on mobile emulators and real devices:


await page.touchscreen.swipe(
  startX, startY,   // from
  endX, endY,       // to
  150               // duration in ms
);

If you prefer Pointer Events:


await page.dispatchEvent('#carousel', 'pointerdown', {x: startX, y: startY});
await page.dispatchEvent('#carousel', 'pointermove', {x: endX, y: endY});
await page.dispatchEvent('#carousel', 'pointerup',   {x: endX, y: endY});

7.3 Flaky Test Mitigation

Common sources of flakiness in swipe automation:

Incorporate retries only for non‑deterministic network calls, not for the gesture itself; a flaky swipe usually indicates a test design issue that should be fixed rather than masked.

8. Leveraging Autonomous Exploration (SUSA) for Swipe Gesture Coverage

8.1 How SUSA Discovers Swipe‑able Areas

SUSA explores an app by treating every tappable, scrollable, or draggable region as a candidate for interaction. It builds a gesture model based on observed UI heuristics: if a view contains a RecyclerView, ViewPager, Carousel, or a horizontally scrollable ScrollView, SUSA generates swipe actions in both directions with varying speeds and lengths. It also respects platform‑specific edge‑swipe reservations (e.g., Android’s system navigation bars) to avoid triggering unintended OS gestures.

During each pass, SUSA records:

8.2 Combining Scripted Cases with Autonomous Runs

Use scripted test cases (the matrix above) to verify intentional behavior—those flows that the product team has specified. Then schedule regular SUSA runs to discover unintended or undocumented swipe‑able regions. For example:

When SUSA flags a new swipe pattern, create a supplemental test case (assign a new SWIPE‑ID) and add it to the regression suite. Conversely, if SUSA reports that a previously passing swipe now causes a crash, prioritize investigating that area immediately.

8.3 Interpreting SUSA Reports for Swipe Gestures

SUSA’s output includes a gesture‑heatmap overlay on screenshots, showing where swipes were attempted and the outcome color‑coded (green = success, red = crash, amber = no change). Look for:

Export the JSON report and integrate it with your test management tool to auto‑generate tickets for any new swipe‑related defects.

9. Checklist for Writing Effective Swipe Test Cases

9.1 Pre‑Flight Checklist

9.2 Post‑Execution Review

10. Real‑World Edge Cases Seen in Production

10.1 List Scrolling with Variable Item Heights

A news app used a RecyclerView with mixed‑size cards (some with images, some text‑only). Users reported that swiping left on a tall card sometimes triggered the swipe‑to‑delete on the *next* card because the RecyclerView’s item animator delayed the layout pass. The fix involved overriding onTouchEvent to temporarily disable item animations during the gesture.

10.2 Swipe‑to‑Delete with Undo

A banking app allowed swiping left to delete a recent transaction, with an Undo snackbar lasting 8 seconds. In production, users with TalkBack enabled found that the Undo action was announced *after* the snackbar disappeared, making recovery impossible. The root cause was that the accessibility announcement was queued on the main thread but delayed by the snackbar’s dismissal animation. Adding an AccessibilityLiveRegion mode resolved the timing issue.

10.3 Nested Scroll Views

A settings screen contained a vertically scrollable list, each row holding a horizontally scrollable picker (e.g., time‑of‑day selector). Users attempting to swipe left on the picker unintentionally scrolled the parent list, leading to perceived unresponsiveness. The solution was to call requestDisallowInterceptTouchEvent(true) on the parent when the picker detected a horizontal gesture.

10.4 Gesture Conflicts (Long Press vs Swipe)

An image gallery implemented both a long‑press to show a context menu and a swipe left/right to navigate between images. On some devices, a slow swipe was interpreted as a long press, opening the menu and blocking navigation. Adjusting the long‑press timeout from 500 ms to 800 ms and increasing the swipe minimum velocity eliminated the false positives.

10.5 Accessibility Overrides (TalkBack, VoiceOver)

When TalkBack is active, Android converts certain swipe gestures into accessibility actions (e.g., swipe left/right moves focus). A custom view that overrode onTouchEvent without calling `super.onTouchEvent

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free