appium-mac2-driver 1.18.0 → 1.18.2

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,17 @@
1
+ ## [1.18.2](https://github.com/appium/appium-mac2-driver/compare/v1.18.1...v1.18.2) (2024-07-21)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * do nothing for an empty array in w3c actions ([#308](https://github.com/appium/appium-mac2-driver/issues/308)) ([a1aa636](https://github.com/appium/appium-mac2-driver/commit/a1aa636d8856c97b8edb1c091b3919a45a6d6716))
7
+
8
+ ## [1.18.1](https://github.com/appium/appium-mac2-driver/compare/v1.18.0...v1.18.1) (2024-07-20)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * Add a test for the keyboard input and perform related fixes ([#311](https://github.com/appium/appium-mac2-driver/issues/311)) ([af826e8](https://github.com/appium/appium-mac2-driver/commit/af826e83f60dd278f44042e2ef36b81390f3ef19))
14
+
1
15
  ## [1.18.0](https://github.com/appium/appium-mac2-driver/compare/v1.17.5...v1.18.0) (2024-07-18)
2
16
 
3
17
 
@@ -261,6 +261,18 @@
261
261
  },
262
262
  ],
263
263
 
264
+ // Keys are not balanced
265
+ @[@{
266
+ @"type": @"key",
267
+ @"id": @"keyboard",
268
+ @"actions": @[
269
+ @{@"type": @"keyDown", @"value": @"n"},
270
+ @{@"type": @"keyUp", @"value": @"n"},
271
+ @{@"type": @"keyUp", @"value": @"b"},
272
+ ],
273
+ },
274
+ ],
275
+
264
276
  ];
265
277
 
266
278
  for (NSArray<NSDictionary<NSString *, id> *> *invalidGesture in invalidGestures) {
@@ -274,6 +286,7 @@
274
286
 
275
287
  - (void)testClick
276
288
  {
289
+ [self switchToButtonsTab];
277
290
  XCUIElement *checkbox = self.testedApplication.checkBoxes.firstMatch;
278
291
  NSNumber *value = checkbox.value;
279
292
 
@@ -300,6 +313,7 @@
300
313
 
301
314
  - (void)testRightClick
302
315
  {
316
+ [self switchToButtonsTab];
303
317
  XCUIElement *checkbox = self.testedApplication.checkBoxes.firstMatch;
304
318
  NSNumber *value = checkbox.value;
305
319
 
@@ -324,5 +338,57 @@
324
338
  XCTAssertTrue([checkbox.value boolValue] == [value boolValue]);
325
339
  }
326
340
 
341
+ - (void)testKeys
342
+ {
343
+ [self switchToEditsTab];
344
+ XCUIElement *edit = self.testedApplication.textFields.firstMatch;
345
+ [edit click];
346
+
347
+ NSArray<NSDictionary<NSString *, id> *> *gesture =
348
+ @[@{
349
+ @"type": @"key",
350
+ @"id": @"keyboard",
351
+ @"actions": @[
352
+ @{@"type": @"keyDown", @"value": @"\uE008"},
353
+ @{@"type": @"pause", @"duration": @500},
354
+ @{@"type": @"keyDown", @"value": @"n"},
355
+ @{@"type": @"keyUp", @"value": @"n"},
356
+ @{@"type": @"keyDown", @"value": @"b"},
357
+ @{@"type": @"keyUp", @"value": @"b"},
358
+ @{@"type": @"keyDown", @"value": @"a"},
359
+ @{@"type": @"keyUp", @"value": @"a"},
360
+ @{@"type": @"pause", @"duration": @500},
361
+ @{@"type": @"keyUp", @"value": @"\uE008"},
362
+ ],
363
+ },
364
+ ];
365
+ NSError *error;
366
+ XCTAssertTrue([self.testedApplication fb_performW3CActions:gesture
367
+ elementCache:nil
368
+ error:&error]);
369
+ XCTAssertNil(error);
370
+ XCTAssertEqualObjects(edit.value, @"NBA");
371
+ }
372
+
373
+ - (void)testKeysWithEmptyActions
374
+ {
375
+ [self switchToEditsTab];
376
+ XCUIElement *edit = self.testedApplication.textFields.firstMatch;
377
+ [edit click];
378
+
379
+ NSArray<NSDictionary<NSString *, id> *> *gesture =
380
+ @[@{
381
+ @"type": @"key",
382
+ @"id": @"keyboard",
383
+ @"actions": @[],
384
+ },
385
+ ];
386
+ NSError *error;
387
+ XCTAssertTrue([self.testedApplication fb_performW3CActions:gesture
388
+ elementCache:nil
389
+ error:&error]);
390
+ XCTAssertNil(error);
391
+ XCTAssertEqualObjects(edit.value, @"");
392
+ }
327
393
 
328
394
  @end
@@ -80,7 +80,7 @@ static NSString *const FB_KEY_ACTIONS = @"actions";
80
80
 
81
81
  @property (nullable, readonly, nonatomic) FBW3CKeyItem *previousItem;
82
82
 
83
- - (NSUInteger)calculateModifierForChain:(NSArray *)allItems
83
+ - (NSUInteger)calculateModifiersForChain:(NSArray *)allItems
84
84
  lastItemIndex:(NSUInteger)lastItemIndex;
85
85
 
86
86
  @end
@@ -260,7 +260,7 @@ static NSString *const FB_KEY_ACTIONS = @"actions";
260
260
  }
261
261
  return nil;
262
262
  }
