Reference Guide
This is the reference
The TestCase Class
-
class mago.TestCase(methodName='testMethod')
Bases: testtools.testcase.TestCase
Base class for desktop testing
This class setup the test and start/stop the application under test
-
setUp()
setUp
Launch the application when setupOnce is set to False
-
classmethod setUpClass()
setUpClass
Called once for all the tests in a TestCase.
set setupOnce to True to activate it.
This is used if you want to launch the application to test only once
at the beginning of the test session or want to do some extensive setup
-
tearDown()
tearDown
Called once at the end of the test to close the application and
cleanup the environment and destroy the application.
Only called if setupOnce is set to False.
-
classmethod tearDownClass()
tearDownClass
Called once at the end of the class to close the application and
cleanup the environment and destroy the application.
Only called if setupOnce is set to True.
The TestApplication Class
-
class mago.application.TestApplication(launcher=None, launcher_args=[], window_name=None)
Bases: object
TestApplication class
This class present an absctraction layer to manage the application under
test
-
about_close(cmdClose='btnClose', dlgAboutName=None)
Opens the about dialog
Parameters: |
- cmdClose – Name of the component to close the about dialog. If
None it tries to guess it and returns false if it can’t
- dlgAboutName – Name of the about dialog. If None it uses the name
found in about_open
|
-
about_open(cmdOpen=None, dlgAboutName=None)
Opens the about dialog
Parameters: |
- cmdOpen – Name of the component to open the about dialog. If None
it tries to guess it and returns false if it can’t
- dlgAboutName – Name of the about dialog. Try to guess it if None
|
-
authenticate(password='', cancel=False)
Manages the authentication dialog
Parameters: |
- password – User password. Defaults to an empty string
- cancel – If set to True, it cancels the dialog
|
- TODO:
- Manage it automatically with an onwindowcreate event
-
close(timeout=30)
Closes the application
# If the pid still exists:
# 1. Close the app using ldtp
# 2. If the window is not closed close it using SIGTERM
# 3. If the window is still not closed close it with SIGKILL
Parameters: |
- timout – Kill the application after timeout (in seconds)
|
-
get_windowname(discover=False)
Returns the name of the window for the current running application
following the LDTP convention.
It gets it from the _WM_ICON_NAME Atom for the XID of the main window
Parameters: |
- discover – if True or window_name is not set already, it forces
the discovery of the window using X Atoms. Otherwise
it returns the window_name
|
-
launch(launcher=None, launcher_args=[], window_name=None)
Launch the application
Parameters: |
- launcher – Name of the binary to launch the application. If this
argument is not specificied.
- launcher_args – Optional arguments to launch the application
- window_name – Name of the main window of the application. The
name respect the LDTP naming convention
|
-
openDocument(path, actionOpen='mnuOpen*', dlgOpen='dlgOpenDocument', btnOk='btnOpen', defaultTimeout=2, opts={})
Helper method to manage the open dialog.
All the names in argument follow the LDTP naming convention
Parameters: |
- parentWindow – Name of the main window
- path – Path to the document
- actionOpen – Name of the widget to open the Open dialog
- dlgOpen – Name of the Open dialog
- btnOk – Name of the button to open the document
- defaultTimeout – Timeout between actions
- opts – Additional arguments to provide to the dialog. This is a
dict of the form {‘componenent_name’:’value’}
|
-
saveDocument(path, actionSave='mnuSaveAs*', dlgSave='dlgSave*', btnOk='btnSave', defaultTimeout=2, opts={}, replace=True)
Helper method to manage the save dialog.
All the names in argument follow the LDTP naming convention
Parameters: |
- parentWindow – Name of the main window
- path – Path to the document
- actionOpen – Name of the widget to open the Save dialog
- dlgSave – Name of the Save dialog
- btnOk – Name of the button to validate the action
- defaultTimeout – Timeout between actions
- opts – Additional arguments to provide to the dialog. This is a
dict of the form {‘componenent_name’:’value’}
- replace – Set to true (default) to overwrite an existing file
|
The MagoConfig Class
-
class mago.config.MagoConfig(file)
Bases: ConfigParser.SafeConfigParser
This class loads one or many configuration files
-
load_config(file)
Loads a configuration file
This method loads a configuration file using the ConfigParser.read()
method. Addional configuration files can be added with the ‘include’
directive.
[section]
key1 = value1
include = path_to_file
Only one include directive is allowed, the last one will be used and
only one include file can be specified.
Relative path in the include directive are relative to the current
directory not the directory of the parent configuration file.
Utilities
Various tools to compare files and images, take screenshot, run commands,
manage packages, ...
-
mago.utils.a11y_enabled()
Return True is a11y is enabled
-
mago.utils.cmd(command, input=None, stderr=-2, stdout=-1, stdin=None, env=None)
Try to execute given command (array) and return its stdout, or return
a textual error if it failed.
Parameters: |
- command –
- input – Default: None
- stderr – Default: STDOUT
- stdout –
- stdin –
- env –
|
-
mago.utils.dpkg(package, action='status', queryformat='${Package} ${Version}\t${Status}')
Execute a dpkg action on a package. The user needs sudo privileges in
order to execute the actions install, purge and remove.
Returns the return code and output of dpkg
-
mago.utils.file_compare(file1, file2)
Compare 2 files and returns True if files are equals
-
mago.utils.is_package_installed(package)
Query the dpkg status database and returns True is the specified
package is installed
-
mago.utils.running_unity()
Returns true if Unity is running
XLib
Import pywo library and define additional extensions
-
mago.xlib.window_from_pid(pid, command=None)
Return the first XID matching a PID
Parameters: |
- pid – Process ID
- command – Command used to launch the application. Used as fallback
to find the window using WM_COMMAND
|
Mouse
The goal of PyMouse is to have a cross-platform way to control the mouse.
PyMouse should work on Windows, Mac and any Unix that has xlib.
See http://github.com/pepijndevos/PyMouse for more information.
Unity
-
class mago.unity.Unity
-
get_state(UIElement=None)
Dump the state of the UIElement
UIElement: Launcher, Panel, ... or All is None or Unity
-
walk_state(data=None, level=0)
Dump the state in a human readable format
data: If None uses self._state
level: Level of the node