Skip to main content

Automated Testing on macOS

Project description

mac-ui-automation: Automated Testing on macOS

license pypi Build Status codecov style

This library is a fork of [atomacos]. 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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

macuiauto-3.2.0.tar.gz (29.1 kB view details)

Uploaded Source

Built Distribution

macuiauto-3.2.0-py2.py3-none-any.whl (25.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file macuiauto-3.2.0.tar.gz.

File metadata

  • Download URL: macuiauto-3.2.0.tar.gz
  • Upload date:
  • Size: 29.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for macuiauto-3.2.0.tar.gz
Algorithm Hash digest
SHA256 8ce61c751c1c7170a33a95f600708b8827885abc1a8e058a047489148e9998ee
MD5 a5be6543be58fe7fa1164a4443f223fd
BLAKE2b-256 0cb86e198c21c877241ed64feba9e0207cb2d4c29257cad451d469e697c23a6d

See more details on using hashes here.

File details

Details for the file macuiauto-3.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: macuiauto-3.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 25.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for macuiauto-3.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8213ac5b226e87f3821f270684c9675899e3f858eec2d69bf1ecb40ace4fb09f
MD5 f18fbac26c403c1e47a7cc05612f1eb7
BLAKE2b-256 d06f65464e4ca607cde1c0a5f782b7a267cd7ab8e63974ce88b9f5752d927a3b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page