@deque/axe-appium3-webdriveragent 1.7.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +1 -1
  2. package/WebDriverAgent.xcodeproj/project.pbxproj +61 -3
  3. package/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h +4 -1
  4. package/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m +35 -2
  5. package/WebDriverAgentLib/Categories/XCUIDevice+FBHelpers.h +6 -0
  6. package/WebDriverAgentLib/Categories/XCUIDevice+FBHelpers.m +100 -23
  7. package/WebDriverAgentLib/Categories/XCUIDevice+FBRotation.m +8 -3
  8. package/WebDriverAgentLib/Categories/XCUIElement+FBTyping.h +7 -0
  9. package/WebDriverAgentLib/Categories/XCUIElement+FBTyping.m +20 -0
  10. package/WebDriverAgentLib/Commands/AxeAuthCommands.h +4 -0
  11. package/WebDriverAgentLib/Commands/AxeAuthCommands.m +113 -56
  12. package/WebDriverAgentLib/Commands/AxeAutoScanCommands.m +1 -7
  13. package/WebDriverAgentLib/Commands/AxeScanCommands.m +57 -315
  14. package/WebDriverAgentLib/Commands/FBCustomCommands.m +8 -0
  15. package/WebDriverAgentLib/Commands/FBElementCommands.m +12 -5
  16. package/WebDriverAgentLib/Commands/FBSessionCommands.m +1 -1
  17. package/WebDriverAgentLib/Info.plist +2 -2
  18. package/WebDriverAgentLib/Routing/FBSession.m +2 -2
  19. package/WebDriverAgentLib/Utilities/FBConfiguration.h +2 -0
  20. package/WebDriverAgentLib/Utilities/FBConfiguration.m +1 -0
  21. package/WebDriverAgentLib/Utilities/FBHIDOperations.h +41 -0
  22. package/WebDriverAgentLib/Utilities/FBHIDOperations.m +244 -0
  23. package/WebDriverAgentLib/Utilities/FBSettings.h +1 -0
  24. package/WebDriverAgentLib/Utilities/FBSettings.m +1 -0
  25. package/WebDriverAgentLib/Utilities/FBSettingsHandler.m +26 -2
  26. package/WebDriverAgentTests/IntegrationApp/Classes/ViewController.m +11 -7
  27. package/WebDriverAgentTests/IntegrationTests/FBElementAttributeTests.m +44 -0
  28. package/WebDriverAgentTests/IntegrationTests/FBTypingTest.m +33 -0
  29. package/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m +111 -0
  30. package/WebDriverAgentTests/IntegrationTests/XCUIDeviceHelperTests.m +97 -0
  31. package/WebDriverAgentTests/IntegrationTests/XCUIDeviceRotationTests.m +53 -0
  32. package/WebDriverAgentTests/IntegrationTests_tvOS/FBTVFocusIntegrationTests.m +21 -0
  33. package/WebDriverAgentTests/IntegrationTests_watchOS/WDAAppLifecycleIntegrationTests.swift +12 -0
  34. package/axeDevToolsXCUI.xcframework/Info.plist +3 -3
  35. package/axeDevToolsXCUI.xcframework/LICENSE-3RD-PARTY-axe-devtools-ios.md +1 -1
  36. package/axeDevToolsXCUI.xcframework/{axe-devtools-ios-4.3.1.cdx.json → axe-devtools-ios-5.0.0.cdx.json} +6 -6
  37. package/axeDevToolsXCUI.xcframework/{axe-devtools-ios-4.3.1.spdx.json → axe-devtools-ios-5.0.0.spdx.json} +5 -5
  38. package/axeDevToolsXCUI.xcframework/ios-arm64/axeDevToolsXCUI.framework/Headers/AxeTestBundleObserver.h +0 -1
  39. package/axeDevToolsXCUI.xcframework/ios-arm64/axeDevToolsXCUI.framework/Headers/axeDevToolsXCUI-Swift.h +82 -228
  40. package/axeDevToolsXCUI.xcframework/ios-arm64/axeDevToolsXCUI.framework/Info.plist +4 -4
  41. package/axeDevToolsXCUI.xcframework/ios-arm64/axeDevToolsXCUI.framework/Modules/axeDevToolsXCUI.swiftmodule/arm64-apple-ios.abi.json +3120 -5759
  42. package/axeDevToolsXCUI.xcframework/ios-arm64/axeDevToolsXCUI.framework/Modules/axeDevToolsXCUI.swiftmodule/arm64-apple-ios.private.swiftinterface +53 -168
  43. package/axeDevToolsXCUI.xcframework/ios-arm64/axeDevToolsXCUI.framework/Modules/axeDevToolsXCUI.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  44. package/axeDevToolsXCUI.xcframework/ios-arm64/axeDevToolsXCUI.framework/Modules/axeDevToolsXCUI.swiftmodule/arm64-apple-ios.swiftinterface +53 -168
  45. package/axeDevToolsXCUI.xcframework/ios-arm64/axeDevToolsXCUI.framework/axeDevToolsXCUI +0 -0
  46. package/axeDevToolsXCUI.xcframework/ios-arm64_x86_64-simulator/axeDevToolsXCUI.framework/Headers/AxeTestBundleObserver.h +0 -1
  47. package/axeDevToolsXCUI.xcframework/ios-arm64_x86_64-simulator/axeDevToolsXCUI.framework/Headers/axeDevToolsXCUI-Swift.h +164 -456
  48. package/axeDevToolsXCUI.xcframework/ios-arm64_x86_64-simulator/axeDevToolsXCUI.framework/Info.plist +4 -4
  49. package/axeDevToolsXCUI.xcframework/ios-arm64_x86_64-simulator/axeDevToolsXCUI.framework/Modules/axeDevToolsXCUI.swiftmodule/arm64-apple-ios-simulator.abi.json +3120 -5759
  50. package/axeDevToolsXCUI.xcframework/ios-arm64_x86_64-simulator/axeDevToolsXCUI.framework/Modules/axeDevToolsXCUI.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +53 -168
  51. package/axeDevToolsXCUI.xcframework/ios-arm64_x86_64-simulator/axeDevToolsXCUI.framework/Modules/axeDevToolsXCUI.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  52. package/axeDevToolsXCUI.xcframework/ios-arm64_x86_64-simulator/axeDevToolsXCUI.framework/Modules/axeDevToolsXCUI.swiftmodule/arm64-apple-ios-simulator.swiftinterface +53 -168
  53. package/axeDevToolsXCUI.xcframework/ios-arm64_x86_64-simulator/axeDevToolsXCUI.framework/Modules/axeDevToolsXCUI.swiftmodule/x86_64-apple-ios-simulator.abi.json +3120 -5759
  54. package/axeDevToolsXCUI.xcframework/ios-arm64_x86_64-simulator/axeDevToolsXCUI.framework/Modules/axeDevToolsXCUI.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +53 -168
  55. package/axeDevToolsXCUI.xcframework/ios-arm64_x86_64-simulator/axeDevToolsXCUI.framework/Modules/axeDevToolsXCUI.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  56. package/axeDevToolsXCUI.xcframework/ios-arm64_x86_64-simulator/axeDevToolsXCUI.framework/Modules/axeDevToolsXCUI.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +53 -168
  57. package/axeDevToolsXCUI.xcframework/ios-arm64_x86_64-simulator/axeDevToolsXCUI.framework/_CodeSignature/CodeResources +25 -25
  58. package/axeDevToolsXCUI.xcframework/ios-arm64_x86_64-simulator/axeDevToolsXCUI.framework/axeDevToolsXCUI +0 -0
  59. package/build/lib/webdriveragent.d.ts.map +1 -1
  60. package/build/lib/webdriveragent.js +1 -2
  61. package/build/lib/webdriveragent.js.map +1 -1
  62. package/build/tsconfig.tsbuildinfo +1 -1
  63. package/lib/webdriveragent.ts +1 -2
  64. package/package.json +8 -10
