feat: add action and camera values for mobile: pressButton#1115
feat: add action and camera values for mobile: pressButton#1115eglitise wants to merge 6 commits intoappium:masterfrom
action and camera values for mobile: pressButton#1115Conversation
There was a problem hiding this comment.
Pull request overview
Adds support for additional iOS hardware button names (action, camera) to mobile: pressButton in WebDriverAgent by mapping them to the corresponding XCUIDeviceButton values when available on-device.
Changes:
- Extend
XCUIDevice (FBHelpers)button name mapping to includeaction(iOS 16+) andcamera(iOS 16+) gated byhasHardwareButton:. - Update the public header docstring to list the newly supported button names.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| WebDriverAgentLib/Categories/XCUIDevice+FBHelpers.m | Adds runtime-gated mapping for action/camera buttons and updates supported button list construction. |
| WebDriverAgentLib/Categories/XCUIDevice+FBHelpers.h | Updates API documentation to include action and camera button names. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| dstButton = XCUIDeviceButtonHome; | ||
| } | ||
| [supportedButtonNames addObject:@"home"]; | ||
|
|
There was a problem hiding this comment.
would it make sense to extract this logic into a separate private method to simplify this one?
There was a problem hiding this comment.
It could certainly be made to look nicer, but I'm not really sure of the best approach when using these compiler-level guards
There was a problem hiding this comment.
it doesn't change anything, just refactor conditions to a separate method to reduce the cyclomatic complexity of the fb_pressButton one, (e.g. fb_addButtonsIfAvailable)
There was a problem hiding this comment.
Added two helper methods, one for checking if a button is available, and another for adding supported buttons to the list. The latter method is separated, as I would like to reuse both in the other tvOS PR.
| { | ||
| NSError *error; | ||
| BOOL hasActionButton = SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"16.0") | ||
| && [XCUIDevice.sharedDevice hasHardwareButton:XCUIDeviceButtonAction]; |
| [supportedButtonNames addObject:@"home"]; | ||
|
|
||
| #if __clang_major__ >= 17 || (__clang_major__ == 16 && __clang_minor__ >= 3) | ||
| if (@available(iOS 16.0, *) && [self hasHardwareButton:XCUIDeviceButtonAction]) { |
There was a problem hiding this comment.
I see headers below in Xcode 15.0 so I guess XCUIDeviceButtonAction exists in Xcode 15 as well.
typedef NS_ENUM(NSInteger, XCUIDeviceButton) {
XCUIDeviceButtonHome = 1,
XCUIDeviceButtonVolumeUp XCTEST_SIMULATOR_UNAVAILABLE("This API is not available in the Simulator, see the XCUIDeviceButton documentation for details.") = 2,
XCUIDeviceButtonVolumeDown XCTEST_SIMULATOR_UNAVAILABLE("This API is not available in the Simulator, see the XCUIDeviceButton documentation for details.") = 3,
#if TARGET_OS_WATCH || TARGET_OS_IOS
XCUIDeviceButtonAction = 4,
There was a problem hiding this comment.
I assume why Apple docs address they are available since Xcode 16.3 is they moved XCUIAutomation framework from private to public since the version
There was a problem hiding this comment.
#1115 (comment)
Hm, maybe it had a case that references didn't work properly(?)
Looks reasonable to requirethe newer versions like current implementation by following Apple's public doc
There was a problem hiding this comment.
The CI error seems to have been specifically due to XCUIDeviceButtonCamera, so it is likely it was added later than Xcode 15.
My guess is that the target for XCUIDeviceButtonAction is Xcode 15 (coincides with the release of iPhone 15 Pro (Max) which added it), while XCUIDeviceButtonCamera would be Xcode 16 (coincides with the release of the iPhone 16 lineup)
There was a problem hiding this comment.
Changed the guards to actually check if the constant is defined, rather than the Clang version
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| NSError *error; | ||
| BOOL hasActionButton = [XCUIDevice.sharedDevice fb_hasButton:@"action"]; | ||
| BOOL didPressButton = [XCUIDevice.sharedDevice fb_pressButton:@"action" | ||
| forDuration:nil | ||
| error:&error]; | ||
| if (hasActionButton) { | ||
| XCTAssertTrue(didPressButton); | ||
| XCTAssertNil(error); | ||
| } else { |
There was a problem hiding this comment.
NSError *error; is left uninitialized before being passed to fb_pressButton:... error:&error. Since fb_pressButton: does not set *error = nil on success, the subsequent XCTAssertNil(error) can be nondeterministic when the Action button exists and the press succeeds. Initialize error to nil before the call (and consider applying the same pattern in similar tests).
| } | ||
| } | ||
|
|
||
| - (BOOL)fb_hasButton:(NSString *)buttonName |
There was a problem hiding this comment.
I assume this is expected to be called only for non-tvOS, then wrapping the entire method with #if !TARGET_OS_TV and reduce it inside this method would simplify the context switching when we read the code. Then, we can assume this button is dedicated for non-tvOS env.
There was a problem hiding this comment.
I would like to extend it in the other tvOS PR, which is why I haven't added the target compiler guard for the whole method. Or would it be better to make two separate fb_hasButton methods?
| @param buttonName The name of the button to check (e.g., "home", "volumeUp", "volumeDown", "action", "camera") | ||
| @return YES if the button is available on the device, otherwise NO | ||
| */ | ||
| - (BOOL)fb_hasButton:(NSString *)buttonName; |
There was a problem hiding this comment.
Do you want to make this as a public method? Current usage is only in this WebDriverAgentLib/Categories/XCUIDevice+FBHelpers.m helper, so I assume we don't need to make this public til we need this from public space
| [supportedButtonNames addObject:buttonName]; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
consider moving private methods to the tail of the class definition
| [supportedButtonNames addObject:@"volumeUp"]; | ||
| [supportedButtonNames addObject:@"volumeDown"]; | ||
| #if defined(XCUIDeviceButtonCamera) | ||
| if ([buttonNameLC isEqualToString:@"camera"] && [self fb_hasButton:@"camera"]) { |
There was a problem hiding this comment.
are these conditions the same as inside fb_addButtonsIfAvailable ?
Currently WDA only supports the
home,volumeUpandvolumeDownbuttons for iOS, but Apple's documentation also listsactionandcamera. This PR adds support for them.Since not all devices have these buttons, their use is guarded behind the
hasHardwareButton:check, which itself requires iOS 16, so a second guard was also added.(I don't actually have a way to test this, so any validation would be appreciated)
Reference: https://developer.apple.com/documentation/xcuiautomation/xcuidevice/button?language=objc