diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rwxr-xr-x | scripts/check-system | 6 | ||||
-rwxr-xr-x | scripts/run-ui-tests (renamed from scripts/run-dogtail-tests) | 0 | ||||
-rw-r--r-- | tests/shell.py | 52 | ||||
-rw-r--r-- | tests/tree.py | 64 |
6 files changed, 92 insertions, 33 deletions
@@ -1,4 +1,5 @@ *~ +*.pyc install/ build/ source/ @@ -52,7 +52,7 @@ run: x11-utils $(SCRIPTS)/shell/start-sugar test: x11-utils - $(LOG) "$(SCRIPTS)/run-dogtail-tests" $(LOGFILE) + $(LOG) "$(SCRIPTS)/run-ui-tests" $(LOGFILE) shell: x11-utils @PS1="[sugar-build \W]$$ " \ diff --git a/scripts/check-system b/scripts/check-system index 72d4041..8b01945 100755 --- a/scripts/check-system +++ b/scripts/check-system @@ -329,10 +329,10 @@ checks = \ "checker": "binary", "packages": { "fedora": "dbus-x11", "ubuntu": "dbus-x11" } }, - { "check": "import dogtail", + { "check": "import pyatspi", "checker": "python", - "packages": { "fedora": "dogtail", - "ubuntu": "python-dogtail" } }, + "packages": { "fedora": "pyatspi", + "ubuntu": "python-pyatspi2" } }, # sugar-build buildtime diff --git a/scripts/run-dogtail-tests b/scripts/run-ui-tests index ddf126a..ddf126a 100755 --- a/scripts/run-dogtail-tests +++ b/scripts/run-ui-tests diff --git a/tests/shell.py b/tests/shell.py index ee190dd..034e316 100644 --- a/tests/shell.py +++ b/tests/shell.py @@ -1,21 +1,19 @@ import sys from time import sleep -from dogtail import tree -from dogtail import predicate -from dogtail import dump +import tree ACTIVITIES_WITH_OBJECT_CHOOSER = ["Read", "Jukebox"] ACTIVITIES_TO_IGNORE = ["Pippy"] def build_activities_list(): - shell = tree.root.child(name="sugar-session", roleName="application") + root = tree.get_root() + shell = root.find_child(name="sugar-session", role_name="application") activities = [] - table = shell.child(name="", roleName="table") - pred = predicate.GenericPredicate(roleName="table cell") - cells = table.findChildren(pred) + table = shell.find_child(role_name="table") + cells = table.find_children(role_name="table cell") for row in [cells[i:i+5] for i in range(0, len(cells), 5)]: activity_name = row[2].text @@ -27,11 +25,11 @@ def build_activities_list(): return activities def launch_and_stop_activity(activity_name): - shell = tree.root.child(name="sugar-session", roleName="application") + root = tree.get_root() + shell = root.find_child(name="sugar-session", role_name="application") - table = shell.child(name="", roleName="table") - pred = predicate.GenericPredicate(roleName="table cell") - cells = table.findChildren(pred) + table = shell.find_child(role_name="table") + cells = table.find_children(role_name="table cell") for row in [cells[i:i+5] for i in range(0, len(cells), 5)]: name = row[2].name @@ -47,26 +45,27 @@ def launch_and_stop_activity(activity_name): print "Stopping %s" % activity_name if activity_name in ACTIVITIES_WITH_OBJECT_CHOOSER: - close_button = shell.child(name="Close", - roleName="push button") - close_button.click() + close_button = shell.find_child(name="Close", + role_name="push button") + close_button.do_action("click") - activity = tree.root.child(name="sugar-activity", - roleName="application") + activity = root.find_child(name="sugar-activity", + role_name="application") - stop_button = activity.child(name="Stop", roleName="push button") - stop_button.click() + stop_button = activity.find_child(name="Stop", role_name="push button") + stop_button.do_action("click") def go_to_list_view(): - shell = tree.root.child(name="sugar-session", roleName="application") + root = tree.get_root() + shell = root.find_child(name="sugar-session", role_name="application") - done_button = shell.child(name="Done", roleName="push button") - done_button.click() + done_button = shell.find_child(name="Done", role_name="push button") + done_button.do_action("click") sleep(10) - radio_button = shell.child(name="List view", roleName="radio button") - radio_button.click() + radio_button = shell.find_child(name="List view", role_name="radio button") + radio_button.do_action("click") def main(): go_to_list_view() @@ -75,9 +74,4 @@ def main(): sleep(10) launch_and_stop_activity(activity) -try: - main() -except tree.SearchError: - print "\nDumping the accessible tree\n" - dump.plain(tree.root) - sys.exit(1) +main() diff --git a/tests/tree.py b/tests/tree.py new file mode 100644 index 0000000..e8746e2 --- /dev/null +++ b/tests/tree.py @@ -0,0 +1,64 @@ +import pyatspi + +def get_root(): + return Node(pyatspi.Registry.getDesktop(0)) + +class Node: + def __init__(self, accessible): + self._accessible = accessible + + def _predicate(self, accessible, name, role_name): + if name is not None and name != accessible.name: + return False + + if role_name is not None and role_name != accessible.getRoleName(): + return False + + return True + + def find_child(self, name=None, role_name=None): + def predicate(accessible): + return self._predicate(accessible, name, role_name) + + accessible = pyatspi.findDescendant(self._accessible, predicate) + + return Node(accessible) + + def find_children(self, name=None, role_name=None): + def predicate(accessible): + return self._predicate(accessible, name, role_name) + + all_accessibles = pyatspi.findAllDescendants(self._accessible, predicate) + + return [Node(accessible) for accessible in all_accessibles] + + def _dump_accessible(self, accessible, depth): + print "" * depth + str(accessible) + + def _crawl_accessible(self, accessible, depth): + self._dump_accessible(accessible, depth) + + for child in self.find_children(): + self._crawl_accessible(child, depth + 1) + + def dump(self): + self._crawl_accessible(self._accessible, 0) + + def do_action(self, name): + action = self._accessible.queryAction() + for i in range(action.nActions): + if action.getName(i) == name: + action.doAction(i) + + def click(self, button=1): + component = self._accessible.queryComponent() + x, y = component.getPosition(pyatspi.DESKTOP_COORDS) + pyatspi.Registry.generateMouseEvent(x, y, "b%sc" % button) + + @property + def name(self): + return self._accessible.name + + @property + def text(self): + return self._accessible.queryText().getText(0, -1) |