Writing LDTP test scripts in Python scripting language
- Download the binary files from Download
- Or download the source files from GIT and follow the steps to install LDTP in from source.
- Enable accessibility (Assistive Technology)
- Does your platform supported ? Refer -
- Any environment dependency to run ldtp ?
- Yes you need to have GNOME 2.10 / KDE 4.0 and above
- Does your platform supported ? Refer -
import LDTP modules
from ldtp import * from ldtputils import * Reason why we do importing based on the above format instead of 'import ldtp' is, if we do the first one, we can just directly use all the ldtp functions just by calling their name. If we import the module as 'import ldtp', then we need to call the corresponding function as ldtp.
from ldtp import selectmenuitem ('-gedit', 'mnuFile;mnuNew') Example 2:
import ldtp ldtp.selectmenuitem ('*-gedit', 'mnuFile;mnuNew')
- Refer LDTP API page for list of implemented LDTP API's
Call a function to perform an operation
LDTP generally operates on the given object in a particular window.
To select a menu item, you need to call selectmenuitem function. For example, to select open menu item in gedit application, call the below function
selectmenuitem ('frmUnsavedDocument1-gedit', 'mnuFile;mnuOpen') When you call the above a new dialog box will be poped up, you can verify whether the window is opened or not either by guiexist or by waittillguiexist
guiexist function immediately returns either 1 (window exist) or 0 (window does not exist) waittillguiexist waits for the window to appear. Wait time out is by default 30 seconds. This default time out can be either increased on decreased using GUI_TIMEOUT If you want to operate on a push button in a window, you need to call click function:
To press 'Cancel' button in a GTK Open File Selector dialog
- click ('dlgOpenFile', 'btnCancel') When you do the above operation the GTK File selector dialog disappears. To verify whether the window actually quits or not use waittillguinotexist function
If you modify any opened file in gedit, the window title will be modified. To continue operating on the window you need to change your context of operation. Reason: As you are aware that LDTP works based on individual window, the context of window will be changed, when the title changes. To over come this use setcontext function and when you don't require them use releasecontext
Edit your current opened file using:
settextvalue ('frmUnsavedDocument1-gedit', 'txt0', 'Testing editing') This will change the window title. Note, before doing the above operation, title will be 'Unsaved Document 1 - gedit' and after editing the title will look like '*Unsaved Document 1 - gedit'. To further operate on the same window, use
setcontext ('Unsaved Document 1 - gedit', '*Unsaved Document 1 - gedit') So that you can continue using the same window name, for example:
selectmenuitem ('frmUnsavedDocument1-gedit', 'mnuFile;mnuSaveAs') The above function will invoke the GTK save dialog box
If any of the action releated functions (example: selectmenuitem, click, settextvalue) fail, an exception is raised. It has to be handled by the program to either continue operating on execution or just halt
Executing LDTP scripts
* Sequencing set of LDTP scripts <span class="createlink"><a href="https://secure.freedesktop.org/write/ldtp/ikiwiki.cgi?page=ldtprunner_XML&from=LDTP_test_scripts_in_python&do=create" rel="nofollow">?</a>ldtprunner XML</span> * <a href="../How_to_execute_scripts/">How to execute scripts</a>
Debugging LDTP issues
- export LDTP_DEBUG=1 to get the list of commands issued from LDTP python to LDTP engine and also to check the return value from LDTP engine. NOTE: This will be handy, if you are not logging the status of execution.
- export LDTP_DEBUG=2 and start LDTP engine in a terminal and your scripts from a different terminal. This will give a detailed info of whats happening with the current command.
Generating LDTP scripts
- RecordHOWTO - To generate scripts based on users actions * Note: Above mentioned steps is to create scripts manually
* Identify the list of variable arguments and have it in a separate <a href="../Data_XML/">Data XML</a> file
Test cases / Scenarios
* List the test scenarios which you are planing to automate - Refer <span class="createlink"><a href="https://secure.freedesktop.org/write/ldtp/ikiwiki.cgi?page=Testcases&from=LDTP_test_scripts_in_python&do=create" rel="nofollow">?</a>Testcases</span>
* Existing LDTP test scripts - <a href="http://cgit.freedesktop.org/ldtp/pyautosuite/">http://cgit.freedesktop.org/ldtp/pyautosuite/</a> * If you have any issues in writing scripts, you can contact us either through mail or IRC - Refer <a href="../BeginnersGuide/">BeginnersGuide</a>
* If existing feature in LDTP does not work, please file a <a href="http://bugzilla.gnome.org/enter_bug.cgi?product=LDTP">bug</a> and select component as ldtp. Also provide us the steps to reproduce, so that we can fix it at the earliest. * If new feature needs to be added in LDTP, please file an enhancement <a href="http://bugzilla.gnome.org/enter_bug.cgi?product=LDTP">bug</a>
LDTP usage help
* Join the LDTP team on IRC for technical help, online. * Server : irc.freenode.net Channel : #ldtp * Join the LDTP <a href="../Mailing_List/">Mailing List</a> * Refer <a href="../FAQ/">FAQ</a>, <a href="../HOWTO/">HOWTO</a>
* If you are interested in writing a new component function - Refer <a href="../How_to_develop_component_functions_for_LDTP/">How to develop component functions for LDTP</a> * LDTP internal <a href="../Architecture/">Architecture</a> page
- UsefulLinks Other Reference ,