appium-webdriveragent 4.10.8 → 4.10.9

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 CHANGED
@@ -1,3 +1,5 @@
1
+ ## [4.10.9](https://github.com/appium/WebDriverAgent/compare/v4.10.8...v4.10.9) (2022-11-25)
2
+
1
3
  ## [4.10.8](https://github.com/appium/WebDriverAgent/compare/v4.10.7...v4.10.8) (2022-11-24)
2
4
 
3
5
  ## [4.10.7](https://github.com/appium/WebDriverAgent/compare/v4.10.6...v4.10.7) (2022-11-24)
@@ -50,7 +50,7 @@ static char XCUIELEMENT_IS_RESOLVED_NATIVELY_KEY;
50
50
  NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(id<FBXCElementSnapshot> snapshot, NSDictionary *bindings) {
51
51
  return [[FBXCElementSnapshotWrapper wdUIDWithSnapshot:snapshot] isEqualToString:uid];
52
52
  }];
53
- return (XCUIElement *)[query matchingPredicate:predicate].fb_firstMatch;
53
+ return [query matchingPredicate:predicate].fb_firstMatch ?: self;
54
54
  }
55
55
 
56
56
  @end
@@ -38,7 +38,7 @@ const int ELEMENT_CACHE_SIZE = 1024;
38
38
  return nil;
39
39
  }
40
40
  _elementCache = [[LRUCache alloc] initWithCapacity:ELEMENT_CACHE_SIZE];
41
- _elementsNeedReset = YES;
41
+ _elementsNeedReset = NO;
42
42
  return self;
43
43
  }
44
44
 
@@ -50,8 +50,8 @@ const int ELEMENT_CACHE_SIZE = 1024;
50
50
  }
51
51
  @synchronized (self.elementCache) {
52
52
  [self.elementCache setObject:element forKey:uuid];
53
+ self.elementsNeedReset = YES;
53
54
  }
54
- self.elementsNeedReset = YES;
55
55
  return uuid;
56
56
  }
57
57
 
@@ -18,6 +18,7 @@
18
18
  #import "FBProtocolHelpers.h"
19
19
  #import "XCUIElementQuery.h"
20
20
  #import "XCUIElement+FBResolve.h"
21
+ #import "XCUIElement+FBUID.h"
21
22
  #import "XCUIElement+FBUtilities.h"
22
23
  #import "XCUIElement+FBWebDriverAttributes.h"
23
24
 
@@ -39,7 +40,7 @@ id<FBResponsePayload> FBResponseWithCachedElement(XCUIElement *element, FBElemen
39
40
  ? YES
40
41
  : FBSession.activeSession.useNativeCachingStrategy;
41
42
  [elementCache storeElement:(useNativeCachingStrategy ? element : element.fb_stableInstance)];
42
- return FBResponseWithStatus([FBCommandStatus okWithValue: FBDictionaryResponseWithElement(element, compact)]);
43
+ return FBResponseWithStatus([FBCommandStatus okWithValue:FBDictionaryResponseWithElement(element, compact)]);
43
44
  }
44
45
 
45
46
  id<FBResponsePayload> FBResponseWithCachedElements(NSArray<XCUIElement *> *elements, FBElementCache *elementCache, BOOL compact)
@@ -65,7 +66,8 @@ id<FBResponsePayload> FBResponseWithUnknownErrorFormat(NSString *format, ...)
65
66
  va_list argList;
66
67
  va_start(argList, format);
67
68
  NSString *errorMessage = [[NSString alloc] initWithFormat:format arguments:argList];
68
- id<FBResponsePayload> payload = FBResponseWithStatus([FBCommandStatus unknownErrorWithMessage:errorMessage traceback:nil]);
69
+ id<FBResponsePayload> payload = FBResponseWithStatus([FBCommandStatus unknownErrorWithMessage:errorMessage
70
+ traceback:nil]);
69
71
  va_end(argList);
70
72
  return payload;
71
73
  }
