How to write test scripts in python
From LDTP
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.<function name>
Example 1:
from ldtp import *
initappmap ('gedit.map')
Example 2:
import ldtp
ldtp.initappmap ('gedit.map')
LDTP API
Refer API Reference 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
Refer: Appmap_convention, About Appmap

