0

Similar issues without resolution: Run applescript using java on selenium webdriver(Grid) in sauce lab

I need to click to enable touchID on the Hardware dropdown menu on iPhone simulator with appleScript. I have the following piece of code that works perfectly fine (after I grant Eclipse permission to control my computer) but when I run this on saucelabs I get the following error:

java.io.IOException: Cannot run program "osascript": error=2, No such file or directory
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)

Here is my code:

 protected void enableTouchIDLogin(){
   try
   {
       String appleScriptCommand =   "tell application \"System Events\" to tell process \"Simulator\"\n" +
                       "click menu item \"Touch ID Enrolled\" of menu 1 of menu bar item \"Hardware\" of menu bar 1\n"+
                       "end tell";

       runAppleScript(appleScriptCommand);
   }
   catch (Exception e)
   {
       e.printStackTrace();
   }
}

 protected void runAppleScript(String appleScriptCommand) throws IOException{

  Runtime runtime = Runtime.getRuntime();

  String[] args = { "osascript", "-e", appleScriptCommand};
  try
  {
    Process process = runtime.exec(args);
  }
  catch (Exception e)
  {
    e.printStackTrace();
  }

};
Community
  • 1
  • 1
es3735746
  • 841
  • 3
  • 16
  • 40

1 Answers1

0
Runtime runtime = Runtime.getRuntime();

This line would get you the runtime on the test host not the remote machine therefore it'll not work on the remote machine. What you need to do is run your apple script on the remote machine somehow. Appium currently does not support it, neither does the WebDriver API.

https://support.saucelabs.com/customer/en/portal/articles/2135183-guide-to-pre-run-executables

mehmetg
  • 197
  • 1
  • 4
  • 16