@@ -67,6 +67,8 @@
67
67
  [[FBRoute GET:@"/wda/batteryInfo"] respondWithTarget:self action:@selector(handleGetBatteryInfo:)],
68
68
  #endif
69
69
  [[FBRoute POST:@"/wda/pressButton"] respondWithTarget:self action:@selector(handlePressButtonCommand:)],
70
+ [[FBRoute GET:@"/wda/pressableButtons"] respondWithTarget:self action:@selector(handleGetPressableButtons:)],
71
+ [[FBRoute GET:@"/wda/pressableButtons"].withoutSession respondWithTarget:self action:@selector(handleGetPressableButtons:)],
70
72
  #if TARGET_OS_WATCH
71
73
  [[FBRoute POST:@"/wda/rotateDigitalCrown"] respondWithTarget:self action:@selector(handleRotateDigitalCrownCommand:)],
72
74
  [[FBRoute POST:@"/wda/performHandGesture"] respondWithTarget:self action:@selector(handlePerformHandGestureCommand:)],
@@ -352,6 +354,12 @@
352
354
  return FBResponseWithOK();
353
355
  }
354
356
 
357
+ + (id<FBResponsePayload>)handleGetPressableButtons:(FBRouteRequest *)request
358
+ {
359
+ NSArray *xctestButtonNames = [FBAvailableButtonNames().allKeys sortedArrayUsingSelector:@selector(compare:)];
360
+ return FBResponseWithObject(@{@"xctest": xctestButtonNames});
361
+ }
362
+
355
363
  #if TARGET_OS_WATCH
356
364
  + (id<FBResponsePayload>)handleRotateDigitalCrownCommand:(FBRouteRequest *)request