@@ -77,13 +79,12 @@ id<FBResponsePayload> FBResponseWithStatus(FBCommandStatus *status)
77
79
  if (nil == status.error) {
78
80
  response[@"value"] = status.value ?: NSNull.null;
79
81
  } else {
80
- NSMutableDictionary* value = [NSMutableDictionary dictionary];
81
- value[@"error"] = status.error;
82
- value[@"message"] = status.message ?: @"";
83
- value[@"traceback"] = status.traceback ?: @"";
84
- response[@"value"] = value.copy;
82
+ response[@"value"] = @{
83
+ @"error": (id)status.error,
84
+ @"message": status.message ?: @"",
85
+ @"traceback": status.traceback ?: @""
86
+ };
85
87
  }
86
-
87
88
  return [[FBResponseJSONPayload alloc] initWithDictionary:response.copy
88
89
  httpStatusCode:status.statusCode];
89
90
  }
@@ -97,31 +98,34 @@ inline NSDictionary *FBDictionaryResponseWithElement(XCUIElement *element, BOOL
97
98
  if (nil == snapshot) {
98
99
  snapshot = element.lastSnapshot ?: element.fb_takeSnapshot;
99
100
  }
101
+ NSDictionary *compactResult = FBToElementDict((NSString *)[FBXCElementSnapshotWrapper wdUIDWithSnapshot:snapshot]);
102
+ if (compact) {
103
+ return compactResult;
104
+ }
105
+
106
+ NSMutableDictionary *result = compactResult.mutableCopy;
100
107
  FBXCElementSnapshotWrapper *wrappedSnapshot = [FBXCElementSnapshotWrapper ensureWrapped:snapshot];
101
- NSMutableDictionary *dictionary = FBInsertElement(@{}, (NSString *)wrappedSnapshot.wdUID).mutableCopy;
102
- if (!compact) {
103
- NSArray *fields = [FBConfiguration.elementResponseAttributes componentsSeparatedByString:@","];
104
- for (NSString *field in fields) {
105
- // 'name' here is the w3c-approved identifier for what we mean by 'type'
106
- if ([field isEqualToString:@"name"] || [field isEqualToString:@"type"]) {
107
- dictionary[field] = wrappedSnapshot.wdType;
108
- } else if ([field isEqualToString:@"text"]) {
109
- dictionary[field] = FBFirstNonEmptyValue(wrappedSnapshot.wdValue, wrappedSnapshot.wdLabel) ?: [NSNull null];
110
- } else if ([field isEqualToString:@"rect"]) {
111
- dictionary[field] = wrappedSnapshot.wdRect;
112
- } else if ([field isEqualToString:@"enabled"]) {
113
- dictionary[field] = @(wrappedSnapshot.wdEnabled);
114
- } else if ([field isEqualToString:@"displayed"]) {
115
- dictionary[field] = @(wrappedSnapshot.wdVisible);
116
- } else if ([field isEqualToString:@"selected"]) {
117
- dictionary[field] = @(wrappedSnapshot.wdSelected);
118
- } else if ([field isEqualToString:@"label"]) {
119
- dictionary[field] = wrappedSnapshot.wdLabel ?: [NSNull null];
120
- } else if ([field hasPrefix:arbitraryAttrPrefix]) {
121
- NSString *attributeName = [field substringFromIndex:[arbitraryAttrPrefix length]];
122
- dictionary[field] = [wrappedSnapshot fb_valueForWDAttributeName:attributeName] ?: [NSNull null];
123
- }
108
+ NSArray *fields = [FBConfiguration.elementResponseAttributes componentsSeparatedByString:@","];
109
+ for (NSString *field in fields) {
110
+ // 'name' here is the w3c-approved identifier for what we mean by 'type'
111
+ if ([field isEqualToString:@"name"] || [field isEqualToString:@"type"]) {
112
+ result[field] = wrappedSnapshot.wdType;
113
+ } else if ([field isEqualToString:@"text"]) {
114
+ result[field] = FBFirstNonEmptyValue(wrappedSnapshot.wdValue, wrappedSnapshot.wdLabel) ?: [NSNull null];
115
+ } else if ([field isEqualToString:@"rect"]) {
116
+ result[field] = wrappedSnapshot.wdRect;
117
+ } else if ([field isEqualToString:@"enabled"]) {
118
+ result[field] = @(wrappedSnapshot.wdEnabled);
119
+ } else if ([field isEqualToString:@"displayed"]) {
120
+ result[field] = @(wrappedSnapshot.wdVisible);
121
+ } else if ([field isEqualToString:@"selected"]) {
122
+ result[field] = @(wrappedSnapshot.wdSelected);
123
+ } else if ([field isEqualToString:@"label"]) {
124
+ result[field] = wrappedSnapshot.wdLabel ?: [NSNull null];
125
+ } else if ([field hasPrefix:arbitraryAttrPrefix]) {
126
+ NSString *attributeName = [field substringFromIndex:[arbitraryAttrPrefix length]];
127
+ result[field] = [wrappedSnapshot fb_valueForWDAttributeName:attributeName] ?: [NSNull null];
124
128
  }
125
129
  }
126
- return dictionary.copy;
130
+ return result.copy;
127
131
  }
@@ -448,9 +448,10 @@ static const double FB_LONG_TAP_DURATION_MS = 600.0;
448
448
  [result addObject:touchItem];
449
449
  continue;
450
450
  }
451
+ NSMutableDictionary *elementDict = FBCleanupElements(options).mutableCopy;
452
+ [elementDict addEntriesFromDictionary:FBToElementDict(element)];
451
453
  NSMutableDictionary<NSString *, id> *processedItem = touchItem.mutableCopy;
452
- [processedItem setObject:FBInsertElement(FBCleanupElements(options), element)
453
- forKey:FB_OPTIONS_KEY];
454
+ processedItem[FB_OPTIONS_KEY] = elementDict.copy;
454
455
  [result addObject:processedItem.copy];
455
456
  }
