Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/shell.py
blob: 9e3d8b47ef814f81dde4646d0438775f95a0f8d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import sys
from operator import attrgetter

from dogtail import tree
from dogtail import predicate
from dogtail import dump

ACTIVITIES_WITH_OBJECT_CHOOSER = ["Read", "Image Viewer", "Jukebox"]

class ActivityLauncher:
    def __init__(self, name=None, icon=None):
        self.name = name
        self.icon = icon

def get_activity_launchers(shell):
    # Make a list of activities by iterating the table
    activity_launchers = []

    table = shell.child(name="", roleName="table")
    pred = predicate.GenericPredicate(roleName="table cell")
    cells = table.findChildren(pred)

    for row in [cells[i:i+5] for i in range(0, len(cells), 5)]:
        launcher = ActivityLauncher(name=row[2].text, icon=row[1])
        activity_launchers.append(launcher)

    activity_launchers.sort(key=attrgetter("name"))

    return activity_launchers

def launch_and_stop_activity(activity_launcher):
    print "Launching %s" % activity_launcher.name 

    activity_launcher.icon.click()

    if activity_launcher.name in ACTIVITIES_WITH_OBJECT_CHOOSER:
        close_button = shell.child(name="Close", roleName="push button")
        close_button.click()

    activity = tree.root.child(name="sugar-activity", roleName="application")

    stop_button = activity.child(name="Stop", roleName="push button")
    stop_button.click()

def main():
    shell = tree.root.child(name="sugar-session", roleName="application")

    # Complete the intro screen
    done_button = shell.child(name="Done", roleName="push button")
    done_button.click()

    # Switch to the home list view
    radio_button = shell.child(name="List view", roleName="radio button")
    radio_button.click()

    # Launch and close all the activities
    for activity_launcher in get_activity_launchers(shell):
        if activity_launcher.name in ["Pippy", "Write"]:
            continue

        launch_and_stop_activity(activity_launcher)

try:
    main()
except tree.SearchError:
    print "\nDumping the accessible tree\n"
    dump.plain(tree.root)
    sys.exit(1)