357
365
  {
@@ -11,7 +11,6 @@
11
11
  #import "FBConfiguration.h"
12
12
  #import "FBScreen.h"
13
13
  #import "XCUIScreen.h"
14
- #import "FBKeyboard.h"
15
14
  #import "FBRoute.h"
16
15
  #import "FBRouteRequest.h"
17
16
  #import "FBRunLoopSpinner.h"
@@ -404,13 +403,14 @@
404
403
  if (direction) {
405
404
  NSString *const distanceString = request.arguments[@"distance"] ?: @"1.0";
406
405
  CGFloat distance = (CGFloat)distanceString.doubleValue;
407
- if ([direction isEqualToString:@"up"]) {
406
+ NSString *const directionLower = direction.lowercaseString;
407
+ if ([directionLower isEqualToString:@"up"]) {
408
408
  [element fb_scrollUpByNormalizedDistance:distance];
409
- } else if ([direction isEqualToString:@"down"]) {
409
+ } else if ([directionLower isEqualToString:@"down"]) {
410
410
  [element fb_scrollDownByNormalizedDistance:distance];
411
- } else if ([direction isEqualToString:@"left"]) {
411
+ } else if ([directionLower isEqualToString:@"left"]) {
412
412
  [element fb_scrollLeftByNormalizedDistance:distance];
413
- } else if ([direction isEqualToString:@"right"]) {
413
+ } else if ([directionLower isEqualToString:@"right"]) {
414
414
  [element fb_scrollRightByNormalizedDistance:distance];
415
415
  }
416
416
  return FBResponseWithOK();
@@ -556,6 +556,13 @@
556
556
  NSString *textToType = [request.arguments[@"value"] componentsJoinedByString:@""];
557
557
  NSUInteger frequency = [request.arguments[@"frequency"] unsignedIntegerValue] ?: FBConfiguration.sharedInstance.maxTypingFrequency;
558
558
  NSError *error;
559
+ #if TARGET_OS_IOS
560
+ NSTimeInterval keyboardWait = FBConfiguration.sharedInstance.keyboardWaitTimeout;
561
+ if (keyboardWait > 0) {
562
+ XCUIApplication *application = request.session.activeApplication ?: XCUIApplication.fb_activeApplication;
563
+ FBWaitForHittableKey(application, keyboardWait);
564
+ }
565
+ #endif
559
566
  if (!FBTypeText(textToType, frequency, &error)) {
560
567
  return FBResponseWithStatus([FBCommandStatus invalidElementStateErrorWithMessage:error.description
561
568
  traceback:nil]);
@@ -411,7 +411,7 @@
411
411
  if (nil != initialUrl) {
412
412
  return [self openDeepLink:initialUrl withApplication:bundleID timeout:nil];
413
413
  }
414
- [app activate];
414
+ [app fb_activate];
415
415
  return nil;
416
416
  }
417
417
 
@@ -15,11 +15,11 @@
15
15
  <key>CFBundlePackageType</key>
16
16
  <string>FMWK</string>
17
17
  <key>CFBundleShortVersionString</key>
18
- <string>1.7.1</string>
18
+ <string>2.0.0</string>
19
19
  <key>CFBundleSignature</key>
20
20
  <string>????</string>
21
21
  <key>CFBundleVersion</key>
22
- <string>1.7.1</string>
22
+ <string>2.0.0</string>
23
23
  <key>NSPrincipalClass</key>
24
24
  <string/>
25
25
  </dict>
@@ -437,7 +437,7 @@ static NSUInteger _committedTerminationCount = 0;
437
437
  app.launchEnvironment = environment ?: @{};
438
438
  [app launch];
439
439
  } else {
440
- [app activate];
440
+ [app fb_activate];
441
441
  }
442
442
  if (asApplicationUnderTest) {
443
443
  BOOL waitForQuiescence = app.fb_shouldWaitForQuiescence;
@@ -480,7 +480,7 @@ static NSUInteger _committedTerminationCount = 0;
480
480
  - (XCUIApplication *)activateApplicationWithBundleId:(NSString *)bundleIdentifier
481
481
  {
482
482
  XCUIApplication *app = [self makeApplicationWithBundleId:bundleIdentifier];
483
- [app activate];
483
+ [app fb_activate];
484
484
  return app;
485
485
  }
486
486
 
@@ -60,6 +60,8 @@ typedef NS_ENUM(NSInteger, FBConfigurationKeyboardPreference) {
60
60
 
61
61
  /*! The maximum typing frequency for all typing activities */
62
62
  @property (atomic, assign) NSUInteger maxTypingFrequency;
63
+ /*! Seconds to wait for a hittable key before typing on iOS. 0 disables the wait. */
64
+ @property (atomic, assign) NSTimeInterval keyboardWaitTimeout;
63
65
  @property (atomic, readonly) NSUInteger defaultTypingFrequency;
64
66
 
65
67
  /*! Use singleton test manager proxy */
@@ -343,6 +343,7 @@ static NSString *const axSettingsClassName = @"AXSettings";
343
343
  self.shouldUseCompactResponses = YES;
344
344
  self.elementResponseAttributes = @"type,label";
345
345
  self.maxTypingFrequencyOverride = @(self.defaultTypingFrequency);
346
+ self.keyboardWaitTimeout = 0;
346
347
  self.screenshotQuality = 3;
347
348
  self.useFirstMatch = NO;
348
349
  self.boundElementsByIndex = NO;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Copyright (c) 2015-present, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ #import <XCTest/XCTest.h>
10
+ #import <UIKit/UIKit.h>
11
+
12
+ /**
13
+ HID paths for Home, lock/unlock, and rotation on hinged iOS devices.
14
+
15
+ Remove each workaround once its XCTest-only path passes the corresponding regression
16
+ test on supported runtimes and both panels: testHomeButtonBackgroundsApplication,
17
+ testRepeatedLockUnlockAcrossHingePoses, and testRotationOnSelectedDuoDisplay.
18
+ Physical-device Home, lock/unlock, and rotation behavior require verification.
19
+
20
+ Once all paths are obsolete, remove the FBHIDOperations branches and imports from
21
+ XCUIDevice+FBHelpers.m and XCUIDevice+FBRotation.m, then delete this module and its
22
+ Xcode project entries. Hinge control in XCUIDevice+FBHinge is independent.
23
+
24
+ Tracking: https://github.com/appium/appium/issues/22857
25
+ Rotation: https://github.com/appium/appium-ios/pull/81
26
+ */
27
+ @interface FBHIDOperations : NSObject
28
+
29
+ // All operations apply to hinged iOS devices, including physical devices.
30
+ + (BOOL)appliesToDevice:(XCUIDevice *)device;
31
+
32
+ #if !TARGET_OS_TV && !TARGET_OS_WATCH
33
+ // Call only after the corresponding applicability check succeeds.
34
+ + (BOOL)pressHomeWithError:(NSError **)error;
35
+ + (BOOL)pressLockWithError:(NSError **)error;
36
+ // interfaceOrientation is the UIKit equivalent of the requested device orientation.
37
+ + (BOOL)rotateToOrientation:(UIDeviceOrientation)orientation
38
+ interfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
39
+ #endif
40
+
41
+ @end
@@ -0,0 +1,244 @@
1
+ /**
2
+ * Copyright (c) 2015-present, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ #import "FBHIDOperations.h"
10
+
11
+ #import <dlfcn.h>
12
+ #import <mach/mach_time.h>
13
+
14
+ #import "FBConfiguration.h"
15
+ #import "FBErrorBuilder.h"
16
+ #import "FBLogger.h"
17
+ #import "FBRunLoopSpinner.h"
18
+ #import "FBScreen.h"
19
+ #import "FBSession.h"
20
+ #import "XCUIScreen.h"
21
+ #import "XCUIDevice+FBHinge.h"
22
+ #import "XCUIApplication.h"
23
+ #import "XCUIApplication+FBHelpers.h"
24
+ #import "XCUIElement+FBUtilities.h"
25
+
26
+ #if !TARGET_OS_TV && !TARGET_OS_WATCH
27
+
28
+ static const uint32_t FBHIDConsumerUsagePage = 0x0C;
29
+ static const uint32_t FBHIDHomeUsage = 0x40;
30
+ static const uint32_t FBHIDPowerUsage = 0x30;
31
+ static const uint32_t FBHIDOrientationUsagePage = 0xff61;
32
+ static const uint32_t FBHIDOrientationUsage = 0x5b;
33
+ static const CFOptionFlags FBHIDBinarySerialization = 1;
34
+ static const NSTimeInterval FBHIDButtonPressDuration = 0.03;
35
+ static const NSTimeInterval FBHIDRotationTimeout = 5.0;
36
+
37
+ typedef struct {
38
+ CFTypeRef (*createKeyboardEvent)(CFAllocatorRef, uint64_t, uint32_t, uint32_t, Boolean, uint32_t);
39
+ CFTypeRef (*createVendorEvent)(CFAllocatorRef, uint64_t, uint32_t, uint32_t,
40
+ uint32_t, uint8_t *, CFIndex, uint32_t);
41
+ CFTypeRef (*createClient)(CFAllocatorRef);
42
+ void (*dispatchEvent)(CFTypeRef, CFTypeRef);
43
+ void (*setTimestamp)(CFTypeRef, uint64_t);
44
+ CFDataRef (*serialize)(CFTypeRef, CFOptionFlags);
45
+ } FBHIDAPI;
46
+
47
+ static const FBHIDAPI *FBGetHIDAPI(void)
48
+ {
49
+ static FBHIDAPI api;
50
+ static dispatch_once_t onceToken;
51
+ dispatch_once(&onceToken, ^{
52
+ // Keep the framework loaded for the lifetime of the cached function pointers.
53
+ void *handle = dlopen("/System/Library/Frameworks/IOKit.framework/IOKit", RTLD_LAZY);
54
+ if (NULL == handle) {
55
+ return;
56
+ }
57
+ api.createKeyboardEvent = (CFTypeRef (*)(CFAllocatorRef, uint64_t, uint32_t, uint32_t, Boolean, uint32_t))
58
+ dlsym(handle, "IOHIDEventCreateKeyboardEvent");
59
+ api.createVendorEvent = (CFTypeRef (*)(CFAllocatorRef, uint64_t, uint32_t, uint32_t,
60
+ uint32_t, uint8_t *, CFIndex, uint32_t))
61
+ dlsym(handle, "IOHIDEventCreateVendorDefinedEvent");
62
+ api.createClient = (CFTypeRef (*)(CFAllocatorRef))dlsym(handle, "IOHIDEventSystemClientCreate");
63
+ api.dispatchEvent = (void (*)(CFTypeRef, CFTypeRef))dlsym(handle, "IOHIDEventSystemClientDispatchEvent");
64
+ api.setTimestamp = (void (*)(CFTypeRef, uint64_t))dlsym(handle, "IOHIDEventSetTimeStamp");
65
+ api.serialize = (CFDataRef (*)(CFTypeRef, CFOptionFlags))dlsym(handle, "IOCFSerialize");
66
+ });
67
+ // Each operation checks only the symbols it needs.
68
+ return &api;
69
+ }
70
+
71
+ static void FBLogUnverifiedPhysicalHIDOperation(NSString *operation)
72
+ {
73
+ #if !TARGET_OS_SIMULATOR
74
+ [FBLogger logFmt:@"HID %@ on physical hinged devices: not verified yet.", operation];
75
+ #endif
76
+ }
77
+
78
+ static BOOL FBWaitForStableInterfaceOrientation(XCUIApplication *application,
79
+ UIInterfaceOrientation orientation)
80
+ {
81
+ [application fb_waitUntilStableWithTimeout:FBConfiguration.sharedInstance.animationCoolOffTimeout];
82
+ return application.interfaceOrientation == orientation;
83
+ }
84
+
85
+ // Workaround tracked in https://github.com/appium/appium/issues/22857.
86
+ // Reproduced on the iOS 27.1 Duo simulator with Xcode 27.1: XCTest's Home
87
+ // request returns without backgrounding the app. This direct HID path is also
88
+ // enabled on physical hinged devices, but Home behavior there is unverified.
89
+ // The affected Xcode/runtime version range has not been established. Remove
90
+ // the Home workaround when XCTest-only presses pass testHomeButtonBackgroundsApplication
91
+ // on supported Duo environments, including physical devices and both panels.
92
+ static BOOL FBPressHIDButton(uint32_t usage, NSError **error)
93
+ {
94
+ const FBHIDAPI *api = FBGetHIDAPI();
95
+ if (NULL == api->createKeyboardEvent || NULL == api->createClient
96
+ || NULL == api->dispatchEvent || NULL == api->setTimestamp) {
97
+ return [[FBErrorBuilder.builder withDescription:@"The button HID APIs are unavailable"] buildError:error];
98
+ }
99
+ CFTypeRef client = api->createClient(kCFAllocatorDefault);
100
+ CFTypeRef down = api->createKeyboardEvent(kCFAllocatorDefault, mach_absolute_time(),
101
+ FBHIDConsumerUsagePage, usage, YES, 0);
102
+ CFTypeRef up = api->createKeyboardEvent(kCFAllocatorDefault, mach_absolute_time(),
103
+ FBHIDConsumerUsagePage, usage, NO, 0);
104
+ BOOL ready = NULL != client && NULL != down && NULL != up;
105
+ if (ready) {
106
+ // Dispatch a short paired press. Holding Power for 0.5s invokes Siri on Duo.
107
+ api->dispatchEvent(client, down);
108
+ [NSThread sleepForTimeInterval:FBHIDButtonPressDuration];
109
+ api->setTimestamp(up, mach_absolute_time());
110
+ api->dispatchEvent(client, up);
111
+ }
112
+ if (NULL != down) {
113
+ CFRelease(down);
114
+ }
115
+ if (NULL != up) {
116
+ CFRelease(up);
117
+ }
118
+ if (NULL != client) {
119
+ CFRelease(client);
120
+ }
121
+ return ready || [[FBErrorBuilder.builder
122
+ withDescription:@"Cannot create the button HID event or client"] buildError:error];
123
+ }
124
+
125
+ // Work around XCTest updating Duo device orientation without rotating the app.
126
+ // Reproduction details and checks required before removing this workaround:
127
+ // https://github.com/appium/appium-ios/pull/81
128
+ static BOOL FBDispatchHIDOrientation(UIDeviceOrientation orientation)
129
+ {
130
+ XCUIScreen *screen = [FBScreen currentScreenWithError:nil];
131
+ if (nil == screen) {
132
+ return NO;
133
+ }
134
+ // The inner panel's native orientation is a quarter turn from the cover.
135
+ // Values match DeviceKit's orientation-picker-control (Xcode 27.1).
136
+ NSString *value;
137
+ switch (orientation) {
138
+ case UIDeviceOrientationPortrait:
139
+ value = screen.isMainScreen ? @"portrait" : @"landscape-left";
140
+ break;
141
+ case UIDeviceOrientationLandscapeLeft:
142
+ value = screen.isMainScreen ? @"landscape-left" : @"pud";
143
+ break;
144
+ case UIDeviceOrientationLandscapeRight:
145
+ value = screen.isMainScreen ? @"landscape-right" : @"portrait";
146
+ break;
147
+ case UIDeviceOrientationPortraitUpsideDown:
148
+ value = screen.isMainScreen ? @"pud" : @"landscape-right";
149
+ break;
150
+ case UIDeviceOrientationUnknown:
151
+ case UIDeviceOrientationFaceUp:
152
+ case UIDeviceOrientationFaceDown:
153
+ default:
154
+ return NO;
155
+ }
156
+
157
+ const FBHIDAPI *api = FBGetHIDAPI();
158
+ if (NULL == api->serialize || NULL == api->createVendorEvent
159
+ || NULL == api->createClient || NULL == api->dispatchEvent) {
160
+ return NO;
161
+ }
162
+ NSDictionary *payload = @{
163
+ @"provider": @"com.apple.Virtualization.VirtualMachines",
164
+ @"source": @"orientation-picker-control",
165
+ @"type": @"enum",
166
+ @"value": value,
167
+ };
168
+ // The receiver expects IOCF binary serialization, not a binary plist.
169
+ CFDataRef data = api->serialize((__bridge CFTypeRef)payload, FBHIDBinarySerialization);
170
+ if (NULL == data) {
171
+ return NO;
172
+ }
173
+ CFTypeRef event = api->createVendorEvent(kCFAllocatorDefault, mach_absolute_time(),
174
+ FBHIDOrientationUsagePage, FBHIDOrientationUsage, 0,
175
+ (uint8_t *)CFDataGetBytePtr(data), CFDataGetLength(data), 0);
176
+ CFRelease(data);
177
+ CFTypeRef client = api->createClient(kCFAllocatorDefault);
178
+ BOOL canDispatch = NULL != event && NULL != client;
179
+ if (canDispatch) {
180
+ api->dispatchEvent(client, event);
181
+ }
182
+ if (NULL != event) {
183
+ CFRelease(event);
184
+ }
185
+ if (NULL != client) {
186
+ CFRelease(client);
187
+ }
188
+ return canDispatch;
189
+ }
190
+
191
+ #endif
192
+
193
+ @implementation FBHIDOperations
194
+
195
+ + (BOOL)appliesToDevice:(XCUIDevice *)device
196
+ {
197
+ #if !TARGET_OS_TV && !TARGET_OS_WATCH
198
+ return device.fb_supportsHingeAngleReading;
199
+ #else
200
+ return NO;
201
+ #endif
202
+ }
203
+
204
+ #if !TARGET_OS_TV && !TARGET_OS_WATCH
205
+ + (BOOL)pressHomeWithError:(NSError **)error
206
+ {
207
+ FBLogUnverifiedPhysicalHIDOperation(@"Home");
208
+ return FBPressHIDButton(FBHIDHomeUsage, error);
209
+ }
210
+
211
+ + (BOOL)pressLockWithError:(NSError **)error
212
+ {
213
+ FBLogUnverifiedPhysicalHIDOperation(@"lock");
214
+ // XCTest locking times out on Duo / iOS 27.1 (Xcode 27.1). Remove this
215
+ // workaround once XCTest alone passes testRepeatedLockUnlockAcrossHingePoses.
216
+ return FBPressHIDButton(FBHIDPowerUsage, error);
217
+ }
218
+
219
+ + (BOOL)rotateToOrientation:(UIDeviceOrientation)orientation
220
+ interfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
221
+ {
222
+ FBLogUnverifiedPhysicalHIDOperation(@"rotation");
223
+ XCUIApplication *application = XCUIApplication.fb_activeApplication;
224
+ // Point-based detection can select the cover SpringBoard while the app
225
+ // is on the inner panel. Prefer the session's active application.
226
+ application = FBSession.activeSession.activeApplication ?: application;
227
+ // Keep XCTest's reported device orientation in sync on the simulator too.
228
+ [XCUIDevice sharedDevice].orientation = orientation;
229
+ // On Duo simulators XCTest can update its value without rotating the app.
230
+ // Use the same direct HID path on simulators and physical hinged devices.
231
+ if (!FBDispatchHIDOrientation(orientation)) {
232
+ return NO;
233
+ }
234
+ // Event dispatch is asynchronous. Check the app, not just XCTest's value.
235
+ if (![[[FBRunLoopSpinner new] timeout:FBHIDRotationTimeout] spinUntilTrue:^BOOL{
236
+ return application.interfaceOrientation == interfaceOrientation;
237
+ }]) {
238
+ return NO;
239
+ }
240
+ return FBWaitForStableInterfaceOrientation(application, interfaceOrientation);
241
+ }
242
+ #endif
243
+
244
+ @end
@@ -36,6 +36,7 @@ extern NSString* const FB_SETTING_SCREENSHOT_ORIENTATION;
36
36
  extern NSString* const FB_SETTING_WAIT_FOR_IDLE_TIMEOUT;
37
37
  extern NSString* const FB_SETTING_ANIMATION_COOL_OFF_TIMEOUT;
38
38
  extern NSString* const FB_SETTING_MAX_TYPING_FREQUENCY;
39
+ extern NSString* const FB_SETTING_KEYBOARD_WAIT_TIMEOUT;
39
40
  extern NSString* const FB_SETTING_RESPECT_SYSTEM_ALERTS;
40
41
  extern NSString* const FB_SETTING_USE_CLEAR_TEXT_SHORTCUT;
41
42
  extern NSString* const FB_SETTING_LIMIT_XPATH_CONTEXT_SCOPE;
@@ -32,6 +32,7 @@ NSString* const FB_SETTING_SCREENSHOT_ORIENTATION = @"screenshotOrientation";
32
32
  NSString* const FB_SETTING_WAIT_FOR_IDLE_TIMEOUT = @"waitForIdleTimeout";
33
33
  NSString* const FB_SETTING_ANIMATION_COOL_OFF_TIMEOUT = @"animationCoolOffTimeout";
34
34
  NSString* const FB_SETTING_MAX_TYPING_FREQUENCY = @"maxTypingFrequency";
35
+ NSString* const FB_SETTING_KEYBOARD_WAIT_TIMEOUT = @"keyboardWaitTimeout";
35
36
  NSString* const FB_SETTING_RESPECT_SYSTEM_ALERTS = @"respectSystemAlerts";
36
37
  NSString* const FB_SETTING_USE_CLEAR_TEXT_SHORTCUT = @"useClearTextShortcut";
37
38
  NSString* const FB_SETTING_LIMIT_XPATH_CONTEXT_SCOPE = @"limitXPathContextScope";
@@ -8,6 +8,8 @@
8
8
 
9
9
  #import "FBSettingsHandler.h"
10
10
 
11
+ #import <math.h>
12
+
11
13
  #import "FBActiveAppDetectionPoint.h"
12
14
  #import "FBClassChainQueryParser.h"
13
15
  #import "FBCommandStatus.h"
@@ -35,6 +37,7 @@ static NSSet<NSString *> *FBNilClearableSettingKeys(void)
35
37
  FB_SETTING_DISMISS_ALERT_BUTTON_SELECTOR,
36
38
  FB_SETTING_AUTO_CLICK_ALERT_SELECTOR,
37
39
  FB_SETTING_CURRENT_DISPLAY_ID,
40
+ FB_SETTING_KEYBOARD_WAIT_TIMEOUT,
38
41
  nil];
39
42
  });
40
43
  return keys;
@@ -160,6 +163,24 @@ static NSSet<NSString *> *FBNilClearableSettingKeys(void)
160
163
  FBConfiguration.sharedInstance.maxTypingFrequency = [value unsignedIntegerValue];
161
164
  return nil;
162
165
  };
166
+ map[FB_SETTING_KEYBOARD_WAIT_TIMEOUT] = ^FBCommandStatus *(FBSession *session, id value) {
167
+ if (nil == value) {
168
+ FBConfiguration.sharedInstance.keyboardWaitTimeout = 0;
169
+ return nil;
170
+ }
171
+ if (![value isKindOfClass:NSNumber.class]
172
+ || CFGetTypeID((__bridge CFTypeRef)value) == CFBooleanGetTypeID()) {
173
+ return [FBCommandStatus invalidArgumentErrorWithMessage:@"keyboardWaitTimeout must be a non-negative number of seconds"
174
+ traceback:nil];
175
+ }
176
+ double timeout = [(NSNumber *)value doubleValue];
177
+ if (timeout < 0 || !isfinite(timeout)) {
178
+ return [FBCommandStatus invalidArgumentErrorWithMessage:@"keyboardWaitTimeout must be a non-negative number of seconds"
179
+ traceback:nil];
180
+ }
181
+ FBConfiguration.sharedInstance.keyboardWaitTimeout = timeout;
182
+ return nil;
183
+ };
163
184
  map[FB_SETTING_USE_CLEAR_TEXT_SHORTCUT] = ^FBCommandStatus *(FBSession *session, id value) {
164
185
  FBConfiguration.sharedInstance.useClearTextShortcut = [value boolValue];
165
186
  return nil;
@@ -254,10 +275,10 @@ static NSSet<NSString *> *FBNilClearableSettingKeys(void)
254
275
  return @(FBConfiguration.sharedInstance.screenshotQuality);
255
276
  };
256
277
  map[FB_SETTING_KEYBOARD_AUTOCORRECTION] = ^id(FBSession *session) {
257
- return @(FBConfiguration.sharedInstance.keyboardAutocorrection);
278
+ return @((BOOL)(FBConfiguration.sharedInstance.keyboardAutocorrection == FBConfigurationKeyboardPreferenceEnabled));
258
279
  };
259
280
  map[FB_SETTING_KEYBOARD_PREDICTION] = ^id(FBSession *session) {
260
- return @(FBConfiguration.sharedInstance.keyboardPrediction);
281
+ return @((BOOL)(FBConfiguration.sharedInstance.keyboardPrediction == FBConfigurationKeyboardPreferenceEnabled));
261
282
  };
262
283
  map[FB_SETTING_SNAPSHOT_MAX_DEPTH] = ^id(FBSession *session) {
263
284
  return @(FBConfiguration.sharedInstance.snapshotMaxDepth);
@@ -304,6 +325,9 @@ static NSSet<NSString *> *FBNilClearableSettingKeys(void)
304
325
  map[FB_SETTING_MAX_TYPING_FREQUENCY] = ^id(FBSession *session) {
305
326
  return @(FBConfiguration.sharedInstance.maxTypingFrequency);
306
327
  };
328
+ map[FB_SETTING_KEYBOARD_WAIT_TIMEOUT] = ^id(FBSession *session) {
329
+ return @(FBConfiguration.sharedInstance.keyboardWaitTimeout);
330
+ };
307
331
  map[FB_SETTING_RESPECT_SYSTEM_ALERTS] = ^id(FBSession *session) {
308
332
  return @(FBConfiguration.sharedInstance.shouldRespectSystemAlerts);
309
333
  };
@@ -111,10 +111,20 @@
111
111
  }
112
112
 
113
113
  #if !TARGET_OS_TV
114
+ - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
115
+ {
116
+ [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
117
+ [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
118
+ // A 180-degree rotation can leave bounds unchanged. Read the scene after
119
+ // the transition as well as during layout.
120
+ [self updateOrentationLabel];
121
+ }];
122
+ }
123
+
114
124
  - (void)updateOrentationLabel
115
125
  {
116
126
  NSString *orientation = nil;
117
- switch (UIDevice.currentDevice.orientation) {
127
+ switch (self.view.window.windowScene.interfaceOrientation) {
118
128
  case UIInterfaceOrientationPortrait:
119
129
  orientation = @"Portrait";
120
130
  break;
@@ -127,12 +137,6 @@
127
137
  case UIInterfaceOrientationLandscapeRight:
128
138
  orientation = @"LandscapeRight";
129
139
  break;
130
- case UIDeviceOrientationFaceUp:
131
- orientation = @"FaceUp";
132
- break;
133
- case UIDeviceOrientationFaceDown:
134
- orientation = @"FaceDown";
135
- break;
136
140
  case UIInterfaceOrientationUnknown:
137
141
  orientation = @"Unknown";
138
142
  break;
@@ -12,11 +12,37 @@
12
12
  #import "FBFindElementCommands.h"
13
13
  #import "FBTestMacros.h"
14
14
  #import "FBXCodeCompatibility.h"
15
+ #import "XCUIApplication+FBHelpers.h"
15
16
  #import "XCUIElement+FBAccessibility.h"
16
17
  #import "XCUIElement+FBCustomActions.h"
17
18
  #import "XCUIElement+FBIsVisible.h"
18
19
  #import "XCUIElement+FBWebDriverAttributes.h"
19
20
 
21
+ static void FBCountTreeNodes(NSDictionary *tree, NSUInteger *nodesCount, NSUInteger *customActionsCount)
22
+ {
23
+ *nodesCount += 1;
24
+ if (nil != tree[@"customActions"]) {
25
+ *customActionsCount += 1;
26
+ }
27
+ for (NSDictionary *child in tree[@"children"]) {
28
+ FBCountTreeNodes(child, nodesCount, customActionsCount);
29
+ }
30
+ }
31
+
32
+ static NSDictionary *FBFindTreeButton(NSDictionary *tree, NSString *name)
33
+ {
34
+ if ([tree[@"type"] isEqualToString:@"Button"] && [tree[@"name"] isEqual:name]) {
35
+ return tree;
36
+ }
37
+ for (NSDictionary *child in tree[@"children"]) {
38
+ NSDictionary *result = FBFindTreeButton(child, name);
39
+ if (nil != result) {
40
+ return result;
41
+ }
42
+ }
43
+ return nil;
44
+ }
45
+
20
46
  @interface FBElementAttributeTests : FBIntegrationTestCase
21
47
  @end
22
48
 
@@ -270,4 +296,22 @@
270
296
  XCTAssertEqualObjects(customActions, @"Custom Action 1,Custom Action 2");
271
297
  }
272
298
 
299
+ - (void)testCustomActionsInJSONTree
300
+ {
301
+ NSDictionary *tree = self.testedApplication.fb_tree;
302
+ NSUInteger nodesCount = 0;
303
+ NSUInteger customActionsCount = 0;
304
+ FBCountTreeNodes(tree, &nodesCount, &customActionsCount);
305
+ XCTAssertEqual(customActionsCount, nodesCount);
306
+ NSDictionary *button = FBFindTreeButton(tree, @"Button");
307
+ XCTAssertEqualObjects(button[@"customActions"], @"Custom Action 1,Custom Action 2");
308
+
309
+ tree = [self.testedApplication fb_tree:[NSSet setWithObject:@"customActions"]];
310
+ XCTAssertNotNil(FBFindTreeButton(tree, @"Button"));
311
+ nodesCount = 0;
312
+ customActionsCount = 0;
313
+ FBCountTreeNodes(tree, &nodesCount, &customActionsCount);
314
+ XCTAssertEqual(customActionsCount, 0);
315
+ }
316
+
273
317
  @end
@@ -8,6 +8,7 @@
8
8
 
9
9
  #import <XCTest/XCTest.h>
10
10
 
11
+ #import "FBConfiguration.h"
11
12
  #import "FBIntegrationTestCase.h"
12
13
  #import "XCUIElement.h"
13
14
  #import "XCUIElement+FBTyping.h"
@@ -24,6 +25,12 @@
24
25
  [self goToAttributesPage];
25
26
  }
26
27
 
28
+ - (void)tearDown
29
+ {
30
+ FBConfiguration.sharedInstance.keyboardWaitTimeout = 0;
31
+ [super tearDown];
32
+ }
33
+
27
34
  - (void)testTextTyping
28
35
  {
29
36
  NSString *text = @"Happy typing";
@@ -49,6 +56,32 @@
49
56
  XCTAssertEqualObjects(textField.value, expectedText);
50
57
  }
51
58
 
59
+ - (void)testTextTypingImmediatelyAfterFocus
60
+ {
61
+ // The field is a storyboard UIKit text field. This passes with the pause off,
62
+ // which is the default, and it does not reproduce a dropped character.
63
+ NSString *text = @"TheQuickBrownFox123!";
64
+ XCUIElement *textField = self.testedApplication.textFields[@"aIdentifier"];
65
+ [textField tap];
66
+ NSError *error;
67
+ XCTAssertTrue([textField fb_typeText:text shouldClear:NO error:&error]);
68
+ XCTAssertNil(error);
69
+ XCTAssertEqualObjects(textField.value, text);
70
+ }
71
+
72
+ - (void)testTextTypingWithKeyboardWaitTimeout
73
+ {
74
+ // The field is a storyboard UIKit text field. This does not reproduce a dropped character.
75
+ FBConfiguration.sharedInstance.keyboardWaitTimeout = 0.5;
76
+ NSString *text = @"TheQuickBrownFox123!";
77
+ XCUIElement *textField = self.testedApplication.textFields[@"aIdentifier"];
78
+ [textField tap];
79
+ NSError *error;
80
+ XCTAssertTrue([textField fb_typeText:text shouldClear:NO error:&error]);
81
+ XCTAssertNil(error);
82
+ XCTAssertEqualObjects(textField.value, text);
83
+ }
84
+
52
85
  - (void)testTextClearing
53
86
  {
54
87
  XCUIElement *textField = self.testedApplication.textFields[@"aIdentifier"];