Skip to content

Commit 9e70ec1

Browse files
authored
fix: do nothing for an empty array in w3c actions (#919)
* fix: do nothing for an empty array actions * Update FBW3CActionsSynthesizer.m * test: add test
1 parent 89346a5 commit 9e70ec1

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

WebDriverAgentLib/Utilities/FBW3CActionsSynthesizer.m

+13-16
Original file line numberDiff line numberDiff line change
@@ -692,14 +692,6 @@ @implementation FBW3CActionsSynthesizer
692692
});
693693

694694
NSArray<NSDictionary<NSString *, id> *> *actionItems = [actionDescription objectForKey:FB_KEY_ACTIONS];
695-
if (nil == actionItems || 0 == actionItems.count) {
696-
NSString *description = [NSString stringWithFormat:@"It is mandatory to have at least one item defined for each action. Action with id '%@' contains none", actionId];
697-
if (error) {
698-
*error = [[FBErrorBuilder.builder withDescription:description] build];
699-
}
700-
return nil;
701-
}
702-
703695
FBW3CKeyItemsChain *chain = [[FBW3CKeyItemsChain alloc] init];
704696
NSArray<NSDictionary<NSString *, id> *> *processedItems = [self preprocessedActionItemsWith:actionItems];
705697
for (NSDictionary<NSString *, id> *actionItem in processedItems) {
@@ -770,14 +762,6 @@ @implementation FBW3CActionsSynthesizer
770762
}
771763

772764
NSArray<NSDictionary<NSString *, id> *> *actionItems = [actionDescription objectForKey:FB_KEY_ACTIONS];
773-
if (nil == actionItems || 0 == actionItems.count) {
774-
NSString *description = [NSString stringWithFormat:@"It is mandatory to have at least one gesture item defined for each action. Action with id '%@' contains none", actionId];
775-
if (error) {
776-
*error = [[FBErrorBuilder.builder withDescription:description] build];
777-
}
778-
return nil;
779-
}
780-
781765
FBW3CGestureItemsChain *chain = [[FBW3CGestureItemsChain alloc] init];
782766
NSArray<NSDictionary<NSString *, id> *> *processedItems = [self preprocessedActionItemsWith:actionItems];
783767
for (NSDictionary<NSString *, id> *actionItem in processedItems) {
@@ -852,7 +836,20 @@ - (nullable XCSynthesizedEventRecord *)synthesizeWithError:(NSError **)error
852836
*error = [[FBErrorBuilder.builder withDescription:description] build];
853837
}
854838
return nil;
839+
}
840+
NSArray<NSDictionary<NSString *, id> *> *actionItems = [action objectForKey:FB_KEY_ACTIONS];
841+
if (nil == actionItems) {
842+
NSString *description = [NSString stringWithFormat:@"It is mandatory to have at least one item defined for each action. Action with id '%@' contains none", actionId];
843+
if (error) {
844+
*error = [[FBErrorBuilder.builder withDescription:description] build];
845+
}
846+
return nil;
847+
}
848+
if (0 == actionItems.count) {
849+
[FBLogger logFmt:@"Action items in the action id '%@' had an empty array. Skipping the action.", actionId];
850+
continue;
855851
}
852+
856853
[actionIds addObject:actionId];
857854
[actionsMapping setObject:action forKey:actionId];
858855
}

WebDriverAgentTests/IntegrationTests/FBW3CTypeActionsTests.m

+24
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,28 @@ - (void)testTextTyping
158158
XCTAssertEqualObjects(textField.wdValue, @"🏀NBA");
159159
}
160160

161+
- (void)testTextTypingWithEmptyActions
162+
{
163+
if (![XCPointerEvent.class fb_areKeyEventsSupported]) {
164+
return;
165+
}
166+
167+
XCUIElement *textField = self.testedApplication.textFields[@"aIdentifier"];
168+
[textField tap];
169+
NSArray<NSDictionary<NSString *, id> *> *typeAction =
170+
@[
171+
@{
172+
@"type": @"pointer",
173+
@"id": @"touch",
174+
@"actions": @[],
175+
},
176+
];
177+
NSError *error;
178+
XCTAssertTrue([self.testedApplication fb_performW3CActions:typeAction
179+
elementCache:nil
180+
error:&error]);
181+
XCTAssertNil(error);
182+
XCTAssertEqualObjects(textField.value, @"");
183+
}
184+
161185
@end

0 commit comments

Comments
 (0)