-
-
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 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…selenium driver.execute_script()
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -574,6 +574,31 @@ -(void) closeWindow | |
[self.currentWindow performAction:@"AXCancel"]; | ||
} | ||
|
||
- (NSString *)runCommand:(NSString *)commandToRun | ||
{ | ||
NSTask *task = [[NSTask alloc] init]; | ||
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. I assume NSTask starts with an empty environment by default. Shouldn't we inherit the current system env by default? |
||
[task setLaunchPath:@"/bin/sh"]; | ||
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. Are you sure 'sh' will run bash? Why not use /bin/bash to be explicit ? |
||
|
||
NSArray *arguments = [NSArray arrayWithObjects: | ||
@"-c" , | ||
[NSString stringWithFormat:@"%@", commandToRun], | ||
nil]; | ||
NSLog(@"run command:%@", commandToRun); | ||
[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,19 @@ - (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) | ||
{ | ||
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. Not sure if the indentation is from github, but please ensure "return" and the block are aligned. |
||
// The bash command to run | ||
NSString *command = (NSString*)[commandParams objectForKey:@"script"]; | ||
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. Rename to 'script' or 'scriptString', or something else besides 'command'. In this context, command refers to the web driver command itself. |
||
|
||
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. If you can, please support the full "execute" command by allowing shell script arguments passed in through the 'args' commandParam. That will allow the same scriptString to have different behaviors without having to rebuild the string in your client script. |
||
NSString *commandResult = [session runCommand:command]; | ||
|
||
return [AppiumMacHTTPJSONResponse responseWithJson:commandResult 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.
Please use a name like executeShellScript:(NSString *)script. It is more specific, and derived from the "post_execute" web driver command name.