FBXCodeCompatibility.m 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. */
  9. #import "FBXCodeCompatibility.h"
  10. #import "FBXCAXClientProxy.h"
  11. #import "FBConfiguration.h"
  12. #import "FBErrorBuilder.h"
  13. #import "FBLogger.h"
  14. #import "XCUIApplication+FBHelpers.h"
  15. #import "XCUIElementQuery.h"
  16. #import "FBXCTestDaemonsProxy.h"
  17. #import "XCTestManager_ManagerInterface-Protocol.h"
  18. @implementation XCUIElementQuery (FBCompatibility)
  19. - (XCElementSnapshot *)fb_uniqueSnapshotWithError:(NSError **)error
  20. {
  21. return [self uniqueMatchingSnapshotWithError:error];
  22. }
  23. - (XCUIElement *)fb_firstMatch
  24. {
  25. if (FBConfiguration.useFirstMatch) {
  26. XCUIElement* match = self.firstMatch;
  27. return [match exists] ? match : nil;
  28. }
  29. return self.fb_allMatches.firstObject;
  30. }
  31. - (NSArray<XCUIElement *> *)fb_allMatches
  32. {
  33. return FBConfiguration.boundElementsByIndex
  34. ? self.allElementsBoundByIndex
  35. : self.allElementsBoundByAccessibilityElement;
  36. }
  37. @end
  38. @implementation XCUIElement (FBCompatibility)
  39. + (BOOL)fb_supportsNonModalElementsInclusion
  40. {
  41. static dispatch_once_t hasIncludingNonModalElements;
  42. static BOOL result;
  43. dispatch_once(&hasIncludingNonModalElements, ^{
  44. result = [XCUIApplication.fb_systemApplication.query respondsToSelector:@selector(includingNonModalElements)];
  45. });
  46. return result;
  47. }
  48. - (XCUIElementQuery *)fb_query
  49. {
  50. return FBConfiguration.includeNonModalElements && self.class.fb_supportsNonModalElementsInclusion
  51. ? self.query.includingNonModalElements
  52. : self.query;
  53. }
  54. @end
  55. @implementation XCPointerEvent (FBXcodeCompatibility)
  56. + (BOOL)fb_areKeyEventsSupported
  57. {
  58. static BOOL isKbInputSupported = NO;
  59. static dispatch_once_t onceKbInputSupported;
  60. dispatch_once(&onceKbInputSupported, ^{
  61. isKbInputSupported = [XCPointerEvent.class respondsToSelector:@selector(keyboardEventForKeyCode:keyPhase:modifierFlags:offset:)];
  62. });
  63. return isKbInputSupported;
  64. }
  65. @end
  66. NSInteger FBTestmanagerdVersion(void)
  67. {
  68. static dispatch_once_t getTestmanagerdVersion;
  69. static NSInteger testmanagerdVersion;
  70. dispatch_once(&getTestmanagerdVersion, ^{
  71. id<XCTestManager_ManagerInterface> proxy = [FBXCTestDaemonsProxy testRunnerProxy];
  72. if ([(NSObject *)proxy respondsToSelector:@selector(_XCT_exchangeProtocolVersion:reply:)]) {
  73. [FBRunLoopSpinner spinUntilCompletion:^(void(^completion)(void)){
  74. [proxy _XCT_exchangeProtocolVersion:testmanagerdVersion reply:^(unsigned long long code) {
  75. testmanagerdVersion = (NSInteger) code;
  76. completion();
  77. }];
  78. }];
  79. } else {
  80. testmanagerdVersion = 0xFFFF;
  81. }
  82. });
  83. return testmanagerdVersion;
  84. }