Skip to content

Commit

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

* Update FBW3CActionsSynthesizer.m

* test: add test
  • Loading branch information
KazuCocoa authored Jul 18, 2024
1 parent 89346a5 commit 9e70ec1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
29 changes: 13 additions & 16 deletions WebDriverAgentLib/Utilities/FBW3CActionsSynthesizer.m
Original file line number Diff line number Diff line change
Expand Up @@ -692,14 +692,6 @@ @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 item defined for each action. Action with id '%@' contains none", actionId];
if (error) {
*error = [[FBErrorBuilder.builder withDescription:description] build];
}
return nil;
}

FBW3CKeyItemsChain *chain = [[FBW3CKeyItemsChain alloc] init];
NSArray<NSDictionary<NSString *, id> *> *processedItems = [self preprocessedActionItemsWith:actionItems];
for (NSDictionary<NSString *, id> *actionItem in processedItems) {
Expand Down Expand Up @@ -770,14 +762,6 @@ @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];
if (error) {
*error = [[FBErrorBuilder.builder withDescription:description] build];
}
return nil;
}

FBW3CGestureItemsChain *chain = [[FBW3CGestureItemsChain alloc] init];
NSArray<NSDictionary<NSString *, id> *> *processedItems = [self preprocessedActionItemsWith:actionItems];
for (NSDictionary<NSString *, id> *actionItem in processedItems) {
Expand Down Expand Up @@ -852,7 +836,20 @@ - (nullable XCSynthesizedEventRecord *)synthesizeWithError:(NSError **)error
*error = [[FBErrorBuilder.builder withDescription:description] build];
}
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
24 changes: 24 additions & 0 deletions WebDriverAgentTests/IntegrationTests/FBW3CTypeActionsTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,28 @@ - (void)testTextTyping
XCTAssertEqualObjects(textField.wdValue, @"🏀NBA");
}

- (void)testTextTypingWithEmptyActions
{
if (![XCPointerEvent.class fb_areKeyEventsSupported]) {
return;
}

XCUIElement *textField = self.testedApplication.textFields[@"aIdentifier"];
[textField tap];
NSArray<NSDictionary<NSString *, id> *> *typeAction =
@[
@{
@"type": @"pointer",
@"id": @"touch",
@"actions": @[],
},
];
NSError *error;
XCTAssertTrue([self.testedApplication fb_performW3CActions:typeAction
elementCache:nil
error:&error]);
XCTAssertNil(error);
XCTAssertEqualObjects(textField.value, @"");
}

@end

0 comments on commit 9e70ec1

Please sign in to comment.