Farhan Ahmed Wasim
Farhan Ahmed Wasim

Reputation: 949

How to use the function ` performTaskWithPathArgumentsTimeout` of the UIAutomation class?

I am automating some test cases for an iPhone app and I am using the UIAutomation class. I want to use the function performTaskWithPathArgumentsTimeout, which I believe runs some external script. But I cant use it. I have the following code:

#import "revision3.js"
#import "tuneup/tuneup.js"
test("script call", function(target, app){
var target = UIATarget.localTarget();
var host = target.host();
var result = host.performTaskWithPathArgumentsTimeout("fwasim/Desktop/registration.js, ["null"], 5);

UIALogger.logDebug("exitCode: " + result.exitCode);
UIALogger.logDebug("stdout: " + result.stdout);
UIALogger.logDebug("stderr: " + result.stderr);
});

The instrument console says:

Error: launch path not accessible.

I have searched on the internet but there seems to be very scarce resources on UIAutomation class and more specifically on the above function. Can anyone tell me what I am doing wrong?

Upvotes: 0

Views: 2584

Answers (1)

Jonathan Penn
Jonathan Penn

Reputation: 1341

The performTaskWithPathArgumentsTimeout() method on the host is for executing shell programs not JavaScript. That error message is telling you that it can't find an executable command at the path you gave.

Here's how you could execute a command with that method:

var result = host.performTaskWithPathArgumentsTimeout("/usr/bin/whoami", [], 5);

That executes the whoami command that lives in the /usr/bin directory. That command just prints out the logged in username which you can get at with result.stdout as you're already using.

I'm not quite sure what you're trying to do here, though. From the looks of the script you were trying to execute (fwasim/Desktop/registration.js), are you just trying to run some registration tests that are in a different file? If so, there's an easier way to do that. Just type this:

#import "fwasim/Desktop/registration.js"

That tries to import that JavaScript file as if it was relative to the directory of the script file that is running. You'd only need performTaskWithPathArgumentsTimeout() if you're trying to execute an external shell script or something like that. It's not for executing JavaScript inside UI Automation.

Upvotes: 4

Related Questions