Search code examples
instrumentsios-ui-automationxcode-instruments

How to access model objects in iOS automation scripts?


Accessing UI components through Instruments for testing automation can be done by turning on accessibility and giving them a label but what about getting our hands on the properties or variables that represent the data model ... how can that be accomplished in the script?


Solution

  • This is not possible and not recommended. If you want to test the internal data model state of the application, that is best done with lower level tests written with Xcode's unit testing framework. UI Automation is strictly for testing things "as the user sees them" and no mechanism is given to delve deeper into the app.

    Of course, if you want to expose things in the app to the outside, you could. Look up UIAHost for how to run shell scripts from within a test, for example. I've also used off-screen views in development builds that expose extra information that the user doesn't see but UI Automation can pick up.

    But again, this is not UI Automation's purpose and you'd be fighting against the tool.