问题
Over the last few days I've been playing with Apple's UIAutomation framework in an attempt to try to put together a suite of acceptance tests to drive the development of an app I'm working on (in a BDD type way...).
One thing I'm bumping up against is how to get the SUT into a given state so I can begin my tests if I need to set some internal state for that to happen. The problem is that Apple's Javascript environment doesn't provide any functionality I could use to communicate with the device other than through it's UI (I'm sure this is probably by design but sometimes this is just impractical): whilst solutions like iCuke or Frank can use HTTP to communicate with an listening server embedded in the target app for the purposes of such communication, there is is no way to do anything like this within the Instrument's UIAutomation environment.
Looking at the API's provided I noticed that there is a function on the UIAApplication class which allows me to set a preference value on the target device (see here for more details): it occurred to me that I could install some code on the device that could use KVO to watch for a chance to a given preference key, and then I could use this as a means for communicating with some special test-specific helper code in the target application (reacting when the value of the preference is changed).
I began playing around to see if I could make this work, but ran up against a brick wall in that I cannot find a way to access the preferences that are set by UIAutomation from within the target app. The issue is that the preferences seem to be set at the host domain level (that is they are set in the file /Library/Preferences/com.mycompany.MyApp
) and not in the sandboxed /Library
folder specific to my application.
I know for sure that the preferences I set are hitting the device - I can see the value changing in the aforementioned file, but I cannot find a way to access these values using NSUserDefaults.
Can anyone shed any light on how I am supposed to access the preferences stored at this level (NSLocalDomain...) on an iOS device?
NB: I realise this is a total hack but unfortunately the environment Apple provides right now seems to fall woefully short of the mark so I'm trying my best to fill in the gaps in lieu of further updates from Apple. If you search the web you'll see that other people have had very similar experiences and have tried to work around the current deficiencies in similar ways.
Update: there is the possibility this is a bug according to this thread. I'm unable to confirm this for sure though..
回答1:
I also have similar issue post here.
The way I use automate test to run through my application is just to run it in actual iOS device (iPhone to be specific). However, I also found that function like deactivate in UIA script won't work on real device. For some reason the automation can't find the application button and reenter the application.
Hope this help!
来源:https://stackoverflow.com/questions/4977673/reading-preferences-set-by-uiautomations-uiaapplication-setpreferencesvaluefork