Skip to content

fix: prefer Appium events endpoint in driver.events with getSession fallback - #1382

Closed
RainyMarks wants to merge 1 commit into
appium:masterfrom
RainyMarks:fix/session-events-appium4
Closed

RainyMarks wants to merge 1 commit into
appium:masterfrom
RainyMarks:fix/session-events-appium4

Conversation

@RainyMarks

Copy link
Copy Markdown
Contributor

Summary

Updates Session.events (driver.events in appium/webdriver/extensions/session.py) to query POST /session/$sessionId/appium/events (Command.GET_EVENTS) first and fall back to GET /session/$sessionId (Command.GET_SESSION) only when the server rejects the events endpoint with UnknownMethodException.

Why

  • Appium 4 removes the deprecated JSONWP GET /session/:sessionId route and the appium:eventTimings capability (refactor(base-driver)!: remove deprecated getSession command appium#22725), recommending getLogEvents (POST /session/:sessionId/appium/events) instead.
  • driver.events currently only calls GET /session/$sessionId, so against Appium 4 it fails and logs a warning before silently returning {}.
  • POST /session/$sessionId/appium/events has been supported since Appium 1.16.0 and returns the event history object directly under value without requiring appium:eventTimings.
  • Falling back to GET /session/$sessionId on UnknownMethodException preserves backwards compatibility with older servers while avoiding unnecessary legacy requests on Appium 1.16–4.x.

Changes

  • appium/webdriver/extensions/session.py:
    • Register Command.GET_EVENTS alongside Command.GET_SESSION in Session._add_commands().
    • Query Command.GET_EVENTS with an empty JSON object body ({}) first, validate that value is a dict, and fall back to Command.GET_SESSION on UnknownMethodException.
    • Retain the warning + {} return behavior on missing/invalid payloads or non-method errors.
  • test/unit/webdriver/webdriver_test.py:
    • Verify driver.events uses POST /session/$sessionId/appium/events with {} even when GET /session/$sessionId returns 404 unknown command.
    • Verify fallback to GET /session/$sessionId when POST /session/$sessionId/appium/events returns 404 unknown command.
    • Verify missing/non-dict payloads and transport errors return {} without spurious fallback requests.

Testing

  • ruff check . — passed.
  • ruff format --check . — passed (399 files already formatted).
  • mypy appium — passed (0 issues across 320 source files).
  • pytest test/unit/webdriver/webdriver_test.py test/unit/webdriver/log_events_test.py — 45/45 passed.

@KazuCocoa

Copy link
Copy Markdown
Member

Thank you, but I'd like to include appium 4 related changes in #1388 so closing this PR

@KazuCocoa KazuCocoa closed this Nov 27, 2026
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.

2 participants