1

使用 Apple 的 UI 自动化,我已经成功地通过 bash 脚本构建和执行我的测试脚本。我正在尝试对需要将 sqlite 文件中的数据与应用程序中显示的数据进行比较的应用程序进行自动化测试。

我编写了一个 python 脚本,它将 sqlite 数据作为 javascript 变量保存在一个名为 settings.js 的文件中。使用performTaskWithPathArgumentsTimeout,我可以执行这个脚本来创建 settings.js 文件:

var target = UIATarget.localTarget();
var host = target.host();
var result = host.performTaskWithPathArgumentsTimeout("/usr/bin/python",["/Users/Matt/Code/automation/DBData/UIAsettingsKVDump.py", "/Users/Matt/Code/automation/DBData/settings.sqlite"],20);

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

#import "./../DBData/settings.js"

这成功地创建了 settings.js 文件。但是,当我尝试像上面那样导入 settings.js 文件时,在将三个 logDebug 消息输出到控制台之前,我收到“未找到导入文件(null)”错误 - 这让我相信 #import 已完成在脚本执行之前。

如何确保在执行 #import 之前创建了我的 settings.js 文件?

4

1 回答 1

1

There's no documentation about this, but from my experience Apple is preprocessing the JavaScript files and performing the imports at script parsing time before the script is evaluated. I think this happens because the #import statement isn't part of of the JS language.

Rather than try to import the JavaScript file, what if you just had your Python script print the settings JavaScript to standard out. That way you can get that output from the result returned from performTaskWithPathArgumentsTimeout and use eval() to convert it into a JavaScript result. That may be finicky and you're certainly going to have trouble debugging it, but that might be the quickest way to get what you want.

于 2013-06-07T05:02:16.393 回答