263
-
263
+
264
264
  XCUIElement *element = isOriginAnElement ? (XCUIElement *)origin : nil;
265
265
  NSNumber *x = [self.actionItem objectForKey:FB_ACTION_ITEM_KEY_X];
266
266
  NSNumber *y = [self.actionItem objectForKey:FB_ACTION_ITEM_KEY_Y];
@@ -272,7 +272,7 @@ static NSString *const FB_KEY_ACTIONS = @"actions";
272
272
  }
273
273
  return nil;
274
274
  }
275
-
275
+
276
276
  if (nil != element) {
277
277
  if (nil == x && nil == y) {
278
278
  return [self hitpointWithElement:element
@@ -283,13 +283,13 @@ static NSString *const FB_KEY_ACTIONS = @"actions";
283
283
  positionOffset:[NSValue am_valueWithCGPoint:CGPointMake(x.floatValue, y.floatValue)]
284
284
  error:error];
285
285
  }
286
-
286
+
287
287
  if ([origin isKindOfClass:NSString.class] && [origin isEqualToString:FB_ORIGIN_TYPE_VIEWPORT]) {
288
288
  return [self hitpointWithElement:nil
289
289
  positionOffset:[NSValue am_valueWithCGPoint:CGPointMake(x.floatValue, y.floatValue)]
290
290
  error:error];
291
291
  }
292
-
292
+
293
293
  // origin == FB_ORIGIN_TYPE_POINTER
294
294
  if (nil == self.previousItem) {
295
295
  NSString *errorDescription = [NSString stringWithFormat:@"There is no previous item for '%@' action item, however %@ is set to '%@'", self.actionItem, FB_ACTION_ITEM_KEY_ORIGIN, FB_ORIGIN_TYPE_POINTER];
@@ -436,7 +436,7 @@ static NSString *const FB_KEY_ACTIONS = @"actions";
436
436
  return self;
437
437
  }
438
438
 
439
- - (NSUInteger)calculateModifierForChain:(NSArray *)allItems
439
+ - (NSUInteger)calculateModifiersForChain:(NSArray *)allItems
440
440
  lastItemIndex:(NSUInteger)lastItemIndex
441
441
  {
442
442
  NSUInteger result = 0;
@@ -501,7 +501,7 @@ static NSString *const FB_KEY_ACTIONS = @"actions";
501
501
  BOOL isKeyDown = [item isKindOfClass:FBKeyDownItem.class];
502
502
  BOOL isKeyUp = !isKeyDown && [item isKindOfClass:FBKeyUpItem.class];
503
503
  if (!isKeyUp && !isKeyDown) {
504
- break;
504
+ continue;
505
505
  }
506
506
 
507
507
  NSString *value = [item performSelector:@selector(value)];
@@ -536,36 +536,46 @@ static NSString *const FB_KEY_ACTIONS = @"actions";
536
536
  }
537
537
 
538
538
  NSNumber *modifier = AMToMetaModifier(self.value);
539
- NSTimeInterval offsetSeconds = FBMillisToSeconds(self.offset);
540
- XCPointerEventPath *result = nil == eventPath ? [[XCPointerEventPath alloc] initForTextInput] : eventPath;
541
539
  if (nil != modifier) {
542
- NSUInteger previousModifier = [self calculateModifierForChain:allItems lastItemIndex:currentItemIndex - 1];
543
- [result setModifiers:previousModifier & ~[modifier unsignedIntValue]
544
- mergeWithCurrentModifierFlags:NO
545
- atOffset:offsetSeconds];
546
- return @[result];
540
+ return @[];
547
541
  }
548
542
 
543
+ NSTimeInterval offsetSeconds = FBMillisToSeconds(self.offset);
544
+ XCPointerEventPath *result = nil == eventPath ? [[XCPointerEventPath alloc] initForTextInput] : eventPath;
545
+
549
546
  NSString *specialKey = AMToSpecialKey(self.value);
547
+ NSUInteger modifiers = [self calculateModifiersForChain:allItems lastItemIndex:currentItemIndex];
550
548
  if (nil != specialKey) {
551
- NSUInteger previousModifier = [self calculateModifierForChain:allItems lastItemIndex:currentItemIndex];
552
- if ([specialKey isEqualToString:@""]) {
553
- // NOOP
554
- [result setModifiers:previousModifier
555
- mergeWithCurrentModifierFlags:NO
556
- atOffset:offsetSeconds];
557
- } else {
549
+ if (specialKey.length > 0) {
558
550
  [result typeKey:specialKey
559
- modifiers:previousModifier
551
+ modifiers:modifiers
560
552
  atOffset:offsetSeconds];
561
553
  }
562
554
  return @[result];
563
555
  }
564
556
 
565
- [result typeText:self.value
566
- atOffset:offsetSeconds
567
- typingSpeed:[self.class defaultTypingFrequency]
568
- shouldRedact:NO];
557
+ NSUInteger len = [self.value length];
558
+ unichar buffer[len + 1];
559
+ [self.value getCharacters:buffer range:NSMakeRange(0, len)];
560
+ for (int i = 0; i < 1; i++) {
561
+ unichar charCode = buffer[i];
562
+ NSString *oneChar = [NSString stringWithFormat:@"%C", charCode];
563
+ // 0x7F is the end of the first half of the ASCII table, where (almoust) all
564
+ // chars have their own key representations
565
+ if (charCode <= 0x7F) {
566
+ [result typeKey:oneChar
567
+ modifiers:modifiers
568
+ atOffset:offsetSeconds];
569
+ } else {
570
+ // The typeText API does not respect modifiers
571
+ // while the typeKey API can only enter keys
572
+ [result typeText:oneChar
573
+ atOffset:offsetSeconds
574
+ typingSpeed:[self.class defaultTypingFrequency]
575
+ shouldRedact:NO];
576
+ }
577
+ }
578
+
569
579
  return @[result];
570
580
  }
571
581
 
@@ -608,7 +618,7 @@ mergeWithCurrentModifierFlags:NO
608
618
  BOOL isKeyDown = [item isKindOfClass:FBKeyDownItem.class];
609
619
  BOOL isKeyUp = !isKeyDown && [item isKindOfClass:FBKeyUpItem.class];
610
620
  if (!isKeyUp && !isKeyDown) {
611
- break;
621
+ continue;
612
622
  }
613
623
 
614
624
  NSString *value = [item performSelector:@selector(value)];
@@ -635,20 +645,7 @@ mergeWithCurrentModifierFlags:NO
635
645
  return nil;
636
646
  }
