Skip to content

Commit

Permalink
fix: do nothing for an empty array in w3c actions (#308)
Browse files Browse the repository at this point in the history
* fix: do nothing for an empty array in w3c actions

* apply the same change in key actions

* add test case

* revert removed code for safe

* tweak spaces
  • Loading branch information
KazuCocoa authored Jul 21, 2024
1 parent a0aedfe commit a1aa636
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
21 changes: 21 additions & 0 deletions WebDriverAgentMac/IntegrationTests/AMW3CActionsTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -370,4 +370,25 @@ - (void)testKeys
XCTAssertEqualObjects(edit.value, @"NBA");
}

- (void)testKeysWithEmptyActions
{
[self switchToEditsTab];
XCUIElement *edit = self.testedApplication.textFields.firstMatch;
[edit click];

NSArray<NSDictionary<NSString *, id> *> *gesture =
@[@{
@"type": @"key",
@"id": @"keyboard",
@"actions": @[],
},
];
NSError *error;
XCTAssertTrue([self.testedApplication fb_performW3CActions:gesture
elementCache:nil
error:&error]);
XCTAssertNil(error);
XCTAssertEqualObjects(edit.value, @"");
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ - (nullable NSValue *)positionWithError:(NSError **)error
}
return nil;
}

XCUIElement *element = isOriginAnElement ? (XCUIElement *)origin : nil;
NSNumber *x = [self.actionItem objectForKey:FB_ACTION_ITEM_KEY_X];
NSNumber *y = [self.actionItem objectForKey:FB_ACTION_ITEM_KEY_Y];
Expand All @@ -272,7 +272,7 @@ - (nullable NSValue *)positionWithError:(NSError **)error
}
return nil;
}

if (nil != element) {
if (nil == x && nil == y) {
return [self hitpointWithElement:element
Expand All @@ -283,13 +283,13 @@ - (nullable NSValue *)positionWithError:(NSError **)error
positionOffset:[NSValue am_valueWithCGPoint:CGPointMake(x.floatValue, y.floatValue)]
error:error];
}

if ([origin isKindOfClass:NSString.class] && [origin isEqualToString:FB_ORIGIN_TYPE_VIEWPORT]) {
return [self hitpointWithElement:nil
positionOffset:[NSValue am_valueWithCGPoint:CGPointMake(x.floatValue, y.floatValue)]
error:error];
}

// origin == FB_ORIGIN_TYPE_POINTER
if (nil == self.previousItem) {
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];
Expand Down Expand Up @@ -734,7 +734,7 @@ @implementation FBW3CActionsSynthesizer
shouldCancelNextItem = YES;
continue;
}

if (nil == self.elementCache) {
[result addObject:actionItem];
continue;
Expand Down Expand Up @@ -874,7 +874,7 @@ @implementation FBW3CActionsSynthesizer

NSArray<NSDictionary<NSString *, id> *> *actionItems = [actionDescription objectForKey:FB_KEY_ACTIONS];
if (nil == actionItems || 0 == actionItems.count) {
NSString *description = [NSString stringWithFormat:@"It is mandatory to have at least one gesture item defined for each action. Action with id '%@' contains none", actionId];
NSString *description = [NSString stringWithFormat:@"It is mandatory to have at least one gesture item defined for each action. Action with id '%@' contains none", actionId];
if (error) {
*error = [[FBErrorBuilder.builder withDescription:description] build];
}
Expand Down Expand Up @@ -959,6 +959,19 @@ - (nullable XCSynthesizedEventRecord *)synthesizeWithError:(NSError **)error
}
return nil;
}
NSArray<NSDictionary<NSString *, id> *> *actionItems = [action objectForKey:FB_KEY_ACTIONS];
if (nil == actionItems) {
NSString *description = [NSString stringWithFormat:@"It is mandatory to have at least one item defined for each action. Action with id '%@' contains none", actionId];
if (error) {
*error = [[FBErrorBuilder.builder withDescription:description] build];
}
return nil;
}
if (0 == actionItems.count) {
[FBLogger logFmt:@"Action items in the action id '%@' had an empty array. Skipping the action.", actionId];
continue;
}

[actionIds addObject:actionId];
[actionsMapping setObject:action forKey:actionId];
}
Expand Down

0 comments on commit a1aa636

Please sign in to comment.