456
457
  return [[result reverseObjectEnumerator] allObjects];
@@ -12,13 +12,12 @@
12
12
  NS_ASSUME_NONNULL_BEGIN
13
13
 
14
14
  /**
15
- Inserts element uuid into the response dictionary
15
+ Prepares an element dictionary, which could be then used in hybrid W3C/JWP responses
16
16
 
17
- @param dst The target dictionary. It is NOT mutated
18
17
  @param element Either element identifier or element object itself
19
- @returns The changed dictionary
18
+ @returns The resulting dictionary
20
19
  */
21
- NSDictionary *FBInsertElement(NSDictionary *dst, id element);
20
+ NSDictionary<NSString *, id> *FBToElementDict(id element);
22
21
 
23
22
  /**
24
23
  Extracts element uuid from dictionary
@@ -20,12 +20,12 @@ static NSString *const ALWAYS_MATCH_KEY = @"alwaysMatch";
20
20
  static NSString *const FIRST_MATCH_KEY = @"firstMatch";
21
21
 
22
22
 
23
- NSDictionary *FBInsertElement(NSDictionary *dst, id element)
23
+ NSDictionary<NSString *, id> *FBToElementDict(id element)
24
24
  {
25
- NSMutableDictionary *result = dst.mutableCopy;
26
- result[W3C_ELEMENT_KEY] = element;
27
- result[JSONWP_ELEMENT_KEY] = element;
28
- return result.copy;
25
+ return @{
26
+ W3C_ELEMENT_KEY: element,
27
+ JSONWP_ELEMENT_KEY: element
28
+ };
29
29
  }
30
30
 
31
31
  id FBExtractElement(NSDictionary *src)
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "appium-webdriveragent",
3
- "version": "4.10.8",
3
+ "version": "4.10.9",
4
4
  "description": "Package bundling WebDriverAgent",
5
5
  "main": "./build/index.js",
6
6
  "scripts": {