IntroductionSugarbot is a conglomeration of clever Python programming and XML-RPC. There main components to sugarbot are: - Script server (XML-RPC)
- Activity emulation
- GTK hooking and widget identification
- Script execution engine
Script ServerThe script server is very simple. It is provided with a list of Python files (specified on the command-line), and then serves those files' contents over XML-RPC (as well as some other data scraped from the files) to the sugarbot clients. The server supports multiple concurrent sessions, as would be expected, so all of the clients can connect to a single XML-RPC server. The XML-RPC server also provides future capabilities to extend error reporting, as it is made aware of all of the success/failures of the client script execution. Activity EmulationIn order to test an Activity, it has to be instantiated. In the Sugar/OLPC environment, this is less easy than it would originally seem. However, due to dynamic typing and nifty run-time inheritance changes, the entire activity is emulated, and operates exactly as it would normally operate. GTK Hooks and Widget IdentificationBefore the GUI can be manipulated, all of the GUI widgets not only have to be identified, but they must be assigned meaningful identifiers. By hooking into the core of GTK, we can build a database of all of the instantiated widgets. Using the base gtk.Widget class, developers can specify names for each of the Widgets. Alternatively, sugarbot attempts to create proper names for un-named widgets by using various means, allowing developers to quickly start writing tests without having to make large changes to the existing code-base. Script execution engineThe script execution engine takes all of the information gathered by the GTK hooks and Widget identification, and then passes that information to a script. In addition to providing convenience accessors, the script has full access to the actual gtk.Widget objects, and can perform any custom manipulation needed. The scripts used by sugarbot are all native Python code, so it is not necessary to learn any new syntax. The only unique property of the scripts are that they must define a global variable, define a specific function for execution. Example script: import time
import logging
sugarActivityName = 'Calculate'
def sugarbot_main(widgets):
# Test 'selected' functionality.
assert widgets['Share with:'].selected == "Private"
widgets['Share with:'].selected = "My Neighborhood"
assert widgets['Share with:'].selected == "My Neighborhood"
# Test widget fetching/assignment
one = widgets['1']
plus = widgets['+']
enter = widgets['enter']
for i in range(0,5):
# Test click
one.click()
plus.click()
one.click()
# Test Entry text assignment
assert widgets['TextEntry'].text == '1+1'
enter.click()
assert len(widgets['TextEntry'].text) == 0
time.sleep(1)
# More Entry text assignment
widgets['TextEntry'].text = "1+5"
assert widgets['TextEntry'].text == '1+5'
enter.click()
|