Skip to content

Commit 9f0dcbc

Browse files
fix: Sync the session creation arguments and status response with W3C spec (#203)
1 parent 4a14981 commit 9f0dcbc

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

WebDriverAgentLib/Commands/FBSessionCommands.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ + (NSArray *)routes
8080
{
8181
NSDictionary<NSString *, id> *requirements;
8282
NSError *error;
83-
if (nil == (requirements = FBParseCapabilities(request.arguments, &error))) {
83+
if (![request.arguments[@"capabilities"] isKindOfClass:NSDictionary.class]) {
84+
return FBResponseWithStatus([FBCommandStatus sessionNotCreatedError:@"'capabilities' is mandatory to create a new session"
85+
traceback:nil]);
86+
}
87+
if (nil == (requirements = FBParseCapabilities(request.arguments[@"capabilities"], &error))) {
8488
return FBResponseWithStatus([FBCommandStatus sessionNotCreatedError:error.description traceback:nil]);
8589
}
8690
[FBConfiguration setShouldUseTestManagerForVisibilityDetection:[requirements[@"shouldUseTestManagerForVisibilityDetection"] boolValue]];
@@ -188,6 +192,8 @@ + (NSArray *)routes
188192

189193
return FBResponseWithObject(
190194
@{
195+
@"ready" : @YES,
196+
@"message" : @"WebDriverAgent is ready to accept commands",
191197
@"state" : @"success",
192198
@"os" :
193199
@{

WebDriverAgentLib/Utilities/FBAppiumActionsSynthesizer.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ @implementation FBAppiumActionsSynthesizer
397397
continue;
398398
}
399399
NSMutableDictionary<NSString *, id> *processedItem = touchItem.mutableCopy;
400-
[processedItem setObject:FBInsertElement((id) [processedItem objectForKey:FB_OPTIONS_KEY], element)
400+
[processedItem setObject:FBInsertElement(FBCleanupElements(options), element)
401401
forKey:FB_OPTIONS_KEY];
402402
[result addObject:processedItem.copy];
403403
}

WebDriverAgentLib/Utilities/FBProtocolHelpers.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ NSDictionary *FBInsertElement(NSDictionary *dst, id element);
2828
*/
2929
id _Nullable FBExtractElement(NSDictionary *src);
3030

31+
/**
32+
Cleanup items having element keys from the dictionary
33+
34+
@param src The source dictionary
35+
@returns The resulting dictionary
36+
*/
37+
NSDictionary *FBCleanupElements(NSDictionary *src);
38+
3139
/**
3240
Parses key/value pairs of valid W3C capabilities
3341

WebDriverAgentLib/Utilities/FBProtocolHelpers.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ id FBExtractElement(NSDictionary *src)
3939
return nil;
4040
}
4141

42+
NSDictionary *FBCleanupElements(NSDictionary *src)
43+
{
44+
NSMutableDictionary *result = src.mutableCopy;
45+
for (NSString* key in src) {
46+
if ([key.lowercaseString isEqualToString:W3C_ELEMENT_KEY.lowercaseString]
47+
|| [key.lowercaseString isEqualToString:JSONWP_ELEMENT_KEY.lowercaseString]) {
48+
[result removeObjectForKey:key];
49+
}
50+
}
51+
return result.copy;
52+
}
53+
4254
NSArray<NSString *> *standardCapabilities(void)
4355
{
4456
static NSArray<NSString *> *standardCaps;

0 commit comments

Comments
 (0)