appium-webdriveragent 17.0.13 → 17.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/WebDriverAgentLib/Info.plist +2 -2
- package/WebDriverAgentLib/Utilities/FBClassChainQueryParser.h +4 -1
- package/WebDriverAgentLib/Utilities/FBClassChainQueryParser.m +252 -466
- package/WebDriverAgentTests/UnitTests/FBClassChainTests.m +179 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [17.0.14](https://github.com/appium/appium-ios/compare/appium-webdriveragent@17.0.13...appium-webdriveragent@17.0.14) (2026-11-22)
|
|
7
|
+
|
|
8
|
+
### Code Refactoring
|
|
9
|
+
|
|
10
|
+
* **webdriveragent:** replace the class chain tokenizer with a recursive-descent parser ([#234](https://github.com/appium/appium-ios/issues/234)) ([23e77cb](https://github.com/appium/appium-ios/commit/23e77cbf250a5edc100a147fe3a7e3ac4a1adb29))
|
|
11
|
+
|
|
12
|
+
|
|
6
13
|
## [17.0.13](https://github.com/appium/appium-ios/compare/appium-webdriveragent@17.0.12...appium-webdriveragent@17.0.13) (2026-11-21)
|
|
7
14
|
|
|
8
15
|
**Note:** Version bump only for package appium-webdriveragent
|
|
@@ -15,11 +15,11 @@
|
|
|
15
15
|
<key>CFBundlePackageType</key>
|
|
16
16
|
<string>FMWK</string>
|
|
17
17
|
<key>CFBundleShortVersionString</key>
|
|
18
|
-
<string>17.0.
|
|
18
|
+
<string>17.0.14</string>
|
|
19
19
|
<key>CFBundleSignature</key>
|
|
20
20
|
<string>????</string>
|
|
21
21
|
<key>CFBundleVersion</key>
|
|
22
|
-
<string>17.0.
|
|
22
|
+
<string>17.0.14</string>
|
|
23
23
|
<key>NSPrincipalClass</key>
|
|
24
24
|
<string/>
|
|
25
25
|
</dict>
|
|
@@ -90,7 +90,10 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
90
90
|
there are query parsing errors
|
|
91
91
|
@return list of parsed primitives packed to FBClassChainElement class or nil in case
|
|
92
92
|
there was parsing error (the parameter will be initialized with detailed error description in such case)
|
|
93
|
-
@throws FBUnknownAttributeException if any of predicates in the chain contains unknown attribute
|
|
93
|
+
@throws FBUnknownAttributeException if any of predicates in the chain contains unknown attribute
|
|
94
|
+
@throws NSInvalidArgumentException if the text of any predicate in the chain is not a valid predicate.
|
|
95
|
+
The text is never used as a format, so it must not contain format specifiers.
|
|
96
|
+
An empty query is reported as an error, not as an exception.
|
|
94
97
|
*/
|
|
95
98
|
+ (nullable FBClassChain*)parseQuery:(NSString*)classChainQuery error:(NSError **)error;
|
|
96
99
|
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
#import <errno.h>
|
|
10
|
+
|
|
9
11
|
#import "FBClassChainQueryParser.h"
|
|
10
12
|
#import "FBErrorBuilder.h"
|
|
11
13
|
#import "FBElementTypeTransformer.h"
|
|
@@ -14,377 +16,248 @@
|
|
|
14
16
|
|
|
15
17
|
NS_ASSUME_NONNULL_BEGIN
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
@end
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
@interface FBClassNameToken : FBBaseClassChainToken
|
|
26
|
-
|
|
27
|
-
@end
|
|
28
|
-
|
|
29
|
-
@interface FBStarToken : FBBaseClassChainToken
|
|
19
|
+
typedef NS_ENUM(NSUInteger, FBRawGroupKind) {
|
|
20
|
+
FBRawGroupKindPosition,
|
|
21
|
+
FBRawGroupKindSelfPredicate,
|
|
22
|
+
FBRawGroupKindDescendantPredicate,
|
|
23
|
+
};
|
|
30
24
|
|
|
31
|
-
|
|
25
|
+
/*! A bracket group of a step as written in the query: `[1]`, `` [`...`] `` or `[$...$]` */
|
|
26
|
+
@interface FBRawGroup : NSObject
|
|
32
27
|
|
|
33
|
-
@
|
|
28
|
+
@property (nonatomic) FBRawGroupKind kind;
|
|
29
|
+
/*! The position digits, or the predicate text with doubled markers collapsed */
|
|
30
|
+
@property (nonatomic, copy) NSString *text;
|
|
34
31
|
|
|
35
32
|
@end
|
|
36
33
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
@end
|
|
34
|
+
/*! A step that passed the syntax check, but is not resolved yet */
|
|
35
|
+
@interface FBRawStep : NSObject
|
|
40
36
|
|
|
41
|
-
@
|
|
37
|
+
@property (nonatomic) BOOL isDescendant;
|
|
38
|
+
/*! YES if the step is preceded by more than one descendant marker */
|
|
39
|
+
@property (nonatomic) BOOL hasDuplicatedMarker;
|
|
40
|
+
/*! nil stands for the star */
|
|
41
|
+
@property (nonatomic, nullable, copy) NSString *className;
|
|
42
|
+
@property (nonatomic, readonly) NSMutableArray<FBRawGroup *> *groups;
|
|
42
43
|
|
|
43
44
|
@end
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
/*! Single pass syntax check of a class chain query, no tokens are created */
|
|
47
|
+
@interface FBClassChainScanner : NSObject
|
|
46
48
|
|
|
47
|
-
|
|
49
|
+
/*! Index of the character the scan has failed on */
|
|
50
|
+
@property (nonatomic, readonly) NSUInteger failureIndex;
|
|
48
51
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
@end
|
|
52
|
-
|
|
53
|
-
@interface FBAbstractPredicateToken : FBBaseClassChainToken
|
|
54
|
-
|
|
55
|
-
@property (nonatomic) BOOL isParsingCompleted;
|
|
56
|
-
|
|
57
|
-
+ (NSString *)enclosingMarker;
|
|
58
|
-
|
|
59
|
-
@end
|
|
60
|
-
|
|
61
|
-
@interface FBSelfPredicateToken : FBAbstractPredicateToken
|
|
62
|
-
|
|
63
|
-
@end
|
|
64
|
-
|
|
65
|
-
@interface FBDescendantPredicateToken : FBAbstractPredicateToken
|
|
52
|
+
- (instancetype)initWithQuery:(NSString *)query;
|
|
53
|
+
- (nullable NSArray<FBRawStep *> *)scan;
|
|
66
54
|
|
|
67
55
|
@end
|
|
68
56
|
|
|
69
57
|
NS_ASSUME_NONNULL_END
|
|
70
58
|
|
|
71
59
|
|
|
72
|
-
@implementation
|
|
60
|
+
@implementation FBRawGroup
|
|
61
|
+
@end
|
|
73
62
|
|
|
74
|
-
|
|
75
|
-
{
|
|
76
|
-
self = [super init];
|
|
77
|
-
if (self) {
|
|
78
|
-
_asString = @"";
|
|
79
|
-
_previousItemsCountToOverride = 0;
|
|
80
|
-
}
|
|
81
|
-
return self;
|
|
82
|
-
}
|
|
63
|
+
@implementation FBRawStep
|
|
83
64
|
|
|
84
|
-
- (instancetype)
|
|
65
|
+
- (instancetype)init
|
|
85
66
|
{
|
|
86
67
|
self = [super init];
|
|
87
68
|
if (self) {
|
|
88
|
-
|
|
69
|
+
_groups = [NSMutableArray array];
|
|
89
70
|
}
|
|
90
71
|
return self;
|
|
91
72
|
}
|
|
92
73
|
|
|
93
|
-
|
|
94
|
-
{
|
|
95
|
-
// This method is expected to be overriden by subclasses
|
|
96
|
-
return [NSCharacterSet characterSetWithCharactersInString:@""];
|
|
97
|
-
}
|
|
74
|
+
@end
|
|
98
75
|
|
|
99
|
-
+ (NSUInteger)maxLength
|
|
100
|
-
{
|
|
101
|
-
// This method is expected to be overriden by subclasses
|
|
102
|
-
return ULONG_MAX;
|
|
103
|
-
}
|
|
104
76
|
|
|
105
|
-
|
|
106
|
-
{
|
|
107
|
-
// This method is expected to be overriden by subclasses
|
|
108
|
-
return @[];
|
|
109
|
-
}
|
|
77
|
+
static NSString *const DESCENDANT_MARKER = @"**/";
|
|
110
78
|
|
|
111
|
-
|
|
79
|
+
static BOOL FBIsPositionCharacter(unichar character)
|
|
112
80
|
{
|
|
113
|
-
return
|
|
81
|
+
return '-' == character || (character >= '0' && character <= '9');
|
|
114
82
|
}
|
|
115
83
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
[value appendFormat:@"%C", character];
|
|
120
|
-
self.asString = value.copy;
|
|
84
|
+
@implementation FBClassChainScanner {
|
|
85
|
+
NSString *_query;
|
|
86
|
+
NSUInteger _pos;
|
|
121
87
|
}
|
|
122
88
|
|
|
123
|
-
- (
|
|
89
|
+
- (instancetype)initWithQuery:(NSString *)query
|
|
124
90
|
{
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
91
|
+
self = [super init];
|
|
92
|
+
if (self) {
|
|
93
|
+
_query = query;
|
|
94
|
+
_pos = 0;
|
|
95
|
+
_failureIndex = 0;
|
|
129
96
|
}
|
|
130
|
-
return
|
|
97
|
+
return self;
|
|
131
98
|
}
|
|
132
99
|
|
|
133
|
-
- (
|
|
100
|
+
- (BOOL)hasMore
|
|
134
101
|
{
|
|
135
|
-
|
|
136
|
-
[self appendChar:character];
|
|
137
|
-
return self;
|
|
138
|
-
}
|
|
139
|
-
return [self followingTokenBasedOn:character];
|
|
102
|
+
return _pos < _query.length;
|
|
140
103
|
}
|
|
141
104
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
@implementation FBClassNameToken
|
|
146
|
-
|
|
147
|
-
+ (NSCharacterSet *)allowedCharacters
|
|
105
|
+
- (unichar)current
|
|
148
106
|
{
|
|
149
|
-
return [
|
|
107
|
+
return [_query characterAtIndex:_pos];
|
|
150
108
|
}
|
|
151
109
|
|
|
152
|
-
- (
|
|
110
|
+
- (BOOL)isCurrent:(unichar)character
|
|
153
111
|
{
|
|
154
|
-
return
|
|
112
|
+
return [self hasMore] && [self current] == character;
|
|
155
113
|
}
|
|
156
114
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
static NSString *const STAR_TOKEN = @"*";
|
|
160
|
-
@implementation FBStarToken
|
|
161
|
-
|
|
162
|
-
+ (NSCharacterSet *)allowedCharacters
|
|
115
|
+
- (BOOL)isNext:(unichar)character
|
|
163
116
|
{
|
|
164
|
-
return [
|
|
117
|
+
return _pos + 1 < _query.length && [_query characterAtIndex:_pos + 1] == character;
|
|
165
118
|
}
|
|
166
119
|
|
|
167
|
-
- (
|
|
120
|
+
- (BOOL)fail
|
|
168
121
|
{
|
|
169
|
-
|
|
122
|
+
// Failures past the end of the query are reported at its last character
|
|
123
|
+
_failureIndex = MIN(_pos, _query.length - 1);
|
|
124
|
+
return NO;
|
|
170
125
|
}
|
|
171
126
|
|
|
172
|
-
- (
|
|
127
|
+
- (BOOL)consumeDescendantMarker
|
|
173
128
|
{
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
return nextToken;
|
|
179
|
-
}
|
|
180
|
-
[self appendChar:character];
|
|
181
|
-
return self;
|
|
129
|
+
NSUInteger markerLength = DESCENDANT_MARKER.length;
|
|
130
|
+
if (_pos + markerLength > _query.length
|
|
131
|
+
|| NSOrderedSame != [_query compare:DESCENDANT_MARKER options:NSLiteralSearch range:NSMakeRange(_pos, markerLength)]) {
|
|
132
|
+
return NO;
|
|
182
133
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
@end
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
static NSString *const DESCENDANT_MARKER = @"**/";
|
|
190
|
-
@implementation FBDescendantMarkerToken
|
|
191
|
-
|
|
192
|
-
+ (NSCharacterSet *)allowedCharacters
|
|
193
|
-
{
|
|
194
|
-
return [NSCharacterSet characterSetWithCharactersInString:@"*/"];
|
|
134
|
+
_pos += markerLength;
|
|
135
|
+
return YES;
|
|
195
136
|
}
|
|
196
137
|
|
|
197
|
-
- (
|
|
138
|
+
- (BOOL)scanTypeIntoStep:(FBRawStep *)step
|
|
198
139
|
{
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
- (nullable FBBaseClassChainToken*)nextTokenWithCharacter:(unichar)character
|
|
208
|
-
{
|
|
209
|
-
if ([self.class.allowedCharacters characterIsMember:character] && self.asString.length <= self.class.maxLength) {
|
|
210
|
-
if (self.asString.length > 0 && ![DESCENDANT_MARKER hasPrefix:self.asString]) {
|
|
211
|
-
return nil;
|
|
140
|
+
NSCharacterSet *letters = NSCharacterSet.letterCharacterSet;
|
|
141
|
+
if ([self isCurrent:'*']) {
|
|
142
|
+
if ([self isNext:'*']) {
|
|
143
|
+
// Only the complete descendant marker may start with two stars
|
|
144
|
+
++_pos;
|
|
145
|
+
return [self fail];
|
|
212
146
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
147
|
+
++_pos;
|
|
148
|
+
step.className = nil;
|
|
149
|
+
} else if ([self hasMore] && [letters characterIsMember:[self current]]) {
|
|
150
|
+
NSUInteger start = _pos;
|
|
151
|
+
while ([self hasMore] && [letters characterIsMember:[self current]]) {
|
|
152
|
+
++_pos;
|
|
216
153
|
}
|
|
154
|
+
step.className = [_query substringWithRange:NSMakeRange(start, _pos - start)];
|
|
155
|
+
} else {
|
|
156
|
+
return [self fail];
|
|
217
157
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
@end
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
@implementation FBSplitterToken
|
|
225
|
-
|
|
226
|
-
+ (NSCharacterSet *)allowedCharacters
|
|
227
|
-
{
|
|
228
|
-
return [NSCharacterSet characterSetWithCharactersInString:@"/"];
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
- (NSArray<Class> *)followingTokens
|
|
232
|
-
{
|
|
233
|
-
return @[FBStarToken.class, FBClassNameToken.class];
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
+ (NSUInteger)maxLength
|
|
237
|
-
{
|
|
238
|
-
return 1;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
@end
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
@implementation FBOpeningBracketToken
|
|
245
|
-
|
|
246
|
-
+ (NSCharacterSet *)allowedCharacters
|
|
247
|
-
{
|
|
248
|
-
return [NSCharacterSet characterSetWithCharactersInString:@"["];
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
- (NSArray<Class> *)followingTokens
|
|
252
|
-
{
|
|
253
|
-
return @[FBNumberToken.class, FBSelfPredicateToken.class, FBDescendantPredicateToken.class];
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
+ (NSUInteger)maxLength
|
|
257
|
-
{
|
|
258
|
-
return 1;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
@end
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
@implementation FBNumberToken
|
|
265
|
-
|
|
266
|
-
+ (NSCharacterSet *)allowedCharacters
|
|
267
|
-
{
|
|
268
|
-
NSMutableCharacterSet *result = [NSMutableCharacterSet new];
|
|
269
|
-
[result formUnionWithCharacterSet:[NSCharacterSet decimalDigitCharacterSet]];
|
|
270
|
-
[result addCharactersInString:@"-"];
|
|
271
|
-
return result.copy;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
- (NSArray<Class> *)followingTokens
|
|
275
|
-
{
|
|
276
|
-
return @[FBClosingBracketToken.class];
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
@end
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
@implementation FBClosingBracketToken
|
|
283
|
-
|
|
284
|
-
+ (NSCharacterSet *)allowedCharacters
|
|
285
|
-
{
|
|
286
|
-
return [NSCharacterSet characterSetWithCharactersInString:@"]"];
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
- (NSArray<Class> *)followingTokens
|
|
290
|
-
{
|
|
291
|
-
return @[FBSplitterToken.class, FBOpeningBracketToken.class];
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
+ (NSUInteger)maxLength
|
|
295
|
-
{
|
|
296
|
-
return 1;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
@end
|
|
300
|
-
|
|
301
|
-
static NSString *const FBAbstractMethodInvocationException = @"FBAbstractMethodInvocationException";
|
|
302
|
-
|
|
303
|
-
@implementation FBAbstractPredicateToken
|
|
304
|
-
|
|
305
|
-
- (id)init
|
|
306
|
-
{
|
|
307
|
-
self = [super init];
|
|
308
|
-
if (self) {
|
|
309
|
-
_isParsingCompleted = NO;
|
|
158
|
+
if ([self hasMore] && ![self isCurrent:'/'] && ![self isCurrent:'[']) {
|
|
159
|
+
return [self fail];
|
|
310
160
|
}
|
|
311
|
-
return
|
|
161
|
+
return YES;
|
|
312
162
|
}
|
|
313
163
|
|
|
314
|
-
|
|
164
|
+
- (BOOL)scanPredicateWithMarker:(unichar)marker intoStep:(FBRawStep *)step
|
|
315
165
|
{
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
166
|
+
_pos += 2; // '[' and the marker
|
|
167
|
+
NSMutableString *text = [NSMutableString string];
|
|
168
|
+
NSUInteger chunkStart = _pos;
|
|
169
|
+
while (YES) {
|
|
170
|
+
if (![self hasMore]) {
|
|
171
|
+
return [self fail];
|
|
172
|
+
}
|
|
173
|
+
if ([self current] != marker) {
|
|
174
|
+
++_pos;
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
// A doubled marker stands for the marker itself
|
|
178
|
+
BOOL isEscaped = [self isNext:marker];
|
|
179
|
+
[text appendString:[_query substringWithRange:NSMakeRange(chunkStart, _pos - chunkStart + (isEscaped ? 1 : 0))]];
|
|
180
|
+
if (!isEscaped) {
|
|
181
|
+
++_pos;
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
_pos += 2;
|
|
185
|
+
chunkStart = _pos;
|
|
186
|
+
}
|
|
187
|
+
if (0 == text.length || ![self isCurrent:']']) {
|
|
188
|
+
return [self fail];
|
|
189
|
+
}
|
|
190
|
+
++_pos;
|
|
191
|
+
FBRawGroup *group = [FBRawGroup new];
|
|
192
|
+
group.kind = '`' == marker ? FBRawGroupKindSelfPredicate : FBRawGroupKindDescendantPredicate;
|
|
193
|
+
group.text = text.copy;
|
|
194
|
+
[step.groups addObject:group];
|
|
195
|
+
return YES;
|
|
328
196
|
}
|
|
329
197
|
|
|
330
|
-
|
|
198
|
+
- (BOOL)scanPositionIntoStep:(FBRawStep *)step
|
|
331
199
|
{
|
|
332
|
-
|
|
200
|
+
++_pos; // '['
|
|
201
|
+
NSUInteger start = _pos;
|
|
202
|
+
while ([self hasMore] && FBIsPositionCharacter([self current])) {
|
|
203
|
+
++_pos;
|
|
204
|
+
}
|
|
205
|
+
NSUInteger end = _pos;
|
|
206
|
+
if (![self isCurrent:']']) {
|
|
207
|
+
return [self fail];
|
|
208
|
+
}
|
|
209
|
+
++_pos;
|
|
210
|
+
FBRawGroup *group = [FBRawGroup new];
|
|
211
|
+
group.kind = FBRawGroupKindPosition;
|
|
212
|
+
group.text = [_query substringWithRange:NSMakeRange(start, end - start)];
|
|
213
|
+
[step.groups addObject:group];
|
|
214
|
+
return YES;
|
|
333
215
|
}
|
|
334
216
|
|
|
335
|
-
- (
|
|
217
|
+
- (BOOL)scanGroupIntoStep:(FBRawStep *)step
|
|
336
218
|
{
|
|
337
|
-
if (self
|
|
338
|
-
|
|
219
|
+
if ([self isNext:'`']) {
|
|
220
|
+
return [self scanPredicateWithMarker:'`' intoStep:step];
|
|
221
|
+
}
|
|
222
|
+
if ([self isNext:'$']) {
|
|
223
|
+
return [self scanPredicateWithMarker:'$' intoStep:step];
|
|
339
224
|
}
|
|
225
|
+
if (_pos + 1 < _query.length && FBIsPositionCharacter([_query characterAtIndex:_pos + 1])) {
|
|
226
|
+
return [self scanPositionIntoStep:step];
|
|
227
|
+
}
|
|
228
|
+
++_pos;
|
|
229
|
+
return [self fail];
|
|
340
230
|
}
|
|
341
231
|
|
|
342
|
-
- (nullable
|
|
232
|
+
- (nullable NSArray<FBRawStep *> *)scan
|
|
343
233
|
{
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
234
|
+
NSMutableArray<FBRawStep *> *steps = [NSMutableArray array];
|
|
235
|
+
BOOL isDescendant = [self consumeDescendantMarker];
|
|
236
|
+
while (YES) {
|
|
237
|
+
FBRawStep *step = [FBRawStep new];
|
|
238
|
+
step.isDescendant = isDescendant;
|
|
239
|
+
while ([self consumeDescendantMarker]) {
|
|
240
|
+
step.hasDuplicatedMarker = YES;
|
|
241
|
+
}
|
|
242
|
+
if (![self scanTypeIntoStep:step]) {
|
|
243
|
+
return nil;
|
|
244
|
+
}
|
|
245
|
+
while ([self isCurrent:'[']) {
|
|
246
|
+
if (![self scanGroupIntoStep:step]) {
|
|
247
|
+
return nil;
|
|
350
248
|
}
|
|
351
|
-
} else if ([self.class.enclosingMarker isEqualToString:currentChar]) {
|
|
352
|
-
[self appendChar:character];
|
|
353
|
-
self.isParsingCompleted = YES;
|
|
354
|
-
return self;
|
|
355
249
|
}
|
|
356
|
-
[
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
if (self.isParsingCompleted) {
|
|
360
|
-
if ([currentChar isEqualToString:self.class.enclosingMarker]) {
|
|
361
|
-
// Escaped enclosing character has been detected. Do not finish parsing
|
|
362
|
-
self.isParsingCompleted = NO;
|
|
363
|
-
return self;
|
|
364
|
-
} else {
|
|
365
|
-
// Do not include enclosing character
|
|
366
|
-
[self stripLastChar];
|
|
250
|
+
[steps addObject:step];
|
|
251
|
+
if (![self hasMore]) {
|
|
252
|
+
return steps.copy;
|
|
367
253
|
}
|
|
254
|
+
if (![self isCurrent:'/']) {
|
|
255
|
+
[self fail];
|
|
256
|
+
return nil;
|
|
257
|
+
}
|
|
258
|
+
++_pos;
|
|
259
|
+
isDescendant = [self consumeDescendantMarker];
|
|
368
260
|
}
|
|
369
|
-
return [self followingTokenBasedOn:character];
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
@end
|
|
373
|
-
|
|
374
|
-
@implementation FBSelfPredicateToken
|
|
375
|
-
|
|
376
|
-
+ (NSString *)enclosingMarker
|
|
377
|
-
{
|
|
378
|
-
return @"`";
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
@end
|
|
382
|
-
|
|
383
|
-
@implementation FBDescendantPredicateToken
|
|
384
|
-
|
|
385
|
-
+ (NSString *)enclosingMarker
|
|
386
|
-
{
|
|
387
|
-
return @"$";
|
|
388
261
|
}
|
|
389
262
|
|
|
390
263
|
@end
|
|
@@ -423,76 +296,31 @@ static NSString *const FBAbstractMethodInvocationException = @"FBAbstractMethodI
|
|
|
423
296
|
|
|
424
297
|
@implementation FBClassChainQueryParser
|
|
425
298
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
+ (void)initialize {
|
|
429
|
-
if (nil == numberFormatter) {
|
|
430
|
-
numberFormatter = [[NSNumberFormatter alloc] init];
|
|
431
|
-
numberFormatter.numberStyle = NSNumberFormatterDecimalStyle;
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
+ (NSError *)tokenizationErrorWithIndex:(NSUInteger)index originalQuery:(NSString *)originalQuery
|
|
436
|
-
{
|
|
437
|
-
NSString *description = [NSString stringWithFormat:@"Cannot parse class chain query '%@'. Unexpected character detected at position %@:\n%@ <----", originalQuery, @(index + 1), [originalQuery substringToIndex:index + 1]];
|
|
438
|
-
return [[FBErrorBuilder.builder withDescription:description] build];
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
+ (nullable NSArray<FBBaseClassChainToken *> *)tokenizedQueryWithQuery:(NSString*)classChainQuery error:(NSError **)error
|
|
299
|
+
// A non-zero int written as an optional minus followed by ASCII digits, nil if it is something else
|
|
300
|
+
+ (nullable NSNumber *)positionWithString:(NSString *)string
|
|
442
301
|
{
|
|
443
|
-
NSUInteger
|
|
444
|
-
|
|
445
|
-
unichar firstCharacter = [classChainQuery characterAtIndex:0];
|
|
446
|
-
if ([classChainQuery hasPrefix:DESCENDANT_MARKER]) {
|
|
447
|
-
token = [[FBDescendantMarkerToken alloc] initWithStringValue:DESCENDANT_MARKER];
|
|
448
|
-
} else if ([FBClassNameToken canConsumeCharacter:firstCharacter]) {
|
|
449
|
-
token = [[FBClassNameToken alloc] initWithStringValue:[NSString stringWithFormat:@"%C", firstCharacter]];
|
|
450
|
-
} else if ([FBStarToken canConsumeCharacter:firstCharacter]) {
|
|
451
|
-
token = [[FBStarToken alloc] initWithStringValue:[NSString stringWithFormat:@"%C", firstCharacter]];
|
|
452
|
-
} else {
|
|
453
|
-
if (error) {
|
|
454
|
-
*error = [self.class tokenizationErrorWithIndex:0 originalQuery:classChainQuery];
|
|
455
|
-
}
|
|
302
|
+
NSUInteger digitsStart = [string hasPrefix:@"-"] ? 1 : 0;
|
|
303
|
+
if (string.length == digitsStart) {
|
|
456
304
|
return nil;
|
|
457
305
|
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
nextToken = [token nextTokenWithCharacter:[classChainQuery characterAtIndex:charIdx]];
|
|
462
|
-
if (nil == nextToken) {
|
|
463
|
-
if (error) {
|
|
464
|
-
*error = [self.class tokenizationErrorWithIndex:charIdx originalQuery:classChainQuery];
|
|
465
|
-
}
|
|
306
|
+
for (NSUInteger i = digitsStart; i < string.length; ++i) {
|
|
307
|
+
unichar character = [string characterAtIndex:i];
|
|
308
|
+
if (character < '0' || character > '9') {
|
|
466
309
|
return nil;
|
|
467
310
|
}
|
|
468
|
-
if (nextToken != token) {
|
|
469
|
-
[result addObject:token];
|
|
470
|
-
if (nextToken.previousItemsCountToOverride > 0 && result.count > 0) {
|
|
471
|
-
NSUInteger itemsCountToOverride = nextToken.previousItemsCountToOverride <= result.count ? nextToken.previousItemsCountToOverride : result.count;
|
|
472
|
-
[result removeObjectsInRange:NSMakeRange(result.count - itemsCountToOverride, itemsCountToOverride)];
|
|
473
|
-
}
|
|
474
|
-
token = nextToken;
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
if (nextToken) {
|
|
478
|
-
if (nextToken.previousItemsCountToOverride > 0 && result.count > 0) {
|
|
479
|
-
NSUInteger itemsCountToOverride = nextToken.previousItemsCountToOverride <= result.count ? nextToken.previousItemsCountToOverride : result.count;
|
|
480
|
-
[result removeObjectsInRange:NSMakeRange(result.count - itemsCountToOverride, itemsCountToOverride)];
|
|
481
|
-
}
|
|
482
|
-
[result addObject:nextToken];
|
|
483
311
|
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
if (
|
|
487
|
-
[lastToken isKindOfClass:FBClassNameToken.class] ||
|
|
488
|
-
[lastToken isKindOfClass:FBStarToken.class])) {
|
|
489
|
-
if (error) {
|
|
490
|
-
*error = [self.class tokenizationErrorWithIndex:queryStringLength - 1 originalQuery:classChainQuery];
|
|
491
|
-
}
|
|
312
|
+
errno = 0;
|
|
313
|
+
long long value = strtoll(string.UTF8String, NULL, 10);
|
|
314
|
+
if (ERANGE == errno || 0 == value || value < -INT_MAX || value > INT_MAX) {
|
|
492
315
|
return nil;
|
|
493
316
|
}
|
|
494
|
-
|
|
495
|
-
|
|
317
|
+
return @(value);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
+ (NSError *)tokenizationErrorWithIndex:(NSUInteger)index originalQuery:(NSString *)originalQuery
|
|
321
|
+
{
|
|
322
|
+
NSString *description = [NSString stringWithFormat:@"Cannot parse class chain query '%@'. Unexpected character detected at position %@:\n%@ <----", originalQuery, @(index + 1), [originalQuery substringToIndex:index + 1]];
|
|
323
|
+
return [[FBErrorBuilder.builder withDescription:description] build];
|
|
496
324
|
}
|
|
497
325
|
|
|
498
326
|
+ (NSError *)compilationErrorWithQuery:(NSString *)originalQuery description:(NSString *)description
|
|
@@ -501,144 +329,102 @@ static NSNumberFormatter *numberFormatter = nil;
|
|
|
501
329
|
return [[FBErrorBuilder.builder withDescription:fullDescription] build];
|
|
502
330
|
}
|
|
503
331
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
332
|
+
// Steps are resolved in the order they are written, so the first problem wins: bad names and
|
|
333
|
+
// positions are errors, an invalid predicate raises an exception.
|
|
334
|
+
+ (nullable FBClassChain *)compiledQueryWithRawSteps:(NSArray<FBRawStep *> *)rawSteps
|
|
335
|
+
originalQuery:(NSString *)originalQuery
|
|
336
|
+
error:(NSError **)error
|
|
507
337
|
{
|
|
508
|
-
NSMutableArray *result = [NSMutableArray
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
NSMutableArray<FBAbstractPredicateItem *> *predicates = [NSMutableArray array];
|
|
515
|
-
for (FBBaseClassChainToken *token in tokenizedQuery) {
|
|
516
|
-
if ([token isKindOfClass:FBClassNameToken.class]) {
|
|
517
|
-
if (isTypeSet) {
|
|
518
|
-
if (error) {
|
|
519
|
-
NSString *description = [NSString stringWithFormat:@"Unexpected token '%@'. The type name can be set only once.", token.asString];
|
|
520
|
-
*error = [self.class compilationErrorWithQuery:originalQuery description:description];
|
|
521
|
-
}
|
|
522
|
-
return nil;
|
|
338
|
+
NSMutableArray<FBClassChainItem *> *result = [NSMutableArray arrayWithCapacity:rawSteps.count];
|
|
339
|
+
for (FBRawStep *rawStep in rawSteps) {
|
|
340
|
+
if (rawStep.hasDuplicatedMarker) {
|
|
341
|
+
if (error) {
|
|
342
|
+
NSString *description = [NSString stringWithFormat:@"Unexpected token '%@'. Descendant markers cannot be duplicated.", DESCENDANT_MARKER];
|
|
343
|
+
*error = [self.class compilationErrorWithQuery:originalQuery description:description];
|
|
523
344
|
}
|
|
345
|
+
return nil;
|
|
346
|
+
}
|
|
347
|
+
XCUIElementType type = XCUIElementTypeAny;
|
|
348
|
+
if (nil != rawStep.className) {
|
|
524
349
|
@try {
|
|
525
|
-
|
|
526
|
-
isTypeSet = YES;
|
|
350
|
+
type = [FBElementTypeTransformer elementTypeWithTypeName:rawStep.className];
|
|
527
351
|
} @catch (NSException *e) {
|
|
528
352
|
if ([e.name isEqualToString:FBInvalidArgumentException]) {
|
|
529
353
|
if (error) {
|
|
530
|
-
NSString *description = [NSString stringWithFormat:@"'%@' class name is unknown to WDA",
|
|
354
|
+
NSString *description = [NSString stringWithFormat:@"'%@' class name is unknown to WDA", rawStep.className];
|
|
531
355
|
*error = [self.class compilationErrorWithQuery:originalQuery description:description];
|
|
532
356
|
}
|
|
533
357
|
return nil;
|
|
534
358
|
}
|
|
535
359
|
@throw e;
|
|
536
360
|
}
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
if (isDescendantSet) {
|
|
549
|
-
NSString *description = [NSString stringWithFormat:@"Unexpected token '%@'. Descendant markers cannot be duplicated.", token.asString];
|
|
550
|
-
if (error) {
|
|
551
|
-
*error = [self.class compilationErrorWithQuery:originalQuery description:description];
|
|
552
|
-
}
|
|
553
|
-
return nil;
|
|
554
|
-
}
|
|
555
|
-
isTypeSet = NO;
|
|
556
|
-
isPositionSet = NO;
|
|
557
|
-
[predicates removeAllObjects];
|
|
558
|
-
isDescendantSet = YES;
|
|
559
|
-
} else if ([token isKindOfClass:FBAbstractPredicateToken.class]) {
|
|
560
|
-
if (isPositionSet) {
|
|
561
|
-
NSString *description = [NSString stringWithFormat:@"Predicate value '%@' must be set before position value.", token.asString];
|
|
562
|
-
if (error) {
|
|
563
|
-
*error = [self.class compilationErrorWithQuery:originalQuery description:description];
|
|
564
|
-
}
|
|
565
|
-
return nil;
|
|
566
|
-
}
|
|
567
|
-
if (!((FBAbstractPredicateToken *)token).isParsingCompleted) {
|
|
568
|
-
NSString *description = [NSString stringWithFormat:@"Cannot find the end of '%@' predicate value.", token.asString];
|
|
569
|
-
if (error) {
|
|
570
|
-
*error = [self.class compilationErrorWithQuery:originalQuery description:description];
|
|
361
|
+
}
|
|
362
|
+
NSNumber *position = nil;
|
|
363
|
+
NSMutableArray<FBAbstractPredicateItem *> *predicates = [NSMutableArray array];
|
|
364
|
+
for (FBRawGroup *group in rawStep.groups) {
|
|
365
|
+
if (FBRawGroupKindPosition == group.kind) {
|
|
366
|
+
if (nil != position) {
|
|
367
|
+
if (error) {
|
|
368
|
+
NSString *description = [NSString stringWithFormat:@"Position value '%@' is expected to be set only once.", group.text];
|
|
369
|
+
*error = [self.class compilationErrorWithQuery:originalQuery description:description];
|
|
370
|
+
}
|
|
371
|
+
return nil;
|
|
571
372
|
}
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
}
|
|
580
|
-
} else if ([token isKindOfClass:FBNumberToken.class]) {
|
|
581
|
-
if (isPositionSet) {
|
|
582
|
-
NSString *description = [NSString stringWithFormat:@"Position value '%@' is expected to be set only once.", token.asString];
|
|
583
|
-
if (error) {
|
|
584
|
-
*error = [self.class compilationErrorWithQuery:originalQuery description:description];
|
|
373
|
+
NSNumber *value = [self.class positionWithString:group.text];
|
|
374
|
+
if (nil == value) {
|
|
375
|
+
if (error) {
|
|
376
|
+
NSString *description = [NSString stringWithFormat:@"Position value '%@' is expected to be a valid integer number not equal to zero.", group.text];
|
|
377
|
+
*error = [self.class compilationErrorWithQuery:originalQuery description:description];
|
|
378
|
+
}
|
|
379
|
+
return nil;
|
|
585
380
|
}
|
|
586
|
-
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
381
|
+
position = value;
|
|
382
|
+
} else {
|
|
383
|
+
if (nil != position) {
|
|
384
|
+
if (error) {
|
|
385
|
+
NSString *description = [NSString stringWithFormat:@"Predicate value '%@' must be set before position value.", group.text];
|
|
386
|
+
*error = [self.class compilationErrorWithQuery:originalQuery description:description];
|
|
387
|
+
}
|
|
388
|
+
return nil;
|
|
593
389
|
}
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
chainElementPosition = nil;
|
|
601
|
-
}
|
|
602
|
-
if (isDescendantSet) {
|
|
603
|
-
if (isTypeSet) {
|
|
604
|
-
[result addObject:[[FBClassChainItem alloc] initWithType:chainElementType position:chainElementPosition predicates:predicates.copy isDescendant:YES]];
|
|
605
|
-
isDescendantSet = NO;
|
|
390
|
+
NSPredicate *rawPredicate = nil;
|
|
391
|
+
@try {
|
|
392
|
+
rawPredicate = [NSPredicate predicateWithFormat:group.text argumentArray:@[]];
|
|
393
|
+
} @catch (NSException *e) {
|
|
394
|
+
// Foundation raises different exception names depending on the failure and OS version
|
|
395
|
+
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:e.reason userInfo:e.userInfo];
|
|
606
396
|
}
|
|
607
|
-
|
|
608
|
-
[
|
|
397
|
+
NSPredicate *value = [NSPredicate fb_snapshotBlockPredicateWithPredicate:rawPredicate];
|
|
398
|
+
[predicates addObject:FBRawGroupKindSelfPredicate == group.kind
|
|
399
|
+
? [[FBSelfPredicateItem alloc] initWithValue:value]
|
|
400
|
+
: [[FBDescendantPredicateItem alloc] initWithValue:value]];
|
|
609
401
|
}
|
|
610
|
-
isTypeSet = NO;
|
|
611
|
-
isPositionSet = NO;
|
|
612
|
-
[predicates removeAllObjects];
|
|
613
402
|
}
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
if (isDescendantSet) {
|
|
619
|
-
if (isTypeSet) {
|
|
620
|
-
[result addObject:[[FBClassChainItem alloc] initWithType:chainElementType position:chainElementPosition predicates:predicates.copy isDescendant:YES]];
|
|
621
|
-
} else {
|
|
622
|
-
if (error) {
|
|
623
|
-
NSString *description = @"Descendants lookup modifier '**/' should be followed with the actual element type";
|
|
624
|
-
*error = [self.class compilationErrorWithQuery:originalQuery description:description];
|
|
625
|
-
}
|
|
626
|
-
return nil;
|
|
627
|
-
}
|
|
628
|
-
} else {
|
|
629
|
-
[result addObject:[[FBClassChainItem alloc] initWithType:chainElementType position:chainElementPosition predicates:predicates.copy isDescendant:NO]];
|
|
403
|
+
[result addObject:[[FBClassChainItem alloc] initWithType:type
|
|
404
|
+
position:position
|
|
405
|
+
predicates:predicates.copy
|
|
406
|
+
isDescendant:rawStep.isDescendant]];
|
|
630
407
|
}
|
|
631
408
|
return [[FBClassChain alloc] initWithElements:result.copy];
|
|
632
409
|
}
|
|
633
410
|
|
|
634
411
|
+ (FBClassChain *)parseQuery:(NSString*)classChainQuery error:(NSError **)error
|
|
635
412
|
{
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
413
|
+
if (0 == classChainQuery.length) {
|
|
414
|
+
if (error) {
|
|
415
|
+
*error = [self.class compilationErrorWithQuery:classChainQuery ?: @"" description:@"The query must not be empty."];
|
|
416
|
+
}
|
|
417
|
+
return nil;
|
|
418
|
+
}
|
|
419
|
+
FBClassChainScanner *scanner = [[FBClassChainScanner alloc] initWithQuery:classChainQuery];
|
|
420
|
+
NSArray<FBRawStep *> *rawSteps = [scanner scan];
|
|
421
|
+
if (nil == rawSteps) {
|
|
422
|
+
if (error) {
|
|
423
|
+
*error = [self.class tokenizationErrorWithIndex:scanner.failureIndex originalQuery:classChainQuery];
|
|
424
|
+
}
|
|
639
425
|
return nil;
|
|
640
426
|
}
|
|
641
|
-
return [self.class
|
|
427
|
+
return [self.class compiledQueryWithRawSteps:rawSteps originalQuery:classChainQuery error:error];
|
|
642
428
|
}
|
|
643
429
|
|
|
644
430
|
@end
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
#import "XCUIElementDouble.h"
|
|
12
12
|
#import "FBClassChainQueryParser.h"
|
|
13
|
+
#import "FBElementTypeTransformer.h"
|
|
13
14
|
|
|
14
15
|
@interface FBClassChainTests : XCTestCase
|
|
15
16
|
@end
|
|
@@ -310,4 +311,182 @@
|
|
|
310
311
|
}
|
|
311
312
|
}
|
|
312
313
|
|
|
314
|
+
// Type, optional position and the number of self/descendant predicates of every item, e.g. "**/Window[2]{1,0}"
|
|
315
|
+
static NSString *FBDescribeChain(FBClassChain *chain)
|
|
316
|
+
{
|
|
317
|
+
NSMutableArray<NSString *> *items = [NSMutableArray array];
|
|
318
|
+
for (FBClassChainItem *item in chain.elements) {
|
|
319
|
+
NSUInteger selfPredicates = 0;
|
|
320
|
+
NSUInteger descendantPredicates = 0;
|
|
321
|
+
for (FBAbstractPredicateItem *predicate in item.predicates) {
|
|
322
|
+
if ([predicate isKindOfClass:FBSelfPredicateItem.class]) {
|
|
323
|
+
++selfPredicates;
|
|
324
|
+
} else {
|
|
325
|
+
++descendantPredicates;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
NSString *type = [[FBElementTypeTransformer stringWithElementType:item.type] stringByReplacingOccurrencesOfString:@"XCUIElementType" withString:@""];
|
|
329
|
+
[items addObject:[NSString stringWithFormat:@"%@%@%@{%lu,%lu}", item.isDescendant ? @"**/" : @"", type,
|
|
330
|
+
nil == item.position ? @"" : [NSString stringWithFormat:@"[%@]", item.position],
|
|
331
|
+
(unsigned long)selfPredicates, (unsigned long)descendantPredicates]];
|
|
332
|
+
}
|
|
333
|
+
return [items componentsJoinedByString:@" "];
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
- (void)testParsedItems
|
|
337
|
+
{
|
|
338
|
+
NSDictionary<NSString *, NSString *> *expectations = @{
|
|
339
|
+
@"XCUIElementTypeWindow[12]/XCUIElementTypeAny[-1]": @"Window[12]{0,0} Any[-1]{0,0}",
|
|
340
|
+
@"*/*/*[2]/*/XCUIElementTypeButton": @"Any{0,0} Any{0,0} Any[2]{0,0} Any{0,0} Button{0,0}",
|
|
341
|
+
@"**/*/*/XCUIElementTypeButton[1]": @"**/Any{0,0} Any{0,0} Button[1]{0,0}",
|
|
342
|
+
@"XCUIElementTypeWindow/**/*": @"Window{0,0} **/Any{0,0}",
|
|
343
|
+
@"**/XCUIElementTypeCell[1]/**/XCUIElementTypeButton": @"**/Cell[1]{0,0} **/Button{0,0}",
|
|
344
|
+
@"XCUIElementTypeWindow[`name == \"a\"`][`label == \"1\"`][2]": @"Window[2]{2,0}",
|
|
345
|
+
@"XCUIElementTypeWindow[$name == 'a'$][$label == 'b'$]": @"Window{0,2}",
|
|
346
|
+
@"XCUIElementTypeWindow[`name == 'a'`][$label == 'b'$][`value == 'c'`]": @"Window{2,1}",
|
|
347
|
+
@"XCUIElementTypeWindow[`name == \"a``b\"`]": @"Window{1,0}",
|
|
348
|
+
@"XCUIElementTypeWindow[$name == \"a$$b\"$]": @"Window{0,1}",
|
|
349
|
+
@"XCUIElementTypeWindow[`value == \"[1]/**/\"`]": @"Window{1,0}",
|
|
350
|
+
@"XCUIElementTypeWindow[`value == \"a\"\n`]": @"Window{1,0}",
|
|
351
|
+
@"**/XCUIElementTypeWindow[`name == \"a\"`]/**/XCUIElementTypeButton[`name == \"b\"`][2]": @"**/Window{1,0} **/Button[2]{1,0}",
|
|
352
|
+
@"XCUIElementTypeWindow[2147483647]/XCUIElementTypeButton[-2147483647]": @"Window[2147483647]{0,0} Button[-2147483647]{0,0}",
|
|
353
|
+
};
|
|
354
|
+
for (NSString *query in expectations) {
|
|
355
|
+
NSError *error = nil;
|
|
356
|
+
FBClassChain *chain = [FBClassChainQueryParser parseQuery:query error:&error];
|
|
357
|
+
XCTAssertNotNil(chain, @"%@", query);
|
|
358
|
+
XCTAssertEqualObjects(FBDescribeChain(chain), expectations[query], @"%@", query);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
- (void)testMoreInvalidChains
|
|
363
|
+
{
|
|
364
|
+
NSArray<NSString *> *invalidQueries = @[
|
|
365
|
+
@"", @"**/", @"**//*", @"****/*", @"/**/*", @"XCUIElementTypeWindow/**/",
|
|
366
|
+
@"XCUIElementTypeWindow/***/*", @"**/[1]", @"**/[`name == '1'`]",
|
|
367
|
+
@"XCUIElementTypeWindow[1][2]", @"XCUIElementTypeWindow[-0]", @"XCUIElementTypeWindow[-]",
|
|
368
|
+
@"XCUIElementTypeWindow[--1]", @"XCUIElementTypeWindow[1-]", @"XCUIElementTypeWindow[1-1]",
|
|
369
|
+
@"XCUIElementTypeWindow1", @"XCUIElementType_Window", @"XCUIElementTypeWindow ",
|
|
370
|
+
@"XCUIElementTypeWindow/ XCUIElementTypeButton", @"XCUIElementTypeWindow[]", @"XCUIElementTypeWindow[",
|
|
371
|
+
@"XCUIElementTypeWindow[1", @"XCUIElementTypeWindow[`visible = 1`] [1]", @"XCUIElementTypeWindow[`visible = 1",
|
|
372
|
+
@"XCUIElementTypeWindow[`visible = 1`", @"XCUIElementTypeWindow[```]", @"XCUIElementTypeWindow[``]x`]",
|
|
373
|
+
@"XCUIElementTypeWindow[`name = \"bla\"`]x", @"XCUIElementTypeWindow[`name = \"bla\"`]*",
|
|
374
|
+
@"XCUIElementTypeWindow[1]*", @"XCUIElementTypeWindow[1]x", @"*[1]*", @"*x",
|
|
375
|
+
@"**/**/XCUIElementTypeWindow", @"XCUIElementTypeWindow/**/**/XCUIElementTypeButton",
|
|
376
|
+
@"XCUIElementTypeWindow/**/**/**/XCUIElementTypeButton", @"**/**/**/*",
|
|
377
|
+
];
|
|
378
|
+
for (NSString *query in invalidQueries) {
|
|
379
|
+
NSError *error = nil;
|
|
380
|
+
XCTAssertNil([FBClassChainQueryParser parseQuery:query error:&error], @"%@", query);
|
|
381
|
+
XCTAssertNotNil(error, @"%@", query);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// An invalid predicate raises, but only if nothing before it in the query is an error
|
|
386
|
+
- (void)testFirstProblemWins
|
|
387
|
+
{
|
|
388
|
+
NSArray<NSString *> *errors = @[
|
|
389
|
+
@"XCUIElementTypeWindow[`name == \"a\"`]/blabla",
|
|
390
|
+
@"blabla/XCUIElementTypeWindow[`name ==`]",
|
|
391
|
+
@"XCUIElementTypeWindow[`name == \"a\"`]/**/**/XCUIElementTypeButton[`name ==`]",
|
|
392
|
+
@"XCUIElementTypeWindow[`name == \"a\"`][1][`name ==`]",
|
|
393
|
+
@"XCUIElementTypeWindow[1][`name ==`]/XCUIElementTypeButton[`name ==`]",
|
|
394
|
+
// syntax is checked before any predicate is compiled
|
|
395
|
+
@"XCUIElementTypeWindow[`name ==`]/XCUIElementTypeButton[`name == \"a\"`]x",
|
|
396
|
+
];
|
|
397
|
+
for (NSString *query in errors) {
|
|
398
|
+
NSError *error = nil;
|
|
399
|
+
XCTAssertNil([FBClassChainQueryParser parseQuery:query error:&error], @"%@", query);
|
|
400
|
+
XCTAssertNotNil(error, @"%@", query);
|
|
401
|
+
}
|
|
402
|
+
NSArray<NSString *> *invalidPredicates = @[
|
|
403
|
+
@"XCUIElementTypeWindow[`name ==`]/blabla",
|
|
404
|
+
@"XCUIElementTypeWindow[`name ==`]/XCUIElementTypeButton[0]",
|
|
405
|
+
@"XCUIElementTypeWindow[`name ==`]/**/**/XCUIElementTypeButton",
|
|
406
|
+
@"XCUIElementTypeWindow[`name ==`][1][`name ==`]",
|
|
407
|
+
@"XCUIElementTypeWindow[`name == `]",
|
|
408
|
+
];
|
|
409
|
+
for (NSString *query in invalidPredicates) {
|
|
410
|
+
NSError *error = nil;
|
|
411
|
+
XCTAssertThrowsSpecificNamed([FBClassChainQueryParser parseQuery:query error:&error], NSException, NSInvalidArgumentException, @"%@", query);
|
|
412
|
+
}
|
|
413
|
+
NSArray<NSString *> *unknownAttributes = @[
|
|
414
|
+
@"XCUIElementTypeWindow[`nosuchattribute == 1`]",
|
|
415
|
+
@"XCUIElementTypeWindow[$nosuchattribute == 1$]",
|
|
416
|
+
@"XCUIElementTypeWindow[`nosuchattribute == 1`]/blabla",
|
|
417
|
+
];
|
|
418
|
+
for (NSString *query in unknownAttributes) {
|
|
419
|
+
NSError *error = nil;
|
|
420
|
+
XCTAssertThrowsSpecificNamed([FBClassChainQueryParser parseQuery:query error:&error], NSException, @"FBUnknownAttributeException", @"%@", query);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
- (void)testStarsDirectlyBeforeClassNameAreRejected
|
|
425
|
+
{
|
|
426
|
+
for (NSString *query in @[@"**XCUIElementTypeButton", @"***XCUIElementTypeButton", @"XCUIElementTypeWindow/**XCUIElementTypeButton", @"**/**XCUIElementTypeButton"]) {
|
|
427
|
+
NSError *error = nil;
|
|
428
|
+
XCTAssertNil([FBClassChainQueryParser parseQuery:query error:&error], @"%@", query);
|
|
429
|
+
XCTAssertNotNil(error, @"%@", query);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
- (void)testEmptyPredicateIsRejected
|
|
434
|
+
{
|
|
435
|
+
for (NSString *query in @[@"XCUIElementTypeWindow[``]", @"XCUIElementTypeWindow[$$]"]) {
|
|
436
|
+
NSError *error = nil;
|
|
437
|
+
XCTAssertNil([FBClassChainQueryParser parseQuery:query error:&error], @"%@", query);
|
|
438
|
+
XCTAssertNotNil(error, @"%@", query);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
- (void)testLeadingPredicateMarkersAreNotSwallowed
|
|
443
|
+
{
|
|
444
|
+
NSError *error = nil;
|
|
445
|
+
// The first marker opens the predicate and the second one closes it, so nothing valid follows
|
|
446
|
+
XCTAssertNil([FBClassChainQueryParser parseQuery:@"XCUIElementTypeWindow[``name == 'a'`]" error:&error]);
|
|
447
|
+
XCTAssertNotNil(error);
|
|
448
|
+
// The predicate text is "`name == 'a'", where the doubled marker is an escaped one
|
|
449
|
+
XCTAssertThrowsSpecificNamed([FBClassChainQueryParser parseQuery:@"XCUIElementTypeWindow[```name == 'a'`]" error:&error], NSException, NSInvalidArgumentException);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
- (void)testPositionIsAnAsciiInt
|
|
453
|
+
{
|
|
454
|
+
NSArray<NSString *> *invalid = @[@"[٣]", @"[0]", @"[4294967296]", @"[99999999999999999999]", @"[-99999999999999999999]", @"[2147483648]", @"[-2147483648]", @"[-9223372036854775808]"];
|
|
455
|
+
for (NSString *position in invalid) {
|
|
456
|
+
NSString *query = [@"XCUIElementTypeWindow" stringByAppendingString:position];
|
|
457
|
+
NSError *error = nil;
|
|
458
|
+
XCTAssertNil([FBClassChainQueryParser parseQuery:query error:&error], @"%@", query);
|
|
459
|
+
XCTAssertNotNil(error, @"%@", query);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
- (void)testPredicateTextIsNotAFormatString
|
|
464
|
+
{
|
|
465
|
+
NSError *error = nil;
|
|
466
|
+
FBClassChain *chain = [FBClassChainQueryParser parseQuery:@"XCUIElementTypeWindow[`name LIKE '50%'`]" error:&error];
|
|
467
|
+
XCTAssertNotNil(chain);
|
|
468
|
+
XCTAssertEqual(chain.elements.firstObject.predicates.count, 1);
|
|
469
|
+
XCTAssertThrowsSpecificNamed([FBClassChainQueryParser parseQuery:@"XCUIElementTypeWindow[`name == %@`]" error:&error], NSException, NSInvalidArgumentException);
|
|
470
|
+
XCTAssertThrowsSpecificNamed([FBClassChainQueryParser parseQuery:@"XCUIElementTypeWindow[`name == %d AND label == %@`]" error:&error], NSException, NSInvalidArgumentException);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
- (void)testErrorMessages
|
|
474
|
+
{
|
|
475
|
+
NSDictionary<NSString *, NSString *> *expectations = @{
|
|
476
|
+
@"": @"Cannot parse class chain query ''. The query must not be empty.",
|
|
477
|
+
@"XCUIElementTypeWindow//*": @"Cannot parse class chain query 'XCUIElementTypeWindow//*'. Unexpected character detected at position 23:\nXCUIElementTypeWindow// <----",
|
|
478
|
+
@"XCUIElementTypeWindow/": @"Cannot parse class chain query 'XCUIElementTypeWindow/'. Unexpected character detected at position 22:\nXCUIElementTypeWindow/ <----",
|
|
479
|
+
@"blabla": @"Cannot parse class chain query 'blabla'. 'blabla' class name is unknown to WDA",
|
|
480
|
+
@"XCUIElementTypeWindow[0]": @"Cannot parse class chain query 'XCUIElementTypeWindow[0]'. Position value '0' is expected to be a valid integer number not equal to zero.",
|
|
481
|
+
@"XCUIElementTypeWindow[1][2]": @"Cannot parse class chain query 'XCUIElementTypeWindow[1][2]'. Position value '2' is expected to be set only once.",
|
|
482
|
+
@"XCUIElementTypeWindow[1][`name == 'a'`]": @"Cannot parse class chain query 'XCUIElementTypeWindow[1][`name == 'a'`]'. Predicate value 'name == 'a'' must be set before position value.",
|
|
483
|
+
@"**/**/XCUIElementTypeWindow": @"Cannot parse class chain query '**/**/XCUIElementTypeWindow'. Unexpected token '**/'. Descendant markers cannot be duplicated.",
|
|
484
|
+
};
|
|
485
|
+
for (NSString *query in expectations) {
|
|
486
|
+
NSError *error = nil;
|
|
487
|
+
XCTAssertNil([FBClassChainQueryParser parseQuery:query error:&error], @"%@", query);
|
|
488
|
+
XCTAssertEqualObjects(error.localizedDescription, expectations[query], @"%@", query);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
313
492
|
@end
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "appium-webdriveragent",
|
|
3
|
-
"version": "17.0.
|
|
3
|
+
"version": "17.0.14",
|
|
4
4
|
"description": "Package bundling WebDriverAgent",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Appium",
|
|
@@ -83,5 +83,5 @@
|
|
|
83
83
|
"node": "^22.22.2 || ^24.15.0 || >=26.0.0",
|
|
84
84
|
"npm": ">=10"
|
|
85
85
|
},
|
|
86
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "e4a85699cd63eda53c26682f7c001b119967ba43"
|
|
87
87
|
}
|