Skip to main content

atomacos: Automated Testing on macOS

license pypi Build Status codecov style

This library is a fork of atomac. It was created to provide a release with python 3 support because there has not been a release since 2013

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.

Getting started

Requirements

  • macOS
  • pyobjc
  • 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.

Installing

For release

$ pip install atomacos

For pre-release

$ pip install --pre atomacos

Usage Examples

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()[0]
>>> window.AXTitle
u'Untitled'
>>> sheet = window.sheets()[0]

Note that we retrieved an accessibility attribute from the Window object - AXTitle. Atomacos supports reading and writing of most attributes. Xcode's included 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()[0]

There are search methods for most types of accessibility objects. Each search method, such as windows, has a corresponding recursive search function, such as windowsR.

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. Note that * and ? can be used as wildcard match characters in all search methods:

>>> close = sheet.buttons('Close')[0]

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')

findFirst and findFirstR return the first item found to match the criteria or None. findAll and 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:

>>> close.Press()

Any action can be triggered this way.

Links

Release files for atomacos 3.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for atomacos 3.3.0
File Size Uploaded
atomacos-3.3.0.tar.gz 35.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for atomacos 3.3.0
File Interpreter ABI Platform
atomacos-3.3.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 61.8 kB

Release files / atomacos-3.3.0.tar.gz

Download URL atomacos-3.3.0.tar.gz
Size 35.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1733fc541512bd5b05e924b340717053001210f38b286dbf30cf5acb3a52689c
BLAKE2b-256 checksum
How to use checksums
7197ad8e7c041b82ad6851ba857509511b201cbfdc6c6164c70ddd098547a3d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.25.1

Release files / atomacos-3.3.0-py2.py3-none-any.whl

Download URL atomacos-3.3.0-py2.py3-none-any.whl
Size 26.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
58c01c66384f58606868e6f2be977ab64b56bccbdab3300a0b139c9d10691c46
BLAKE2b-256 checksum
How to use checksums
ec04ea63b7592ba6facb3fc09a0545774d268f95fe2b624bf1513159bba14d75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.25.1
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page