XCUIElement+FBAccessibility.m 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 "XCUIElement+FBAccessibility.h"
  10. #import "FBConfiguration.h"
  11. #import "XCTestPrivateSymbols.h"
  12. #import "XCUIElement+FBUtilities.h"
  13. #import "FBXCElementSnapshotWrapper+Helpers.h"
  14. @implementation XCUIElement (FBAccessibility)
  15. - (BOOL)fb_isAccessibilityElement
  16. {
  17. id<FBXCElementSnapshot> snapshot = [self fb_standardSnapshot];
  18. return [FBXCElementSnapshotWrapper ensureWrapped:snapshot].fb_isAccessibilityElement;
  19. }
  20. @end
  21. @implementation FBXCElementSnapshotWrapper (FBAccessibility)
  22. - (BOOL)fb_isAccessibilityElement
  23. {
  24. NSNumber *isAccessibilityElement = self.additionalAttributes[FB_XCAXAIsElementAttribute];
  25. if (nil != isAccessibilityElement) {
  26. return isAccessibilityElement.boolValue;
  27. }
  28. NSError *error;
  29. NSNumber *attributeValue = [self fb_attributeValue:FB_XCAXAIsElementAttributeName
  30. error:&error];
  31. if (nil != attributeValue) {
  32. NSMutableDictionary *updatedValue = [NSMutableDictionary dictionaryWithDictionary:self.additionalAttributes ?: @{}];
  33. [updatedValue setObject:attributeValue forKey:FB_XCAXAIsElementAttribute];
  34. self.snapshot.additionalAttributes = updatedValue.copy;
  35. return [attributeValue boolValue];
  36. }
  37. NSLog(@"Cannot determine accessibility of '%@' natively: %@. Defaulting to: %@",
  38. self.fb_description, error.description, @(NO));
  39. return NO;
  40. }
  41. @end