XCUIElement+FBVisibleFrame.m 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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+FBVisibleFrame.h"
  10. #import "FBElementUtils.h"
  11. #import "FBXCodeCompatibility.h"
  12. #import "FBXCElementSnapshotWrapper+Helpers.h"
  13. #import "XCUIElement+FBUtilities.h"
  14. #import "XCTestPrivateSymbols.h"
  15. @implementation XCUIElement (FBVisibleFrame)
  16. - (CGRect)fb_visibleFrame
  17. {
  18. id<FBXCElementSnapshot> snapshot = [self fb_standardSnapshot];
  19. return [FBXCElementSnapshotWrapper ensureWrapped:snapshot].fb_visibleFrame;
  20. }
  21. @end
  22. @implementation FBXCElementSnapshotWrapper (FBVisibleFrame)
  23. - (CGRect)fb_visibleFrame
  24. {
  25. CGRect thisVisibleFrame = [self visibleFrame];
  26. if (!CGRectIsEmpty(thisVisibleFrame)) {
  27. return thisVisibleFrame;
  28. }
  29. NSDictionary *visibleFrameDict = [self fb_attributeValue:FB_XCAXAVisibleFrameAttributeName
  30. error:nil];
  31. if (nil == visibleFrameDict) {
  32. return thisVisibleFrame;
  33. }
  34. id x = [visibleFrameDict objectForKey:@"X"];
  35. id y = [visibleFrameDict objectForKey:@"Y"];
  36. id height = [visibleFrameDict objectForKey:@"Height"];
  37. id width = [visibleFrameDict objectForKey:@"Width"];
  38. if (x != nil && y != nil && height != nil && width != nil) {
  39. return CGRectMake([x doubleValue], [y doubleValue], [width doubleValue], [height doubleValue]);
  40. }
  41. return thisVisibleFrame;
  42. }
  43. @end