FBClassChainQueryParser.h 3.4 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 <XCTest/XCTest.h>
  10. NS_ASSUME_NONNULL_BEGIN
  11. @interface FBAbstractPredicateItem : NSObject
  12. /*! The actual predicate value of an item */
  13. @property (nonatomic, readonly) NSPredicate *value;
  14. /**
  15. Instance constructor, which allows to set item value on instance creation
  16. @param value the actual predicate value
  17. @return FBAbstractPredicateItem instance
  18. */
  19. - (instancetype)initWithValue:(NSPredicate *)value;
  20. @end
  21. @interface FBSelfPredicateItem : FBAbstractPredicateItem
  22. @end
  23. @interface FBDescendantPredicateItem : FBAbstractPredicateItem
  24. @end
  25. @interface FBClassChainItem : NSObject
  26. /*! Element's position */
  27. @property (readonly, nonatomic, nullable) NSNumber *position;
  28. /*! Element's type */
  29. @property (readonly, nonatomic) XCUIElementType type;
  30. /*! Whether an element is a descendant of the previos element */
  31. @property (readonly, nonatomic) BOOL isDescendant;
  32. /*! The ordered list of matching predicates for the current element */
  33. @property (readonly, nonatomic) NSArray<FBAbstractPredicateItem *> *predicates;
  34. /**
  35. Instance constructor, which allows to set element type and position
  36. @param type on of supoported element types declared in XCUIElementType enum
  37. @param position element position relative to its sibling element. Numeration
  38. starts with 1. Zero value means that all sibling element should be selected.
  39. Negative value means that numeration starts from the last element, for example
  40. -1 is the last child element and -2 is the second last element.
  41. nil value means that no element position has been set explicitly.
  42. @param predicates the list of matching descendant/self predicates
  43. @param isDescendant equals to YES if the element is a descendantt element of
  44. the previous element in the chain. NO value means the element is the direct
  45. child of the previous element
  46. @return FBClassChainElement instance
  47. */
  48. - (instancetype)initWithType:(XCUIElementType)type position:(nullable NSNumber *)position predicates:(NSArray<FBAbstractPredicateItem *> *)predicates isDescendant:(BOOL)isDescendant;
  49. @end
  50. @interface FBClassChain : NSObject
  51. /*! Array of parsed chain items */
  52. @property (readonly, nonatomic, copy) NSArray<FBClassChainItem *> *elements;
  53. /**
  54. Instance constructor for parsed class chain instance
  55. @param elements an array of parsed chains elements
  56. @return FBClassChain instance
  57. */
  58. - (instancetype)initWithElements:(NSArray<FBClassChainItem *> *)elements;
  59. @end
  60. @interface FBClassChainQueryParser : NSObject
  61. /**
  62. Method used to interpret class chain queries
  63. @param classChainQuery class chain query as string. See the documentation of
  64. XCUIElement+FBClassChain category for more details about the expected query format
  65. @param error standard NSError object, which is going to be initializaed if
  66. there are query parsing errors
  67. @return list of parsed primitives packed to FBClassChainElement class or nil in case
  68. there was parsing error (the parameter will be initialized with detailed error description in such case)
  69. @throws FBUnknownAttributeException if any of predicates in the chain contains unknown attribute
  70. */
  71. + (nullable FBClassChain*)parseQuery:(NSString*)classChainQuery error:(NSError **)error;
  72. @end
  73. NS_ASSUME_NONNULL_END