DesktopTestingLibrary

Differences between revisions 11 and 12
Revision 11 as of 2008-08-26 12:15:49
Size: 4255
Editor: static-101-137-235-87
Comment:
Revision 12 as of 2008-08-26 13:41:58
Size: 4740
Editor: static-101-137-235-87
Comment:
Deletions are marked like this. Additions are marked like this.
Line 77: Line 77:
The Application class is one of the main classes of the Desktop Testing Library. Its aim is to include all the common behavior of the Ubuntu applications. The Application class is one of the main classes of the Desktop Testing Library. Its aim is to include all the common behavior of the Ubuntu applications. If the application you want to test is not yet in the library, you can still use the Application class.
Line 79: Line 79:
To open any application you can use the open_and_check_menu_item module function (http://people.ubuntu.com/~ara/ldtp/doc/testing_module_doc/ubuntutesting.ubuntu-module.html#open_and_check_menu_item). This function will be move to Application class in future releases of the desktop-testing-library. You need to give the name of the menu item and the name of the window. I.e. to open the Gedit application we would do: To open any application you can use the open_and_check_menu_item module function (http://people.ubuntu.com/~ara/ldtp/doc/testing_module_doc/ubuntutesting.ubuntu-module.html#open_and_check_menu_item). This function will be move to Application class in future releases of the desktop-testing-library. You need to give the name of the menu item and the name of the window. I.e. to open the Calculator application we would do:
Line 81: Line 81:
{{{#!python
# Main LDTP python wrappers [0]
from ooldtp import *
from ldtp import *
from ldtputils import *
Line 82: Line 87:
# The main library in the testing-library for Ubuntu [2]
from ubuntutesting.ubuntu import *
Line 83: Line 90:
If the application you want to test is not yet in the library, you can still use the Application class. try:

    # Open the Calculator and wait for its main window
    open_and_check_menu_item('Calculator', 'Calculator')

}}}

If the application fails to open, an error will be logged in the test log.
Line 87: Line 101:
 * exit: Given an application, it tries to quit it. It reloads the application map for the given context.
 * save: Given an application, it tries to save the current document.
 * exit: Given an application, it tries to quit it. It will work only if the application has a 'Quit' menu item.
 * save: Given an application, it tries to save the current document. It will work only if the application has a 'Save' menu item.

Summary

The aim of this document is to provide a hands-on introduction to the use of the Ubuntu testing package to create new Ubuntu tests.

Prerequisites

ldtp and python-ldtp packages are needed to run the tests based on the testing library. Both packages are available in universe.

Installation

There are PPA packages for Intrepid. To install the library:

  1. Add the following lines to your /etc/apt/source.lists:

deb http://ppa.launchpad.net/apulido/ubuntu intrepid main
deb-src http://ppa.launchpad.net/apulido/ubuntu intrepid main
  1. $ sudo apt-get update
  2. $ sudo apt-get install desktop-testing-library

Hello World!

Once installed we are going to create our first script to test Ubuntu. Our script will open the Gedit and will write the string "Hello World!" in the main gedit window. We will comment below the meaning of each of the lines.

   1 # Main LDTP python wrappers [0]
   2 from ooldtp import *
   3 from ldtp import *
   4 from ldtputils import *
   5 
   6 # Necessary if we want to track performance [1]
   7 from time import *
   8 
   9 # The main library in the testing-library for Ubuntu [2]
  10 from ubuntutesting.ubuntu import *
  11 
  12 try:
  13 
  14     # Gedit is the main class for GEdit tests. [3]
  15     gedit = GEdit()
  16     
  17     # Start performance test
  18     start_time = time()
  19     
  20     # Open Gedit application and wait for existance [4]
  21     gedit.open()
  22     
  23     # Write the selected text [5]
  24     gedit.write_text("Hello World!")
  25     stop_time = time()
  26     
  27     elapsed = stop_time - start_time
  28     
  29     # Log time performance [6]
  30     log ('elapsed_time: ' + str(elapsed), 'comment')
  31     
  32 except LdtpExecutionError, msg:
  33     raise
  • [0]: LDTP is written mainly in C, but it has two wrappers in python, ldtp (http://ldtp.freedesktop.org/user-doc/index.html) and ooldtp. ooldtp is not yet documented.

  • [1]: Right now the performance is done through the time module. It will be changed, eventually, to the desktop-testing-library module.
  • [2]: Import the desktop-testing-library. The latest documentation of the testing library API is available at http://people.ubuntu.com/~ara/ldtp/doc/testing_module_doc/

  • [3]: The applications are subclasses of Application ([../DesktopTestingLibrary/Application]). Check the available applications at the testing library API documentation.
  • [4]: Open (http://people.ubuntu.com/~ara/ldtp/doc/testing_module_doc/ubuntutesting.ubuntu.GEdit-class.html) is a method inherit from the Application class. It will try to open the application through its menu and will wait for the main window to appear.

  • [5]: write_text is a method for the Gedit class, that writes the given text to the main buffer.
  • [6]: log is a function of ldtp that writes to the log.

The Application Class

The Application class is one of the main classes of the Desktop Testing Library. Its aim is to include all the common behavior of the Ubuntu applications. If the application you want to test is not yet in the library, you can still use the Application class.

To open any application you can use the open_and_check_menu_item module function (http://people.ubuntu.com/~ara/ldtp/doc/testing_module_doc/ubuntutesting.ubuntu-module.html#open_and_check_menu_item). This function will be move to Application class in future releases of the desktop-testing-library. You need to give the name of the menu item and the name of the window. I.e. to open the Calculator application we would do:

   1 # Main LDTP python wrappers [0]
   2 from ooldtp import *
   3 from ldtp import *
   4 from ldtputils import *
   5 
   6 # The main library in the testing-library for Ubuntu [2]
   7 from ubuntutesting.ubuntu import *
   8 
   9 try:
  10 
  11     # Open the Calculator and wait for its main window
  12     open_and_check_menu_item('Calculator', 'Calculator')

If the application fails to open, an error will be logged in the test log.

The Application class at least can:

  • exit: Given an application, it tries to quit it. It will work only if the application has a 'Quit' menu item.
  • save: Given an application, it tries to save the current document. It will work only if the application has a 'Save' menu item.
  • write_text: Given an application it tries to write text to its current buffer.
  • remap: It reloads the application map for the given context.

Please, check the complete documentation of the class at the API documentation

Testing/Automation/Mago/DesktopTestingLibrary (last edited 2009-06-29 09:17:00 by 63)