Reputation: 53
Using Apple's UI Automation, I have been successful in building and executing my test scripts through a bash script. I'm trying to automate testing for an app that requires comparing data in a sqlite file with data shown in the app.
I've written a python script which saves the sqlite data as javascript variables in a file called settings.js. Using performTaskWithPathArgumentsTimeout, I can execute this script to create the settings.js file:
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"
This successfully creates the settings.js file. However, when I try to import the settings.js file like above, I get an "Import file not found(null)" error before the three logDebug messages are output onto the console -this leads me to believe that the #import is done before the script is executed.
What can I do to make sure my settings.js file is created before the #import is performed?
Upvotes: 1
Views: 573
Reputation: 1341
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.
Upvotes: 1