Automated Testing on macOS
atomacos: Automated Testing on macOS
Atomacos is a library to enable GUI testing of macOS applications via the Apple Accessibility API. Atomacos has direct access to the API via pyobjc. It's fast and easy to use to write tests.
- Systemwide Accesibility enabled
On travis, it's only on 10.11 because we are able to enable accessibility API.
If you experience issues, please open a ticket in the issue tracker.
Enabling Systemwide Accessibility
Check the checkbox:
System Preferences > Universal Access > Enable access for assistive devices System Preferences > Security & Privacy > Privacy > Accessibility
Failure to enable this will result in
AXErrorAPIDisabled exceptions during some module usage.
$ pip install atomacos
$ pip install --pre atomacos
Once installed, you should be able to use it to launch an application:
>>> import atomacos >>> atomacos.launchAppByBundleId('com.apple.Automator')
This should launch Automator.
Next, get a reference to the UI Element for the application itself:
>>> automator = atomacos.getAppRefByBundleId('com.apple.Automator') >>> automator <atomacos.AXClasses.NativeUIElement AXApplication Automator>
Now, we can find objects in the accessibility hierarchy:
>>> window = automator.windows() >>> window.AXTitle u'Untitled' >>> sheet = window.sheets()
Note that we retrieved an accessibility attribute from the Window object -
Atomacos supports reading and writing of most attributes.
Accessibility Inspector can provide a quick way to find these attributes.
There is a shortcut for getting the sheet object which bypasses accessing it through the Window object. Atomacos can search all objects in the hierarchy:
>>> sheet = automator.sheetsR()
There are search methods for most types of accessibility objects.
Each search method, such as
has a corresponding recursive search function, such as
The recursive search finds items that aren't just direct children, but children of children.
These search methods can be given terms to identify specific elements.
? can be used as wildcard match characters in all search methods:
>>> close = sheet.buttons('Close')
There are methods to search for UI Elements that match any number of criteria. The criteria are accessibility attributes:
>>> close = sheet.findFirst(AXRole='AXButton', AXTitle='Close')
findFirstR return the first item found to match the criteria or
findAllR return a list of all items that match the criteria or an empty list(
Objects are fairly versatile. You can get a list of supported attributes and actions on an object:
>>> close.getAttributes() [u'AXRole', u'AXRoleDescription', u'AXHelp', u'AXEnabled', u'AXFocused', u'AXParent', u'AXWindow', u'AXTopLevelUIElement', u'AXPosition', u'AXSize', u'AXTitle'] >>> close.AXTitle u'Close' >>> close.getActions() [u'Press']
Performing an action is as natural as:
Any action can be triggered this way.
Release history Release notifications
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size atomacos-3.2.0-py2.py3-none-any.whl (82.5 kB)||File type Wheel||Python version py2.py3||Upload date||Hashes View hashes|
|Filename, size atomacos-3.2.0.tar.gz (34.7 kB)||File type Source||Python version None||Upload date||Hashes View hashes|
Hashes for atomacos-3.2.0-py2.py3-none-any.whl