fix: support appium_lib_core 13.x snake_case capabilities#37
Conversation
appium_lib_core 13.x returns the session capabilities as an
Appium::Core::Base::Capabilities object whose keys are snake_case
(e.g. "platform_name", "device_screen_size") rather than the camelCase
keys ("platformName", "deviceScreenSize") older versions returned.
This broke metadata resolution on core 13.x: MetadataResolver could not
find platformName and raised PlatformNotSupported, and os_name/os_version/
device_name/orientation/deviceScreenSize all read nil, so no snapshot was
taken.
Add Percy::Metadata.normalize_capability_key / normalized_capabilities to
look capabilities up in a casing- and prefix-insensitive way (camelCase,
snake_case, SCREAMING_CASE and the W3C "appium:" vendor prefix), and route
the affected metadata reads through it. Backward compatible with
appium_lib_core 12.x and earlier (camelCase) and forward compatible with
13.x (snake_case). First-key-wins preserves the previous resolver
precedence of platformName over platform_name.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Address PR review feedback: - Normalize the nested `desired` capabilities hash via Percy::Metadata.normalize_hash so its keys (including `device`) resolve regardless of camelCase/snake_case, not just an ad-hoc deviceName/device_name fallback. - Add regression tests covering the appium_lib_core 13.x snake_case failure modes: normalize_capability_key, os_name/os_version (platform_version), Android device_screen_size and nested desired device_name, iOS device_name. - Document that the Android viewportRect lookup is intentionally left as-is (it degrades to driver.get_system_bars consistently across versions) and that normalize_capability_key strips all colons by design. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude Code PR ReviewPR: #37 • Head: 600dd5a • Reviewers: stack:code-reviewer SummaryAdds a casing/prefix-insensitive capability lookup ( Review Table
FindingsAll reviewer findings were either addressed in follow-up commit
Verification
Verdict: PASS — correct, focused, backward-compatible fix with regression coverage; all review feedback addressed. |
Bump version to 1.0.1. Supersedes the stray 1.0.0 (published 2024-10-28) that RubyGems resolves as `latest` due to semver ordering but which is broken with real Appium drivers (strict platformName lookup -> PlatformNotSupported -> empty build). 1.0.1 is cut from current main, so `gem install percy-appium-app` now resolves to working code that also includes appium_lib_core 13.x support (PR #37). Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Problem
appium_lib_core13.x returns the session capabilities as anAppium::Core::Base::Capabilitiesobject whose keys are snake_case (platform_name,device_screen_size,platform_version, …) instead of the camelCase keys (platformName,deviceScreenSize,platformVersion) that 12.x and earlier returned.This silently broke Percy on core 13.x:
MetadataResolver.resolvelooked forplatformName, didn't find it, and raisedPlatformNotSupported.os_name,os_version,device_name,orientation, anddeviceScreenSizeall readnil.Fix
Introduce two helpers on
Percy::Metadata:normalize_capability_key(key)— lowercases and strips_/:and the leadingappiumvendor prefix, soplatformName,platform_name,PLATFORM_NAMEandappium:platformNameall normalize toplatformname.normalized_capabilities(driver)— coerces the capabilities object to a plain Hash (as_json/to_h) and builds a{normalized_key => value}view. First key wins, preserving the previous resolver precedence ofplatformNameoverplatform_name.The affected metadata reads (
MetadataResolver,os_name,os_version,get_orientation, Androiddevice_screen_size/_device_name, iOSdevice_name) now go throughget_capability_value, which reads fresh on every call (no memoization — same call semantics as before).The Android
viewportRect/viewportreads are intentionally left unchanged — that path already falls back todriver.get_system_barsconsistently across all appium versions, so it's out of scope for this fix.Compatibility
appium_lib_core≤ 12.x (camelCase).appium_lib_core13.x (snake_case).Verification
specs/*.rb).appium_lib 16.3.0(core 13.x) now takes the snapshot and finalizes green (previously failed withPlatformNotSupported/ "Snapshot command was not called").🤖 Generated with Claude Code