0

Please help!!! I am trying to add some performtaskwithpathargumentstimeout functions to my ios UI automation javascript. Specifically I am submitting a form within the app and subsequently want to check that it has been submitted successfully. However I am having problems.

I want to do several things. The ideal was to do a curl request to a url, and then search the stdout body that comes back to ensure that several keywords were there. However, instruments keeps crashing when I try and use any indexOf or .search functions on the result.stdout...

I thought another option would be to output the html to a file, and then search that file by writing a command line application which will search for the keyword passed as an argument. However, when I try and output the file to a directory using the following-

var target = UIATarget.localTarget();

var host = target.host();

result = target.host().performTaskWithPathArgumentsTimeout("usr/bin/curl", ["-o /Users/andrewweaver/Documents/output.html", "http://www.google.co.uk"], 30);

UIALogger.logDebug("exitCode: " + result.exitCode);

UIALogger.logDebug("stdout: " + result.stdout);

UIALogger.logDebug("stderr: " + result.stderr);

I get the following error-

Warning: Failed to create the file /Users/me/Documents/output.html: \nWarning: No such file or directory

This directory DOES exist, and has permissions for anyone to read & write to it.... also, if I create the .html file in that directory the same thing happens. If I run the same command from terminal it works fine...

I also wanted to do a write out of the http code...

result = target.host().performTaskWithPathArgumentsTimeout("usr/bin/curl", ["--write-out %{http_code}", "http://www.google.co.uk"], 30);

But again, that is failing....

curl: option --write-out %{http_code}: is unknown

I'm not sure what I'm doing wrong....

Any help would be much appreciated : - )

Unheilig
  • 16,196
  • 193
  • 68
  • 98

1 Answers1

0

Fixed it. Each of the args passed into performTaskWithPathArgumentsTimeout needs to be separated by "" and a ,

So, for example to query a website and write the output to a file...

var host = target.host();

var result = target.host().performTaskWithPathArgumentsTimeout("usr/bin/curl", ["-o", "/Users/me/Documents/football.html", "http://www.bbc.co.uk/"], 30);

UIALogger.logDebug("exitCode: " + result.exitCode);

UIALogger.logDebug("stdout: " + result.stdout);

And then to search the outputted file for a particular element I use grep...

var str = "BBC Sport - Football";

var result = target.host().performTaskWithPathArgumentsTimeout("usr/bin/grep", ["-w", (str), "/Users/me/Documents/football.html"], 15);

UIALogger.logDebug("exitCode: " + result.exitCode);

UIALogger.logDebug("stdout: " + result.stdout);

This will return a 0 if the regex is found, and BBC Sport - Football as the stdout.

I can then use an if statement to pass or fail (or use a tuneup js assert) based on whether the expected expression is present...

Useful for sending requests to webservices and then verifying the content...