4

I use UIAutomation to automate an iPad application. I have tried to use (object) performTaskWithPathArgumentsTimeout(path, args, timeout) to run Safari.app from my script:

var target = UIATarget.localTarget();
var host = target.host();
var result = host.performTaskWithPathArgumentsTimeout("/Applications/Safari.app", ["http://www.google.com"], 30);
UIALogger.logDebug("exitCode: " + result.exitCode);
UIALogger.logDebug("stdout: " + result.stdout);
UIALogger.logDebug("stderr: " + result.stderr);

I got the following results: exitCode: 5 stdout: stderr:

I’ve also tried to launch echo:

var target = UIATarget.localTarget();
var host = target.host();
var result = host.performTaskWithPathArgumentsTimeout("/bin/echo", ["Hello
World"], 5);
UIALogger.logDebug("exitCode: " + result.exitCode);
UIALogger.logDebug("stdout: " + result.stdout);
UIALogger.logDebug("stderr: " + result.stderr);

Results: exitCode: 0 stdout: Hello World stderr:

So, looks like performTaskWithPathArgumentsTimeout works for specific applications only.

Could you please help me to answer the following questions: 1. What does exitCode = 5 mean? 2. Which processes can be launched using performTaskWithPathArgumentsTimeout function?

ele
  • 41
  • 2

1 Answers1

4

1) Exit code 5 is most likely EIO, as defined in : Input/Output error. You're attempting to execute "/Applications/Safari.app", which to the launching task is a directory and not a binary.

2) You can launch any application with performTaskWithPathArgumentsTimeout() that NSTask can launch. As long as it's a valid executable, it should work.

For your specific example though, Safari won't accept an argument passed on the command line like that as a URL to visit. You need to use open /Applications/Safari.app "http://www.google.com" instead:

var result = host.performTaskWithPathArgumentsTimeout("/usr/bin/open", ["/Applications/Safari.app", "http://www.google.com"], 30);
MyztikJenz
  • 1,650
  • 14
  • 19