637
647
 
638
- NSNumber *modifier = AMToMetaModifier(self.value);
639
- if (nil == modifier) {
640
- return @[];
641
- }
642
- NSUInteger previousModifier = [self calculateModifierForChain:allItems lastItemIndex:currentItemIndex - 1];
643
- if ([modifier unsignedIntValue] == previousModifier) {
644
- return @[];
645
- }
646
-
647
- XCPointerEventPath *result = nil == eventPath ? [[XCPointerEventPath alloc] initForTextInput] : eventPath;
648
- [result setModifiers:previousModifier | [modifier unsignedIntValue]
649
- mergeWithCurrentModifierFlags:NO
650
- atOffset:FBMillisToSeconds(self.offset)];
651
- return @[result];
648
+ return @[];
652
649
  }
653
650
 
654
651
  @end
@@ -737,7 +734,7 @@ mergeWithCurrentModifierFlags:NO
737
734
  shouldCancelNextItem = YES;
738
735
  continue;
739
736
  }
740
-
737
+
741
738
  if (nil == self.elementCache) {
742
739
  [result addObject:actionItem];
743
740
  continue;
@@ -877,7 +874,7 @@ mergeWithCurrentModifierFlags:NO
877
874
 
878
875
  NSArray<NSDictionary<NSString *, id> *> *actionItems = [actionDescription objectForKey:FB_KEY_ACTIONS];
879
876
  if (nil == actionItems || 0 == actionItems.count) {
880
- NSString *description = [NSString stringWithFormat:@"It is mandatory to have at least one gesture item defined for each action. Action with id '%@' contains none", actionId];
877
+ NSString *description = [NSString stringWithFormat:@"It is mandatory to have at least one gesture item defined for each action. Action with id '%@' contains none", actionId];
881
878
  if (error) {
882
879
  *error = [[FBErrorBuilder.builder withDescription:description] build];
883
880
  }
@@ -962,6 +959,19 @@ mergeWithCurrentModifierFlags:NO
962
959
  }
963
960
  return nil;
964
961
  }
962
+ NSArray<NSDictionary<NSString *, id> *> *actionItems = [action objectForKey:FB_KEY_ACTIONS];
963
+ if (nil == actionItems) {
964
+ NSString *description = [NSString stringWithFormat:@"It is mandatory to have at least one item defined for each action. Action with id '%@' contains none", actionId];
965
+ if (error) {
966
+ *error = [[FBErrorBuilder.builder withDescription:description] build];
967
+ }
968
+ return nil;
969
+ }
970
+ if (0 == actionItems.count) {
971
+ [FBLogger logFmt:@"Action items in the action id '%@' had an empty array. Skipping the action.", actionId];
972
+ continue;
973
+ }
974
+
965
975
  [actionIds addObject:actionId];
966
976
  [actionsMapping setObject:action forKey:actionId];
967
977
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "appium-mac2-driver",
3
- "version": "1.18.0",
3
+ "version": "1.18.2",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "appium-mac2-driver",
9
- "version": "1.18.0",
9
+ "version": "1.18.2",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "@appium/strongbox": "^0.x",
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "mac",
7
7
  "XCTest"
8
8
  ],
9
- "version": "1.18.0",
9
+ "version": "1.18.2",
10
10
  "author": "Appium Contributors",
11
11
  "license": "Apache-2.0",
12
12
  "repository": {