Created
April 4, 2014 16:49
-
-
Save TeresaP/9978566 to your computer and use it in GitHub Desktop.
Example for storing Calabash Backdoor functions outside of the Application Delegate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface CalabashBackdoor : NSObject | |
+(NSString *) backdoorMethodName:(NSString *)string; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation CalabashBackdoor | |
// One of the Backdoor methods | |
+ (NSString *) backdoorMethodName:(NSString *)string | |
{ | |
return @"Result"; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
backdoor('calabashBackdoor','backdoorMethodName') | |
backdoor('calabashBackdoor','backdoorMethodName:') | |
backdoor('calabashBackdoor','backdoorMethodName:parameterValue') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Calabash Automation Methods Proxy | |
-(id *)calabashBackdoor:(NSString *)string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Calls the corresponding method inside the CalabashBackdoor | |
// Syntax from Ruby Code: | |
// backdoor('calabashBackdoor','functionName:parameter') | |
// backdoor('calabashBackdoor','functionName') | |
// backdoor('calabashBackdoor','functionName:') | |
// This will call the functionName function and pass in the desired parameter, if it exists | |
- (id *)calabashBackdoor:(NSString *)string | |
{ | |
// Break string into a function name and its parameter (if it exists) | |
NSArray *userInput = [string componentsSeparatedByString: @":"]; | |
// Method above removes : but the method name must have it, so put it back on the end | |
NSString *methodToCall = [NSString stringWithFormat:@"%@:", userInput[0]]; | |
if (userInput.count > 1 && [[CalabashBackdoor class] respondsToSelector:(NSSelectorFromString(methodToCall))]) | |
{ | |
return (id *)[[CalabashBackdoor class] performSelector: NSSelectorFromString(methodToCall) withObject:userInput[1]]; | |
} | |
else if (userInput.count == 1 && [[CalabashBackdoor class] respondsToSelector:(NSSelectorFromString(methodToCall))]) | |
{ | |
return (id *)[[CalabashBackdoor class] performSelector: NSSelectorFromString(methodToCall)]; | |
} | |
else | |
{ | |
NSString *detailsStr = [NSString stringWithFormat:@"You must define the method (selector) '%@' in CalabashBackdoor.\n", | |
methodToCall]; | |
NSString *usage0 = [NSString stringWithFormat:@"backdoor('calabashBackdoor','%@')", | |
methodToCall]; | |
NSString *usage1 = [NSString stringWithFormat:@"backdoor('calabashBackdoor','%@<arg>')", | |
methodToCall]; | |
NSString *reasonStr = [NSString stringWithFormat:@"The application delegate does not respond to selector '%@'.", | |
methodToCall]; | |
return (id*) [NSDictionary dictionaryWithObjectsAndKeys: | |
@"FAILURE", @"Outcome", | |
reasonStr, @"Reason for Error", | |
detailsStr, @"Details", | |
usage0, @"Usage for method without a parameter", | |
usage1, @"Usage for method with a parameter", | |
nil]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
isn't better to have the calabash backdoor defined in a category of the app delegate, and add this category only to the calabash target?