diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/shell.py | 52 | ||||
-rw-r--r-- | tests/tree.py | 64 |
2 files changed, 87 insertions, 29 deletions
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) |