从 Instruments JavaScript 脚本中的数据库或文本文件中读取数据

read data from a database or text file in instruments javascript script

本文关键字:文本 文件 读取 数据 Instruments JavaScript 脚本 数据库      更新时间:2023-09-26

我有一个这样的脚本:

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"替换为文本文件或数据库查询中的值。这在仪器应用程序中是否可能使用javascript来控制iPhone模拟器的UI Automation?

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

#!/bin/bash
cat myfile

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

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

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

element.setValue(result.stdout);