Skip to content

Commit

Permalink
Initial commit of PyATOM
Browse files Browse the repository at this point in the history
  • Loading branch information
jtatum committed Apr 30, 2011
0 parents commit 48c99da
Show file tree
Hide file tree
Showing 15 changed files with 4,538 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
*.py[co]
*.so

*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
MANIFEST
.installed.cfg

pip-log.txt

339 changes: 339 additions & 0 deletions COPYING.txt

Large diffs are not rendered by default.

105 changes: 105 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
=======================================
PyATOM - Automated Testing on Macintosh
=======================================
Introduction
============
We are pleased to introduce the first Python library to fully enable GUI testing of Macintosh applications via the Apple Accessibility API. This library was created out of desperation. Existing tools such as using appscript to send messages to accessibility objects are painful to write and slow to use. PyATOM has direct access to the API. It's fast and easy to use to write tests.

Getting started
===============
PyATOM requires a system running OS X and Xcode installed. It has been tested extensively on 10.6. 10.5 may work. If you experience issues with PyATOM on a particular version of OS X, please open a ticket in the issue tracker.

Systemwide accessibility must be enabled. Check the checkbox: System Preferences > Universal Access > Enable access for assistive devices. Failure to enable this will result in ErrorAPIDisabled exceptions during some module usage.

Installation should be as simple as running the following command line, which will download, build and install PyATOM::

$ sudo easy_install atom

Usage
=====
Once the pyatom module is installed, you should be able to use it to launch an application::

>>> import pyatom
>>> pyatom.launchAppByBundleId('com.apple.Automator')

This should launch Automator. Next, get a reference to the UI Element for the application itself::

>>> automator = pyatom.getAppRefByBundleId('com.apple.Automator')
>>> automator
<pyatom.AXClasses.NativeUIElement AXApplication u'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. PyATOM supports reading and writing of most attributes. Using 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 - PyATOM 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 PyATOM search methods::

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

PyATOM has a method 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.

Todo and contributing
=====================
Although PyATOM is fully functional and drives hundreds of automated test cases at VMware, we have a to-do list to make the project even better.

* Documentation - The docstrings need to be better sphynxified, and the basic doc layout needs to be created.
* Formatting - this code is not currently PEP-8 compliant.
* Better mouse handling - for example, a method to smoothly drag from one UI Element to another.
* Cleanup the search methods - We could use currying to define all the search methods in AXClasses in a cleaner way.

Feel free to submit pull requests against the project on Github. If you're interested in developing PyATOM itself, sign up to the pyatom-dev mailing list.

See also
========
* The PyATOM `home page`_
* `Mailing lists`_
* `Source code`_ on Github
* `Issue tracker`_

.. _`home page`: http://pyatom.com
.. _`mailing lists`: http://lists.pyatom.com
.. _`source code`: https://github.com/pyatom/pyatom
.. _`issue tracker`: https://github.com/pyatom/pyatom/issues

License
=======

PyATOM is released under the GNU General Public License. See COPYING.txt for more details.

Authors
=======

James Tatum <[email protected]>,
Andrew Wu,
Jesse Mendonca,
Ken Song
33 changes: 33 additions & 0 deletions pyatom/AXCallbacks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (c) 2010 VMware, Inc. All Rights Reserved.

# This file is part of PyATOM.

# PyATOM is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the Free
# Software Foundation version 2 and no later version.

# PyATOM is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License version 2
# for more details.

# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
# St, Fifth Floor, Boston, MA 02110-1301 USA.

def elemDisappearedCallback(retelem, obj, **kwargs):
''' Callback for checking if a UI element is no longer onscreen
kwargs should contains some unique set of identifier (e.g. title /
value, role)
Returns: Boolean
'''
return (not obj.findFirstR(**kwargs))


def returnElemCallback(retelem):
''' Callback for when a sheet appears
Returns: element returned by observer callback
'''
return retelem
Loading

0 comments on commit 48c99da

Please sign in to comment.