Skip to content

feat(longPressOn): add configurable duration parameter#3114

Open
Matheeusb wants to merge 7 commits intomobile-dev-inc:mainfrom
Matheeusb:feature/longpress-custom-duration
Open

feat(longPressOn): add configurable duration parameter#3114
Matheeusb wants to merge 7 commits intomobile-dev-inc:mainfrom
Matheeusb:feature/longpress-custom-duration

Conversation

@Matheeusb
Copy link
Copy Markdown
Contributor

@Matheeusb Matheeusb commented Apr 2, 2026

Summary

Fixes #3083

The longPressOn command had a hardcoded 3-second duration with no way to configure it. This prevented users from automating workflows that require longer (or shorter) press durations, such as bypassing Human Security challenges that require extended presses.

Changes

New YAML API

Users can now specify a duration field (in milliseconds) on longPressOn:

# Custom duration (8 seconds)
- longPressOn:
    id: "my_button"
    duration: 8000

# Works on text selectors too
- longPressOn:
    text: "Hold to confirm"
    duration: 5000

# Works on screen coordinates
- longPressOn:
    point: "50%,50%"
    duration: 2000

# Backward compatible — omitting duration keeps the existing 3s default
- longPressOn: "Some element"

Modules changed

Module Change
maestro-orchestra-models Added duration: Long? to TapOnElementCommand, TapOnPointV2Command, TapOnPointCommand; added DEFAULT_LONG_PRESS_DURATION_MS = 3000L constant
maestro-client Updated Driver interface: longPress(point, durationMs = 3000L); propagated longPressDurationMs through all tap() overloads and into hierarchyBasedTap/screenshotBasedTap
maestro-client (drivers) AndroidDriver, IOSDriver, WebDriver, CdpWebDriver — all now use the passed durationMs instead of the hardcoded 3000
maestro-orchestra YamlElementSelector — new duration field; YamlFluentCommand — extracts and passes duration; Orchestra — passes command.duration to all tap call sites
maestro-test FakeDriver.Event.LongPress now captures durationMs for test assertions

Tests

  • Added 033_longPressOn_withDuration.yaml fixture covering duration on element-by-text, element-by-id, default (null), and screen-point variants
  • Added longPressOn with custom duration should parse duration into command test in YamlCommandReaderTest

Backward compatibility

Fully backward compatible. Omitting duration preserves the existing 3000ms default behaviour.

Add optional duration parameter (in milliseconds) to TapOnElementCommand,
TapOnPointV2Command, and TapOnPointCommand to support custom long press duration.

- Added duration: Long? = null to TapOnElementCommand, TapOnPointV2Command
  and TapOnPointCommand
- Added DEFAULT_LONG_PRESS_DURATION_MS = 3000L constant to TapOnElementCommand

Resolves mobile-dev-inc#3083
Update Driver interface and all implementations to accept a configurable
duration for long press operations instead of a hardcoded 3000ms value.

- Driver.kt: updated longPress signature to longPress(point, durationMs = 3000L)
- Maestro.kt: added longPressDurationMs parameter through the entire tap chain
  (tap, tapOnRelative, performTap, hierarchyBasedTap, screenshotBasedTap)
- AndroidDriver: pass durationMs to 'input swipe' shell command
- IOSDriver: pass durationMs to iosDevice.longPress()
- WebDriver: pass durationMs to Selenium clickAndHold pause
- CdpWebDriver: pass durationMs to Selenium clickAndHold pause

Resolves mobile-dev-inc#3083
…estrator

Add support for parsing the duration field from YAML and passing it through
the orchestra layer to the Maestro client.

- YamlElementSelector.kt: added duration: Long? field for longPressOn YAML config
- YamlFluentCommand.kt: extract duration from YamlElementSelector and pass it
  to TapOnElementCommand and TapOnPointV2Command
- Orchestra.kt: pass command.duration as longPressDurationMs to all maestro.tap()
  call sites (element tap, point tap, relative tap)

Resolves mobile-dev-inc#3083
Update the FakeDriver used in tests to record the durationMs alongside the
point in LongPress events, enabling assertions on the pressed duration.

- FakeDriver.kt: updated Event.LongPress data class to include durationMs field
- FakeDriver.kt: updated longPress() override to forward durationMs parameter

Resolves mobile-dev-inc#3083
Add test coverage for the new duration parameter in longPressOn command.

- 033_longPressOn_withDuration.yaml: test fixture with long press by text, by id,
  with default duration, and on a screen point, all using the duration field
- YamlCommandReaderTest.kt: new test verifying that duration values are correctly
  parsed into TapOnElementCommand and TapOnPointV2Command, and that omitting
  duration results in null (defaults to 3000ms at runtime)

Resolves mobile-dev-inc#3083
@Matheeusb Matheeusb force-pushed the feature/longpress-custom-duration branch from d4a4c51 to 5a5ab9f Compare April 10, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Command longPressOn has a hardcoded 3s duration and cannot bypass Human challange

1 participant