从仪器javascript脚本中的数据库或文本文件中读取数据

我有一个这样的脚本:

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(); 

我想要做的是读取文本文件或数据库连接,因此我可以用文本文件中的值或数据库查询替换“Hello World”。 这是否可以在Instruments应用程序中使用javascript来控制iphone模拟器的UI自动化?

对的,这是可能的。 您可以在bash脚本中获取能够获取的每个数据。 编写一个脚本文件,将所需信息打印到标准输出。 例如

 #!/bin/bash cat myfile 

您可以从UIAutomation运行此bash脚本,并使用此命令获取它的输出

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

现在您可以使用bash脚本的输出:

 element.setValue(result.stdout);