diff --git a/.gitignore b/.gitignore index 2f5858d63..57321f776 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,6 @@ Resources/WebDriverAgent.bundle # Modules map recreated on each build Modules/module.modulemap + +# test run +*.trace diff --git a/WebDriverAgentLib/Categories/NSExpression+FBFormat.m b/WebDriverAgentLib/Categories/NSExpression+FBFormat.m index f5d51d8e6..fa5d8e3c3 100644 --- a/WebDriverAgentLib/Categories/NSExpression+FBFormat.m +++ b/WebDriverAgentLib/Categories/NSExpression+FBFormat.m @@ -17,14 +17,14 @@ + (instancetype)fb_wdExpressionWithExpression:(NSExpression *)input if ([input expressionType] != NSKeyPathExpressionType) { return input; } - NSString *actualPropName = [input keyPath]; - NSUInteger dotPos = [actualPropName rangeOfString:@"."].location; + NSString *propName = [input keyPath]; + NSUInteger dotPos = [propName rangeOfString:@"."].location; if (NSNotFound != dotPos) { - actualPropName = [actualPropName substringToIndex:dotPos]; - NSString *suffix = [actualPropName substringFromIndex:dotPos]; + NSString *actualPropName = [propName substringToIndex:dotPos]; + NSString *suffix = [propName substringFromIndex:(dotPos + 1)]; return [NSExpression expressionForKeyPath:[NSString stringWithFormat:@"%@.%@", [FBElementUtils wdAttributeNameForAttributeName:actualPropName], suffix]]; } - return [NSExpression expressionForKeyPath:[FBElementUtils wdAttributeNameForAttributeName:actualPropName]]; + return [NSExpression expressionForKeyPath:[FBElementUtils wdAttributeNameForAttributeName:propName]]; } @end diff --git a/WebDriverAgentTests/UnitTests/NSExpressionFBFormatTests.m b/WebDriverAgentTests/UnitTests/NSExpressionFBFormatTests.m index 67e6d14b6..e590dab2d 100644 --- a/WebDriverAgentTests/UnitTests/NSExpressionFBFormatTests.m +++ b/WebDriverAgentTests/UnitTests/NSExpressionFBFormatTests.m @@ -20,31 +20,36 @@ @implementation NSExpressionFBFormatTests - (void)testFormattingForExistingProperty { NSExpression *expr = [NSExpression expressionWithFormat:@"wdName"]; - XCTAssertNotNil([NSExpression fb_wdExpressionWithExpression:expr]); + NSExpression *prop = [NSExpression fb_wdExpressionWithExpression:expr]; + XCTAssertEqualObjects([prop keyPath], @"wdName"); } - (void)testFormattingForExistingPropertyShortcut { NSExpression *expr = [NSExpression expressionWithFormat:@"visible"]; - XCTAssertNotNil([NSExpression fb_wdExpressionWithExpression:expr]); + NSExpression *prop = [NSExpression fb_wdExpressionWithExpression:expr]; + XCTAssertEqualObjects([prop keyPath], @"isWDVisible"); } - (void)testFormattingForValidExpressionWOKeys { NSExpression *expr = [NSExpression expressionWithFormat:@"1"]; - XCTAssertNotNil([NSExpression fb_wdExpressionWithExpression:expr]); + NSExpression *prop = [NSExpression fb_wdExpressionWithExpression:expr]; + XCTAssertEqualObjects([prop constantValue], [NSNumber numberWithInt:1]); } - (void)testFormattingForExistingComplexProperty { NSExpression *expr = [NSExpression expressionWithFormat:@"wdRect.x"]; - XCTAssertNotNil([NSExpression fb_wdExpressionWithExpression:expr]); + NSExpression *prop = [NSExpression fb_wdExpressionWithExpression:expr]; + XCTAssertEqualObjects([prop keyPath], @"wdRect.x"); } - (void)testFormattingForExistingComplexPropertyWOPrefix { NSExpression *expr = [NSExpression expressionWithFormat:@"rect.x"]; - XCTAssertNotNil([NSExpression fb_wdExpressionWithExpression:expr]); + NSExpression *prop = [NSExpression fb_wdExpressionWithExpression:expr]; + XCTAssertEqualObjects([prop keyPath], @"wdRect.x"); } - (void)testFormattingForPredicateWithUnknownKey