3

I have a script like so:

var target = UIATarget.localTarget();
var mainWindow = target.frontMostApp().mainWindow();

var element = mainWindow.textFields()["UserID"];
element.setValue("Hello World");

UIALogger.logStart("Logging element tree ...");
target.logElementTree();
UIALogger.logPass();

What I want to do is read a text file or database connection, so I can replace the "Hello World" with either a value from a text file or a database query. Is this possible in the Instruments application with using javascript to control UI Automation for the iphone simulator?

Nick Turner
  • 927
  • 1
  • 11
  • 21
  • I am able to create javascript arrays in another file and import that file, but i'd much rather read an xml file, connect to a web service, or query a database. – Nick Turner Sep 25 '13 at 18:55

1 Answers1

3

Yes it is possible. You can acquire every data that you are able to acquire in a bash script. Write a script file that prints the desired information to the standard output. For example

#!/bin/bash
cat myfile

You can run this bash-script from UIAutomation and get the output of it with this command

var result = target.host().performTaskWithPathArgumentsTimeout(full_path_to_your_script, [""], 10);

Now your can use the output of your bash script:

element.setValue(result.stdout);
fabe
  • 718
  • 5
  • 10
  • can I do this for an imageview control also and set it with the output of a png file? – Nick Turner Sep 26 '13 at 14:34
  • 1
    @NickTurner, I have a similar requirement to read data from another file. how to write a script file to execute this statement in terminal? 'cat myfile' – coder284 Nov 20 '13 at 11:28
  • @NickTurner You can always have your host-side script return json - and that means you can encode anything you want, including image data (just do something like base64-encoded values) – James Moore Dec 02 '14 at 21:34
  • @fabe can we write data from instruments to a file and save it on the disk ?? – Prabhu Konchada Jul 04 '15 at 12:01
  • 1
    @PrabhuKonchada you can. You just need to write a bash script that will write to a file. Something like echo $1 >> file.json – Braains Jul 24 '15 at 15:25