XCUIApplication+FBTouchAction.m 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 "XCUIApplication+FBTouchAction.h"
  10. #import "FBBaseActionsSynthesizer.h"
  11. #import "FBConfiguration.h"
  12. #import "FBExceptions.h"
  13. #import "FBLogger.h"
  14. #import "FBRunLoopSpinner.h"
  15. #import "FBW3CActionsSynthesizer.h"
  16. #import "FBXCTestDaemonsProxy.h"
  17. #import "XCEventGenerator.h"
  18. #import "XCUIElement+FBUtilities.h"
  19. #if !TARGET_OS_TV
  20. @implementation XCUIApplication (FBTouchAction)
  21. + (BOOL)handleEventSynthesWithError:(NSError *)error
  22. {
  23. if ([error.localizedDescription containsString:@"not visible"]) {
  24. [[NSException exceptionWithName:FBElementNotVisibleException
  25. reason:error.localizedDescription
  26. userInfo:error.userInfo] raise];
  27. }
  28. return NO;
  29. }
  30. - (BOOL)fb_performActionsWithSynthesizerType:(Class)synthesizerType
  31. actions:(NSArray *)actions
  32. elementCache:(FBElementCache *)elementCache
  33. error:(NSError **)error
  34. {
  35. FBBaseActionsSynthesizer *synthesizer = [[synthesizerType alloc] initWithActions:actions
  36. forApplication:self
  37. elementCache:elementCache
  38. error:error];
  39. if (nil == synthesizer) {
  40. return NO;
  41. }
  42. XCSynthesizedEventRecord *eventRecord = [synthesizer synthesizeWithError:error];
  43. if (nil == eventRecord) {
  44. return [self.class handleEventSynthesWithError:*error];
  45. }
  46. return [self fb_synthesizeEvent:eventRecord error:error];
  47. }
  48. - (BOOL)fb_performW3CActions:(NSArray *)actions
  49. elementCache:(FBElementCache *)elementCache
  50. error:(NSError **)error
  51. {
  52. if (![self fb_performActionsWithSynthesizerType:FBW3CActionsSynthesizer.class
  53. actions:actions
  54. elementCache:elementCache
  55. error:error]) {
  56. return NO;
  57. }
  58. [self fb_waitUntilStableWithTimeout:FBConfiguration.animationCoolOffTimeout];
  59. return YES;
  60. }
  61. - (BOOL)fb_synthesizeEvent:(XCSynthesizedEventRecord *)event error:(NSError *__autoreleasing*)error
  62. {
  63. return [FBXCTestDaemonsProxy synthesizeEventWithRecord:event error:error];
  64. }
  65. @end
  66. #endif