Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Automated Testing on macOS

License

NotificationsYou must be signed in to change notification settings

OpenAdaptAI/atomacos

 
 

Repository files navigation

licensepypiBuild Statuscodecovstyle

This library is a fork ofatomac.It was created to provide a release with python 3 support becausethere has not been a releasesince 2013

Atomacos is a library to enable GUI testing of macOS applications via the Apple Accessibility API.Atomacos has direct access to the API viapyobjc. 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 theissue tracker.

Enabling Systemwide Accessibility

Check the checkbox:

System Preferences > Universal Access > Enable access for assistive devicesSystem Preferences > Security & Privacy > Privacy > Accessibility

Failure to enable this will result inAXErrorAPIDisabled 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:

>>>importatomacos>>>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.NativeUIElementAXApplicationAutomator>

Now, we can find objects in the accessibility hierarchy:

>>>window=automator.windows()[0]>>>window.AXTitleu'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 includedAccessibility Inspector can provide a quick way to find these attributes.

There is a shortcut for getting the sheet object whichbypasses 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 aswindows,has a corresponding recursive search function, such aswindowsR.

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 andfindFirstR return the first item found to match the criteria orNone.findAll andfindAllR 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.AXTitleu'Close'>>>close.getActions()[u'Press']

Performing an action is as natural as:

>>>close.Press()

Any action can be triggered this way.

Links

Packages

No packages published

Languages

  • Python99.1%
  • Shell0.9%

[8]ページ先頭

©2009-2025 Movatter.jp