-
-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds the ability to run bash script through appium-for-mac #30
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -574,6 +574,32 @@ -(void) closeWindow | |
[self.currentWindow performAction:@"AXCancel"]; | ||
} | ||
|
||
- (NSString *)executeShellScript:(NSString *)script | ||
{ | ||
NSTask *task = [[NSTask alloc] init]; | ||
[task setLaunchPath:@"/bin/bash"]; | ||
|
||
NSArray *arguments = [NSArray arrayWithObjects: | ||
@"-c" , | ||
[NSString stringWithFormat:@"%@", script], | ||
nil]; | ||
|
||
NSLog(@"running bash script:'%@'", script); | ||
[task setArguments:arguments]; | ||
|
||
NSPipe *pipe = [NSPipe pipe]; | ||
[task setStandardOutput:pipe]; | ||
|
||
NSFileHandle *file = [pipe fileHandleForReading]; | ||
|
||
[task launch]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The launch method is deprecated. Please use only supported APIs. |
||
|
||
NSData *data = [file readDataToEndOfFile]; | ||
|
||
NSString *output = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; | ||
return output; | ||
} | ||
|
||
-(NSString*) currentApplicationName | ||
{ | ||
return self._currentApplicationName; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,6 +240,17 @@ - (AppiumMacHTTPJSONResponse *)post_url:(NSString*)path data:(NSData*)postData | |
// POST /session/:sessionId/execute | ||
// Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. The executed script is assumed to be synchronous and the result of evaluating the script is returned to the client. | ||
|
||
- (AppiumMacHTTPJSONResponse *)post_execute:(NSString*)path data:(NSData*)postData | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it should be also possible to pass additional environment variables |
||
{ | ||
return [self executeWebDriverCommandWithPath:path data:postData onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode) | ||
{ | ||
// The bash script to run | ||
NSString *script = (NSString*)[commandParams objectForKey:@"script"]; | ||
NSString *scriptResult = [session executeShellScript: script]; | ||
return [AppiumMacHTTPJSONResponse responseWithJson:scriptResult status:kAfMStatusCodeSuccess session:session.sessionId]; | ||
}]; | ||
} | ||
|
||
// POST /session/:sessionId/execute_async | ||
// Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. The executed script is assumed to be asynchronous and must signal that is done by invoking the provided callback, which is always provided as the final argument to the function. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume NSTask starts with an empty environment by default. Shouldn't we inherit the current system env by default?