-
Notifications
You must be signed in to change notification settings - Fork 500
feat: add action and camera values for mobile: pressButton
#1115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
88de359
9567bbb
77352bd
818d8d6
2098b98
8f4c7bd
32a676d
9420780
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,41 @@ | |
| static const NSTimeInterval FBHomeButtonCoolOffTime = 1.; | ||
| static const NSTimeInterval FBScreenLockTimeout = 5.; | ||
|
|
||
| NSDictionary<NSString *, NSNumber *> *availableButtonNames(void) { | ||
| static dispatch_once_t onceToken; | ||
| static NSDictionary *result; | ||
| dispatch_once(&onceToken, ^{ | ||
| NSMutableDictionary *buttons = [NSMutableDictionary dictionary]; | ||
|
|
||
| // Home button is always available | ||
| buttons[@"home"] = @(XCUIDeviceButtonHome); | ||
|
|
||
| #if !TARGET_OS_TV | ||
| #if !TARGET_OS_SIMULATOR | ||
| buttons[@"volumeup"] = @(XCUIDeviceButtonVolumeUp); | ||
| buttons[@"volumedown"] = @(XCUIDeviceButtonVolumeDown); | ||
| #endif | ||
|
|
||
| if (@available(iOS 16.0, *)) { | ||
| #if defined(XCUIDeviceButtonAction) | ||
| if ([XCUIDevice.sharedDevice hasHardwareButton:XCUIDeviceButtonAction]) { | ||
| buttons[@"action"] = @(XCUIDeviceButtonAction); | ||
| } | ||
| #endif | ||
| #if defined(XCUIDeviceButtonCamera) | ||
| #if !TARGET_OS_SIMULATOR | ||
| if ([XCUIDevice.sharedDevice hasHardwareButton:XCUIDeviceButtonCamera]) { | ||
| buttons[@"camera"] = @(XCUIDeviceButtonCamera); | ||
| } | ||
| #endif | ||
| #endif | ||
| } | ||
| #endif | ||
| result = [buttons copy]; | ||
| }); | ||
| return result; | ||
| } | ||
|
|
||
| @implementation XCUIDevice (FBHelpers) | ||
|
|
||
| static bool fb_isLocked; | ||
|
|
@@ -210,6 +245,11 @@ - (BOOL)fb_activateSiriVoiceRecognitionWithText:(NSString *)text error:(NSError | |
| } | ||
| } | ||
|
|
||
| - (BOOL)fb_hasButton:(NSString *)buttonName | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this is expected to be called only for non-tvOS, then wrapping the entire method with
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally yes. One is dedicated for tvOS and the other is iPhone, rather than mixed up both in one method and add many if/endif in it. (this is more internal/private method thing) |
||
| { | ||
| return availableButtonNames()[buttonName.lowercaseString] != nil; | ||
| } | ||
|
|
||
| - (BOOL)fb_pressButton:(NSString *)buttonName | ||
| forDuration:(nullable NSNumber *)duration | ||
| error:(NSError **)error | ||
|
|
@@ -270,7 +310,7 @@ - (BOOL)fb_pressButton:(NSString *)buttonName | |
|
|
||
| if (remoteButton == -1) { | ||
| return [[[FBErrorBuilder builder] | ||
| withDescriptionFormat:@"The button '%@' is unknown. Only the following button names are supported: %@", buttonName, supportedButtonNames] | ||
| withDescriptionFormat:@"The button '%@' is not supported. The device under test only supports the following buttons: %@", buttonName, supportedButtonNames] | ||
| buildError:error]; | ||
| } | ||
|
|
||
|
|
@@ -290,29 +330,15 @@ - (BOOL)fb_pressButton:(NSString *)buttonName | |
| - (BOOL)fb_pressButton:(NSString *)buttonName | ||
| error:(NSError **)error | ||
| { | ||
| NSMutableArray<NSString *> *supportedButtonNames = [NSMutableArray array]; | ||
| XCUIDeviceButton dstButton = 0; | ||
| if ([buttonName.lowercaseString isEqualToString:@"home"]) { | ||
| dstButton = XCUIDeviceButtonHome; | ||
| } | ||
| [supportedButtonNames addObject:@"home"]; | ||
| #if !TARGET_OS_SIMULATOR | ||
| if ([buttonName.lowercaseString isEqualToString:@"volumeup"]) { | ||
| dstButton = XCUIDeviceButtonVolumeUp; | ||
| } | ||
| if ([buttonName.lowercaseString isEqualToString:@"volumedown"]) { | ||
| dstButton = XCUIDeviceButtonVolumeDown; | ||
| } | ||
| [supportedButtonNames addObject:@"volumeUp"]; | ||
| [supportedButtonNames addObject:@"volumeDown"]; | ||
| #endif | ||
|
|
||
| if (dstButton == 0) { | ||
| NSDictionary<NSString *, NSNumber *> *availableButtons = availableButtonNames(); | ||
| NSNumber *buttonValue = availableButtons[buttonName.lowercaseString]; | ||
|
|
||
| if (!buttonValue) { | ||
| return [[[FBErrorBuilder builder] | ||
| withDescriptionFormat:@"The button '%@' is unknown. Only the following button names are supported: %@", buttonName, supportedButtonNames] | ||
| withDescriptionFormat:@"The button '%@' is not supported. The device under test only supports the following buttons: %@", buttonName, availableButtons.allKeys] | ||
| buildError:error]; | ||
| } | ||
| [self pressButton:dstButton]; | ||
| [self pressButton:(XCUIDeviceButton)[buttonValue unsignedIntegerValue]]; | ||
| return YES; | ||
| } | ||
| #endif | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.