############################################################################# # # Linux Desktop Testing Project http://ldtp.freedesktop.org # # Author: # Veerapuram Varadhan # Prashanth Mohan # Venkateswaran S # Nagappan Alagappan # # Copyright 2004 - 2007 Novell, Inc. # Copyright 2008 - 2009 Nagappan Alagappan # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Library General Public # License as published by the Free Software Foundation; either # version 2 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Library General Public License for more details. # # You should have received a copy of the GNU Library General Public # License along with this library; if not, write to the # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, # Boston, MA 02110, USA. # ############################################################################# __author__ = "Nagappan Alagappan , "\ "Veerapuram Varadhan , "\ "Prashanth Mohan , Venkateswaran S " # __maintainer__ = "Nagappan Alagappan " __version__ = "1.7.2" import os import re import sys import xml import time import types import base64 import select import socket import struct import random import thread import traceback import threading import datetime from xml.sax import saxutils from xml.parsers.expat import ExpatError from xml.dom.minidom import parse, parseString try: import subprocess subprocessModule = True except: import commands subprocessModule = False # Let us not register our application under at-spi application list os.environ ['GTK_MODULES'] = '' import ldtplib import ldtputils from ldtplib.ldtplibutils import * _ldtpDebug = os.getenv ('LDTP_DEBUG') _userName = 'LDTP' if os.getenv ('USER'): _userName = os.getenv ('USER') elif os.getenv ('LOGNAME'): _userName = os.getenv ('LOGNAME') _screenshotDir = _logDir = '/tmp/ldtp-%s' % _userName if subprocessModule: subprocess.call('mkdir -p %s' % _logDir, shell = True) subprocess.call('rm -f /tmp/LDTP-XML-*', shell = True) else: commands.getstatusoutput('mkdir -p %s' % _logDir) commands.getstatusoutput('rm -f /tmp/LDTP-XML-*') # Init callback functions dictionary _callbackFunctions = {} # Init callback functions dictionary _ltfxCallbackFunctions = {} # Create read flag _readFlag = threading.Event () # Clear the flag by default _readFlag.clear () # Create notification flag _notificationFlag = threading.Event () # Set the flag by default _notificationFlag.set () # Contains poll fd's _serverPoll = None _mainSock, _ldtpUseTcp = connect2LdtpExecutionEngine () _sockFdPool = ldtplib.ldtplibutils.sockFdPool _sockFdPool [threading.currentThread ()] = _mainSock logger = None xmlhdlr = None # Default GUI timeout 30 seconds _ldtpGuiTimeout = 30 __timeDelayBetweenCmds = os.getenv ('LDTP_DELAY_CMD') def logFailures (error, screenshot = True, logStatus = "error"): log (error, logStatus) if screenshot and not _ldtpUseTcp: _logFile = "%s/screenshot-%s.png" % (_screenshotDir, time.strftime ("%m-%d-%Y-%H-%M-%s")) log (ldtputils.imagecapture (outFile = _logFile), "screenshot") def generatexml (commandId, *args): """This Function will parse some information into an LDTP packet INPUT: commandId --> command_id args --> [,window_name[,object_name[,args...]]] OUTPUT: returns a string in the LDTP packet (XML lib2) format""" # Argument length argsLen = len (args) _argDebug = '' # Fill action name _xml = "%ld" % commandId if argsLen >= 1: _xml = "%s%s" % (_xml, saxutils.escape (args [0])) if commandId != command.INITAPPMAP and argsLen >= 2: _xml = "%s%s" % (_xml, saxutils.escape (args [1])) _argDebug = "'%s'" % args [1] if argsLen >= 3: _xml = "%s%s" % (_xml, saxutils.escape (args [2])) _argDebug = "%s, '%s'" % (_argDebug, args [2]) if argsLen >= 4: _xml = "%s" % _xml # Fixme: Dirty hack :( start if type (args [3]) == list: args = args [3] args.insert (0, '') args.insert (1, '') args.insert (2, '') argsLen = len (args) # Fixme: Dirty hack :( end for index in range (3, argsLen): if args [index] != None and args [index] != '': if type (args [index]) is type (int): _xml = "%s" % (_xml, args [index]) _argDebug = "%s, %d" % (_argDebug, args [index]) else: _xml = "%s" % (_xml, args [index]) _argDebug = "%s, '%s'" % (_argDebug, args [index]) _xml = "%s" % _xml if commandId == command.INITAPPMAP: _xml = "%s" % (_xml, args [1]) _argDebug = "'%s'" % args [1] _cmd = dir (command)[commandId] if re.search ('exist', _cmd, re.I) == None and \ re.search ('verify', _cmd, re.I) == None and \ re.search ('wait', _cmd, re.I) == None and \ re.search ('list', _cmd, re.I) == None and \ re.search ('getobject', _cmd, re.I) == None and \ re.search ('getchild', _cmd, re.I) == None and \ re.search ('has', _cmd) == None: # Let us delay the command execution by 1 second, as the at-cspi really hogs if __timeDelayBetweenCmds != None: try: # Delay each command by '__timeDelayBetweenCmds' seconds time.sleep (int (__timeDelayBetweenCmds)) except IndexError: # Default to 5 seconds delay if LDTP_DELAY_CMD # env variable is set time.sleep (5) else: time.sleep (1) if _ldtpDebug: try: print "%s (%s)" % (dir (command)[commandId].lower (), _argDebug) except: if hasattr (traceback, 'format_exc'): print traceback.format_exc () else: print traceback.print_exc () _xml = '%s' % _xml return _xml def parseobjectlist (xmldata): """Returns the object list""" try: _objList = None try: dom = parseString (xmldata) except UnicodeEncodeError: dom = parseString (xmldata.encode ('utf-8')) try: _objList = dom.getElementsByTagName ('OBJECTLIST') except IndexError: raise LdtpExecutionError ('Invalid Object List') if _objList == None: raise LdtpExecutionError ('Invalid Object List') taglist = [] for dataelements in _objList: for data in dataelements.getElementsByTagName ('OBJECT'): taglist.append (getText (data.childNodes)) return taglist except ExpatError, msg: if _ldtpDebug: if hasattr (traceback, 'format_exc'): print traceback.format_exc () else: print traceback.print_exc () raise LdtpExecutionError ('Parsing XML error: ' + str (msg)) def parsexml (xmlpacket): """Returns the value obtained from the server's return LDTP packet""" _statusMsg = None _statusCode = None _serverResponse = None _responseType = None _requestId = None _serverResponse = None _responseObj = None _serverResponseLen = 0 try: dom = parseString (xmlpacket) try: _responseObj = dom.getElementsByTagName ('RESPONSE')[0] _responseType = 'response' except IndexError: try: _responseObj = dom.getElementsByTagName ('NOTIFICATION')[0] _responseType = 'notification' except IndexError, msg: raise LdtpExecutionError ('Invalid Response') try: _responseStatusObj = _responseObj.getElementsByTagName ('STATUS')[0] _statusCode = int (getText (_responseStatusObj.getElementsByTagName ('CODE')[0].childNodes)) _statusMsg = getText (_responseStatusObj.getElementsByTagName ('MESSAGE')[0].childNodes) except ValueError: raise LdtpExecutionError ('Invalid Status') except IndexError: raise LdtpExecutionError ('Invalid Status') try: data = _responseObj.getElementsByTagName ('DATA')[0] _serverResponse = getCData (data.getElementsByTagName ('VALUE').item (0).childNodes)#.encode ('utf-8') _serverResponseLen = int (getText (data.getElementsByTagName ('LENGTH')[0].childNodes)) except ValueError: raise LdtpExecutionError ('Invalid Data Length') except IndexError: # Data tag may not be present pass try: data = _responseObj.getElementsByTagName ('FILE')[0] fileName = getText (data.getElementsByTagName ('NAME').item (0).childNodes)#.encode ('utf-8') if not os.path.exists (fileName): raise LdtpExecutionError ('File %s does not exist' % fileName) fp = open (fileName) _serverResponse = '' for line in fp.readlines (): _serverResponse = _serverResponse + line _serverResponseLen = len (_serverResponse) #commands.getstatusoutput ('rm -f ' + fileName) except IndexError: # Data tag may not be present pass try: _requestId = getText (_responseObj.getElementsByTagName ('ID')[0].childNodes) except IndexError: # On notification _requestId will be empty pass except ExpatError, msg: if msg.code == xml.parsers.expat.errors.XML_ERROR_NO_ELEMENTS: return None if xml.parsers.expat.ErrorString (msg.code) == xml.parsers.expat.errors.XML_ERROR_NO_ELEMENTS: return None raise LdtpExecutionError ('Parsing XML error: ' + str (msg)) # Return all the respective values, let the calling function decide what to do with the values return _responseType, (_statusCode, _statusMsg, _requestId), (_serverResponseLen, _serverResponse) def getresponse (packetId = None, sockfd = None, timeOut = True): global _ldtpGuiTimeout count = 0 # Let us initialize with empty string, as we are going to check for None later # returned by recvpacket later _responsePacket = '' while count < _ldtpGuiTimeout: try: _responsePacket = recvpacket (sockfd = sockfd) break except LdtpExecutionError, msg: if str(msg) == 'Timeout': if timeOut is False: # don't timeout, so don't increase the count ! continue time.sleep (1) # If timeout, let us retry for _ldtpGuiTimeout times count += 1 continue raise if _responsePacket == None: if _ldtpDebug != None and _ldtpDebug == '2': print 'Response None' _mainSock, _ldtpUseTcp = connect2LdtpExecutionEngine () _sockFdPool = ldtplib.ldtplibutils.sockFdPool _sockFdPool [threading.currentThread ()] = _mainSock raise LdtpExecutionError ('Server aborted') try: _responseType, _responseStatus, _responseData = parsexml (_responsePacket) if _responseType == 'response': # If response type is response, then let us enforce checking packetId if _responseStatus [2] == packetId: return _responseStatus, _responseData else: if _ldtpDebug: print 'Invalid response packet', _responseStatus [2], packetId return (-1, "Invalid response packet", packetId), (0, None) # If notification, then return directly, don't check return _responseStatus, _responseData except TypeError, msg: if _ldtpDebug != None and _ldtpDebug == '2': print 'TypeError', msg return (-1, "Invalid response packet", packetId), (0, None) def invokecallback (windowTitle, *args): _clientFd, _ldtpUseTcp = connect2LdtpExecutionEngine () _sockFdPool = ldtplib.ldtplibutils.sockFdPool _sockFdPool [threading.currentThread ()] = _clientFd # Since the LDTP engine sends notification packet to the socket fd # who initiate the onwindowcreate call # and so, the registering for window event should be in this function _requestId = threading.currentThread ().getName () + str (command.ONWINDOWCREATE) _message = generatexml (command.ONWINDOWCREATE, _requestId, windowTitle) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError ('onwindowcreate failed: ' + _responseStatus [1]) # Once we receive the response, let us go into this thread getresponse call # If we receive any notification from LDTP engine, let us invoke the callback function # and go back to receive mode while True: # NOTE: The script writer has to use removecallback function to stop this never # ending while loop _responseStatus, _responseData = getresponse (sockfd = _clientFd, timeOut = False) if _ldtpDebug: print _responseStatus, _responseData # Get the callback function callback = _callbackFunctions.get(_responseData [1]) if callback: callback = callback[0] else: if _ldtpDebug: print 'Window not registered with LDTP window format' # Check whether its callable if callable(callback): # If callable then call the function if len(args) and args[0]: callback(*args[0]) else: callback() else: if _ldtpDebug: print 'callback function is not callable, ignoring' def invokeltfxcallback (clientsocket, callback): clientsock, _ldtpUseTcp = connect2LdtpExecutionEngine () global _serverPoll # Register newly created socket for polling _serverPoll.register (clientsock, select.POLLIN) # Add new client socket to socket fd pool _sockFdPool[threading.currentThread ()] = clientsock _notificationFlag.set () if (callable (callback)): callback () # Unregister newly created socket from polling once its completed _serverPoll.unregister (clientsock) def shutdown (): if threading.activeCount () > 1: thread.exit () stoplog () #sys.exit () def selectevent (windowName, componentName, calendarEventName): """Selects the row from the table of calendar events based on the calendar event name specified INPUT: selectevent ('', '', '') OUTPUT: Returns 1 on success and 0 on error.""" try: _requestId = threading.currentThread ().getName () + str (command.SELECTEVENT) _message = generatexml (command.SELECTEVENT, _requestId, windowName, componentName, calendarEventName) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('selectevent failed: %s' % str(msg)) raise def selecteventindex (windowName, componentName, eventNumber): """Select an event from a calendar table using its index. Index for a calendar event starts from 1. INPUT: selecteventindex ('', '', ) OUTPUT: Returns 1 on success and 0 on error.""" try: _requestId = threading.currentThread ().getName () + str (command.SELECTEVENTINDEX) _message = generatexml (command.SELECTEVENTINDEX, _requestId, windowName, componentName, str (eventNumber)) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('selecteventindex failed: %s' % str(msg)) raise def verifyeventexist (windowName, componentName): """verifies whether any events are present in a calendar table INPUT: verifyeventexist ('', '') OUTPUT: Returns 1 on success and 0 on no events.""" try: _requestId = threading.currentThread ().getName () + str (command.VERIFYEVENTEXIST) _message = generatexml (command.VERIFYEVENTEXIST, _requestId, windowName, componentName) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: logFailures ('verifyeventexist failed: %s' % _responseStatus [1], screenshot = False, logStatus = "warning") return 0 return 1 except LdtpExecutionError, msg: logFailures ('verifyeventexist failed: %s' % str(msg), screenshot = False, logStatus = "warning") return 0 def ischildselected (windowName, componentName, item): """ INPUT: ischildselected ('', '', '') OUTPUT: Returns 1 on success and 0 on no events.""" try: _requestId = threading.currentThread ().getName () + str (command.ISCHILDSELECTED) _message = generatexml (command.ISCHILDSELECTED, _requestId, windowName, componentName, item) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: logFailures ('ischildselected failed: %s' % _responseStatus [1], screenshot = False, logStatus = "warning") return 0 return 1 except LdtpExecutionError, msg: logFailures ('ischildselected failed: %s' % str(msg), screenshot = False, logStatus = "warning") return 0 def ischilditemselected (windowName, componentName, item): """ INPUT: ischilditemselected ('', '', '') OUTPUT: Returns 1 on success and 0 on no events.""" try: _requestId = threading.currentThread ().getName () + \ str (command.ISCHILDITEMSELECTED) _message = generatexml (command.ISCHILDITEMSELECTED, _requestId, windowName, componentName, item) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: logFailures ('ischilditemselected failed: %s' % _responseStatus [1], screenshot = False, logStatus = "warning") return 0 return 1 except LdtpExecutionError, msg: logFailures ('ischilditemselected failed: %s' % str(msg), screenshot = False, logStatus = "warning") return 0 def ischildindexselected (windowName, componentName, index): """ INPUT: ischildindexselected ('', '', index) OUTPUT: Returns 1 on success and 0 on no events.""" try: _requestId = threading.currentThread ().getName () + str (command.ISCHILDINDEXSELECTED) _message = generatexml (command.ISCHILDINDEXSELECTED, _requestId, windowName, componentName, str (index)) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: logFailures ('ischildindexselected failed: %s' % _responseStatus [1], screenshot = False, logStatus = "warning") return 0 return 1 except LdtpExecutionError, msg: logFailures ('ischildindexselected failed: %s' % str(msg), screenshot = False, logStatus = "warning") return 0 def ischilditemindexselected (windowName, componentName, index): """ INPUT: ischilditemindexselected ('', '', index) OUTPUT: Returns 1 on success and 0 on no events.""" try: _requestId = threading.currentThread ().getName () + \ str (command.ISCHILDITEMINDEXSELECTED) _message = generatexml (command.ISCHILDITEMINDEXSELECTED, _requestId, windowName, componentName, str (index)) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: logFailures ('ischilditemindexselected failed: %s' % _responseStatus [1], screenshot = False, logStatus = "warning") return 0 return 1 except LdtpExecutionError, msg: logFailures ('ischilditemindexselected failed: %s' % str(msg), screenshot = False, logStatus = "warning") return 0 def check (windowName, componentName): """Check (tick) the check box state. INPUT: check ('', '') OUTPUT: Returns 1 if state is checked, else 0.""" try: _requestId = threading.currentThread ().getName () + str (command.CHECK) _message = generatexml (command.CHECK, _requestId, windowName, componentName) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('check failed: %s' % str(msg)) raise def uncheck (windowName, componentName): """Uncheck (un-tick) the check state. INPUT: uncheck ('', '') OUTPUT: Returns 1 if state is unchecked, else 0.""" try: _requestId = threading.currentThread ().getName () + str (command.UNCHECK) _message = generatexml (command.UNCHECK, _requestId, windowName, componentName) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('uncheck failed: %s' % str(msg)) raise def click (windowName, componentName): """click on radio button / check box / push button/ combo box/ radio menu item/ toggle button/ radio button. INPUT: click ('', '') OUTPUT: Clicks the component_name.""" try: _requestId = threading.currentThread ().getName () + str (command.CLICK) _message = generatexml (command.CLICK, _requestId, windowName, componentName) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('click failed: %s' % str(msg)) raise def press (windowName, componentName): """tell the button to press itself INPUT: press ('', '') OUTPUT: Presses the component_name.""" try: _requestId = threading.currentThread ().getName () + str (command.PRESS) _message = generatexml (command.PRESS, _requestId, windowName, componentName) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('press failed: %s' % str(msg)) raise def menucheck (windowName, componentName): """menucheck (tick) the menu item check state. INPUT: menucheck ('', '') OUTPUT: Returns 1 if state is checked, else 0.""" try: _requestId = threading.currentThread ().getName () + str (command.MENUCHECK) _message = generatexml (command.MENUCHECK, _requestId, windowName, componentName) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('menucheck failed: %s' % str(msg)) raise def menuuncheck (windowName, componentName): """menuuncheck (un-tick) the check state. INPUT: menuuncheck ('', '') OUTPUT: Returns 1 if state is unchecked, else 0.""" try: _requestId = threading.currentThread ().getName () + str (command.MENUUNCHECK) _message = generatexml (command.MENUUNCHECK, _requestId, windowName, componentName) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('menuuncheck failed: %s' % str(msg)) raise def verifycheck (windowName, componentName): """Checks the state of check box. INPUT: verifycheck ('', '') OUTPUT: If check box state is checked, then returns 1, else 0.""" try: _requestId = threading.currentThread ().getName () + str (command.VERIFYCHECK) _message = generatexml (command.VERIFYCHECK, _requestId, windowName, componentName) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: logFailures ('verifycheck failed: %s' % _responseStatus [1], screenshot = False, logStatus = "warning") return 0 return 1 except LdtpExecutionError, msg: logFailures ('verifycheck failed: %s' % str(msg), screenshot = False, logStatus = "warning") return 0 def verifyuncheck (windowName, componentName): """Checks the state of check box. INPUT: verifyuncheck ('', '') OUTPUT: If check box state is un-checked, then returns 1, else 0.""" try: _requestId = threading.currentThread ().getName () + str (command.VERIFYUNCHECK) _message = generatexml (command.VERIFYUNCHECK, _requestId, windowName, componentName) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: logFailures ('verifyuncheck failed: %s' % _responseStatus [1], screenshot = False, logStatus = "warning") return 0 return 1 except LdtpExecutionError, msg: logFailures ('verifyuncheck failed: %s' % str(msg), screenshot = False, logStatus = "warning") return 0 def menuitemenabled (windowName, menuItem): """ INPUT: menuitemenabled ('', '') OUTPUT: 1 on success, 0 on failure""" try: _requestId = threading.currentThread ().getName () + str (command.MENUITEMENABLED) _message = generatexml (command.MENUITEMENABLED, _requestId, windowName, menuItem) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: logFailures ('menuitemenabled failed: %s' % _responseStatus [1], screenshot = False, logStatus = "warning") return 0 return 1 except LdtpExecutionError, msg: logFailures ('menuitemenabled failed: %s' % str(msg), screenshot = False, logStatus = "warning") return 0 def verifymenucheck (windowName, menuItem): """ INPUT: verifymenucheck ('', '') OUTPUT: 1 on success, 0 on failure""" try: _requestId = threading.currentThread ().getName () + str (command.VERIFYMENUCHECK) _message = generatexml (command.VERIFYMENUCHECK, _requestId, windowName, menuItem) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: logFailures ('verifymenucheck failed: %s' % _responseStatus [1], screenshot = False, logStatus = "warning") return 0 return 1 except LdtpExecutionError, msg: logFailures ('verifymenucheck failed: %s' % str(msg), screenshot = False, logStatus = "warning") return 0 def verifymenuuncheck (windowName, menuItem): """ INPUT: verifymenuuncheck ('', '') OUTPUT: 1 on success, 0 on failure""" try: _requestId = threading.currentThread ().getName () + str (command.VERIFYMENUUNCHECK) _message = generatexml (command.VERIFYMENUUNCHECK, _requestId, windowName, menuItem) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: logFailures ('verifymenuuncheck failed: %s' % _responseStatus [1], screenshot = False, logStatus = "warning") return 0 return 1 except LdtpExecutionError, msg: logFailures ('verifymenuuncheck failed: %s' % str(msg), screenshot = False, logStatus = "warning") return 0 def verifydropdown (windowName, componentName): """ INPUT: verifydropdown ('', '') OUTPUT: 1 on success, 0 on failure""" try: _requestId = threading.currentThread ().getName () + str (command.VERIFYDROPDOWN) _message = generatexml (command.VERIFYDROPDOWN, _requestId, windowName, componentName) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: logFailures ('verifydropdown failed: %s' % _responseStatus [1], screenshot = False, logStatus = "warning") return 0 return 1 except LdtpExecutionError, msg: logFailures ('verifydropdown failed: %s' % str(msg), screenshot = False, logStatus = "warning") return 0 # CheckMenuItem Functions def selectmenuitem (windowName, menuHierarchy): """Selects the menu item specified. INPUT: selectmenuitem ('', '') OUTPUT: 1 on success, LdtpExecutionError on failure.""" try: _requestId = threading.currentThread ().getName () + str (command.SELECTMENUITEM) _message = generatexml (command.SELECTMENUITEM, _requestId, windowName, menuHierarchy) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('selectmenuitem failed: %s' % str(msg)) raise # Combobox Functions def hidelist (windowName, componentName): """ Hides combo box drop down list in the current dialog. Suppose in previous operation one testcase has clicked on combo box, its drop down list will be displayed. If further no any operation has been done on that combo box then to close that drop down list 'HideList' action is required. INPUT: hidelist ('', '') OUTPUT: 1 on success, LdtpExecutionError on failure""" try: _requestId = threading.currentThread ().getName () + str (command.HIDELIST) _message = generatexml (command.HIDELIST, _requestId, windowName, componentName) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('hidelist failed: %s' % str(msg)) raise def selectindex (windowName, componentName, index): """ SelectIndex action will select an item from combo box where value of index is pointing to its position in list/menu. INPUT: selectindex ('', '', ) OUTPUT: 1 on success, LdtpExecutionError on failure""" try: _requestId = threading.currentThread ().getName () + str (command.SELECTINDEX) _message = generatexml (command.SELECTINDEX, _requestId, windowName, componentName, str (index)) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('selectindex failed: %s' % str(msg)) raise def unselectindex (windowName, componentName, index): """ Unselectindex action will unselect an item from layered pane where value of index is pointing to its position in list. INPUT: unselectindex ('', '', ) OUTPUT: 1 on success, LdtpExecutionError on failure""" try: _requestId = threading.currentThread ().getName () + \ str (command.UNSELECTINDEX) _message = generatexml (command.UNSELECTINDEX, _requestId, windowName, componentName, str (index)) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('unselectindex failed: %s' % str(msg)) raise def unselectitemindex (windowName, componentName, index): """ Unselectitemindex action will unselect an item from layered pane where value of index is from the previously selected items INPUT: unselectitemindex ('', '', ) OUTPUT: 1 on success, LdtpExecutionError on failure""" try: _requestId = threading.currentThread ().getName () + \ str (command.UNSELECTITEMINDEX) _message = generatexml (command.UNSELECTITEMINDEX, _requestId, windowName, componentName, str (index)) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('unselectitemindex failed: %s' % str(msg)) raise def settextvalue (windowName, componentName, text): """puts the text into the component given by the component name INPUT: settextvalue ('', '', '') OUTPUT: returns 1 on success and 0 otherwise""" try: _requestId = threading.currentThread ().getName () + \ str (command.SETTEXTVALUE) _message = generatexml (command.SETTEXTVALUE, _requestId, windowName, componentName, text) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('settextvalue failed: %s' % str(msg)) raise def gettextvalue (windowName, componentName, startPosition = None, endPosition = None): """ INPUT: gettextvalue ('', '', [start position], [end position]) OUTPUT: returns 1 on success and 0 otherwise""" if startPosition != None: startPosition = str (startPosition) if endPosition != None: endPosition = str (endPosition) try: _requestId = threading.currentThread ().getName () + \ str (command.GETTEXTVALUE) _message = generatexml (command.GETTEXTVALUE, _requestId, windowName, componentName, startPosition, endPosition) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return _responseData [1] except LdtpExecutionError, msg: logFailures ('gettextvalue failed: %s' % str(msg)) raise def activatetext (windowName, componentName): """ INPUT: activatetext ('', '') OUTPUT: 1 on success, LdtpExecutionError on failure""" try: _requestId = threading.currentThread ().getName () + str (command.ACTIVATETEXT) _message = generatexml (command.ACTIVATETEXT, _requestId, windowName, componentName) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('activatetext failed: %s' % str(msg)) raise def appendtext (windowName, componentName, text): """ INPUT: appendtext ('', ') OUTPUT: 1 on success, LdtpExecutionError on failure""" try: _requestId = threading.currentThread ().getName () + str (command.APPENDTEXT) _message = generatexml (command.APPENDTEXT, _requestId, windowName, componentName, text) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('appendtext failed: %s' % str(msg)) raise def getcursorposition (windowName, componentName): """ INPUT: windowName --> Name in the title bar componentName --> Name of the object (TextBox) OUTPUT: postion of the text cursor in the object (integer)""" try: _requestId = threading.currentThread ().getName () + str (command.GETCURSORPOSITION) _message = generatexml (command.GETCURSORPOSITION, _requestId, windowName, componentName) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return long (_responseData [1]) except LdtpExecutionError, msg: logFailures ('getcursorposition failed: %s' % str(msg)) raise def setcursorposition (windowName, componentName, position): """ INPUT: windowName --> Name in the title bar componentName --> Name of the object (TextBox) position --> Position in the TextBox where cursor is to be moved to OUTPUT: 1 on success, LdtpExecutionError on failure""" try: _requestId = threading.currentThread ().getName () + str (command.SETCURSORPOSITION) _message = generatexml (command.SETCURSORPOSITION, _requestId, windowName, componentName, str (position)) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('setcursorposition failed: %s' % str(msg)) raise def capturetofile (windowName, componentName, fileName = None): """ INPUT: capturetofile ('', ''[, '']) OUTPUT: 1 on success, LdtpExecutionError on failure""" try: _requestId = threading.currentThread ().getName () + str (command.CAPTURETOFILE) _message = generatexml (command.CAPTURETOFILE, _requestId, windowName, componentName, fileName) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('capturetofile failed: %s' % str(msg)) raise def showlist (windowName, componentName): """ Displays combo box drop down list in the current dialog. INPUT: showlist ('windowName', 'componentName') OUTPUT: 1 on success, LdtpExecutionError on failure""" try: _requestId = threading.currentThread ().getName () + str (command.SHOWLIST) _message = generatexml (command.SHOWLIST, _requestId, windowName, componentName) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('showlist failed: %s' % str(msg)) raise def verifyhidelist (windowName, componentName): """ Verifies if combo box drop down list in the current dialog is not visible. INPUT: verifyhidelist ('', '') OUTPUT: 1 on success, 0 on failure""" try: _requestId = threading.currentThread ().getName () + str (command.VERIFYHIDELIST) _message = generatexml (command.VERIFYHIDELIST, _requestId, windowName, componentName) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: logFailures ('verifyhidelist failed: %s' % _responseStatus [1], screenshot = False, logStatus = "warning") return 0 return 1 except LdtpExecutionError, msg: logFailures ('verifyhidelist failed: %s' % str(msg), screenshot = False, logStatus = "warning") return 0 def verifyselect (windowName, componentName, selectArgument): """ VerfySelect action will verify if combo box is set to value given in argument. INPUT: verifyselect ('', '', '') OUTPUT: VerifySelect function will try to find if text box associated with combo box is set to value specified in the argument.""" try: _requestId = threading.currentThread ().getName () + str (command.VERIFYSELECT) _message = generatexml (command.VERIFYSELECT, _requestId, windowName, componentName, selectArgument) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: logFailures ('verifyselect failed: %s' % _responseStatus [1], screenshot = False, logStatus = "warning") return 0 return 1 except LdtpExecutionError, msg: logFailures ('verifyselect failed: %s' % str(msg), screenshot = False, logStatus = "warning") return 0 def verifysettext (windowName, componentName, text): """ checks if the text is inserted into the component given by the component name INPUT: verifysettext ('', '', '') OUTPUT: returns 1 if the text is inserted into the specified component else returns 0 """ try: _requestId = threading.currentThread ().getName () + str (command.VERIFYSETTEXT) _message = generatexml (command.VERIFYSETTEXT, _requestId, windowName, componentName, text) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: logFailures ('verifysettext failed: %s' % _responseStatus [1], screenshot = False, logStatus = "warning") return 0 return 1 except LdtpExecutionError, msg: logFailures ('verifysettext failed: %s' % str(msg), screenshot = False, logStatus = "warning") return 0 def verifyshowlist (windowName, componentName): """ Verifies if combo box drop down list in the current dialog is visible. INPUT: verifyshowlist ('', '') OUTPUT: Combo box will generally have a list as its child or a menu as its child. So this function gets object handle of list or menu object, checks if list or menu items of combo box is visible, if yes then return zero else minus one.""" try: _requestId = threading.currentThread ().getName () + str (command.VERIFYSHOWLIST) _message = generatexml (command.VERIFYSHOWLIST, _requestId, windowName, componentName) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: logFailures ('verifyshowlist failed: %s' % _responseStatus [1], screenshot = False, logStatus = "warning") return 0 return 1 except LdtpExecutionError, msg: logFailures ('verifyshowlist failed: %s' % str(msg), screenshot = False, logStatus = "warning") return 0 def comboselect (windowName, componentName, menuItemName): """Select a menu item or list item in a combo box INPUT: comboselect ('', '', '') OUTPUT: 1 on success, LdtpExecutionError on failure""" try: _requestId = threading.currentThread ().getName () + str (command.COMBOSELECT) _message = generatexml (command.COMBOSELECT, _requestId, windowName, componentName, menuItemName) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('comboselect failed: %s' % str(msg)) raise def comboselectindex (windowName, componentName, index): """ INPUT: comboselectindex ('', '', ) OUTPUT: 1 on success, LdtpExecutionError on failure""" try: _requestId = threading.currentThread ().getName () + str (command.COMBOSELECTINDEX) _message = generatexml (command.COMBOSELECTINDEX, _requestId, windowName, componentName, str (index)) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('comboselectindex failed: %s' % str(msg)) raise def comparetextproperty (windowName, componentName, textProperty, startPosition = None, endPosition = None): """ INPUT: comparetextproperty ('', '', [, [, ]]) OUTPUT: 1 on success, 0 on failure""" if startPosition != None: startPosition = str (startPosition) if endPosition != None: endPosition = str (endPosition) try: _requestId = threading.currentThread ().getName () + str (command.COMPARETEXTPROPERTY) _message = generatexml (command.COMPARETEXTPROPERTY, _requestId, windowName, componentName, textProperty, startPosition, endPosition) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: logFailures ('comparetextproperty failed: %s' % _responseStatus [1], screenshot = False, logStatus = "warning") return 0 return 1 except LdtpExecutionError, msg: logFailures ('comparetextproperty failed: %s' % str(msg), screenshot = False, logStatus = "warning") return 0 def containstextproperty (windowName, componentName, textProperty, startPosition = None, endPosition = None): """ INPUT: containstextproperty ('', '', [, [, ]]) OUTPUT: 1 on success, 0 on failure""" if startPosition != None: startPosition = str (startPosition) if endPosition != None: endPosition = str (endPosition) try: _requestId = threading.currentThread ().getName () + str (command.CONTAINSTEXTPROPERTY) _message = generatexml (command.CONTAINSTEXTPROPERTY, _requestId, windowName, componentName, textProperty, startPosition, endPosition) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: logFailures ('containstextproperty failed: %s' % _responseStatus [1], screenshot = False, logStatus = "warning") return 0 return 1 except LdtpExecutionError, msg: logFailures ('containstextproperty failed: %s' % str(msg), screenshot = False, logStatus = "warning") return 0 def gettextproperty (windowName, componentName, startPosition = None, endPosition = None): """ INPUT: gettextproperty ('', ''[, [, ]]) OUTPUT: 1 on success, LdtpExecutionError on failure""" if startPosition != None: startPosition = str (startPosition) if endPosition != None: endPosition = str (endPosition) try: _requestId = threading.currentThread ().getName () + str (command.GETTEXTPROPERTY) _message = generatexml (command.GETTEXTPROPERTY, _requestId, windowName, componentName, startPosition, endPosition) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return _responseData [1] except LdtpExecutionError, msg: logFailures ('gettextproperty failed: %s' % str(msg)) raise def copytext (windowName, componentName, startPosition = None, endPosition = None): """ INPUT: copytext ('', ''[, [, ]]) OUTPUT: 1 on success, LdtpExecutionError on failure""" if startPosition != None: startPosition = str (startPosition) if endPosition != None: endPosition = str (endPosition) try: _requestId = threading.currentThread ().getName () + str (command.COPYTEXT) _message = generatexml (command.COPYTEXT, _requestId, windowName, componentName, startPosition, endPosition) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('copytext failed: %s' % str(msg)) raise def cuttext (windowName, componentName, startPosition = None, endPosition = None): """ INPUT: cuttext ('', ''[, [, ]]) OUTPUT: 1 on success, LdtpExecutionError on failure""" if startPosition != None: startPosition = str (startPosition) if endPosition != None: endPosition = str (endPosition) try: _requestId = threading.currentThread ().getName () + str (command.CUTTEXT) _message = generatexml (command.CUTTEXT, _requestId, windowName, componentName, startPosition, endPosition) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('cuttext failed: %s' % str(msg)) raise def inserttext (windowName, componentName, position, text): """ INPUT: inserttext ('', '', , '') OUTPUT: 1 on success, LdtpExecutionError on failure""" try: _requestId = threading.currentThread ().getName () + str (command.INSERTTEXT) _message = generatexml (command.INSERTTEXT, _requestId, windowName, componentName, str (position), text) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('inserttext failed: %s' % str(msg)) raise def deletetext (windowName, componentName, startPosition = None, endPosition = None): """ INPUT: deletetext ('', ''[, [, ]]) OUTPUT: 1 on success, LdtpExecutionError on failure""" if startPosition != None: startPosition = str (startPosition) if endPosition != None: endPosition = str (endPosition) try: _requestId = threading.currentThread ().getName () + str (command.DELETETEXT) _message = generatexml (command.DELETETEXT, _requestId, windowName, componentName, startPosition, endPosition) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('deletetext failed: %s' % str(msg)) raise def selecttextbyindexandregion (windowName, componentName, startPosition = None, endPosition = None, selectionNum = None): """ INPUT: selecttextbyindexandregion ('', ''[, [, [, ]]]) OUTPUT: 1 on success, LdtpExecutionError on failure""" if startPosition != None: startPosition = str (startPosition) if endPosition != None: endPosition = str (endPosition) if selectionNum != None: selectionNum = str (selectionNum) try: _requestId = threading.currentThread ().getName () + str (command.SELECTTEXTBYINDEXANDREGION) _message = generatexml (command.SELECTTEXTBYINDEXANDREGION, _requestId, windowName, \ componentName, startPosition, endPosition, selectionNum) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('selecttextbyindexandregion failed: %s' % str(msg)) raise def selecttextbyname (windowName, componentName): """ INPUT: selecttextbyname ('', '') OUTPUT: 1 on success, LdtpExecutionError on failure""" try: _requestId = threading.currentThread ().getName () + str (command.SELECTTEXTBYNAME) _message = generatexml (command.SELECTTEXTBYNAME, _requestId, windowName, componentName) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('selecttextbyname failed: %s' % str(msg)) raise def pastetext (windowName, componentName, position = None): """ INPUT: pastetext ('', ''[, ]) OUTPUT: 1 on success, LdtpExecutionError on failure""" if position != None: position = str (position) try: _requestId = threading.currentThread ().getName () + str (command.PASTETEXT) _message = generatexml (command.PASTETEXT, _requestId, windowName, componentName, position) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('pastetext failed: %s' % str(msg)) raise def expandtablecell (windowName, componentName, position): """ INPUT: expandtablecell ('', '', ) OUTPUT: 1 on success, LdtpExecutionError on failure""" try: _requestId = threading.currentThread ().getName () + str (command.EXPANDTABLECELL) _message = generatexml (command.EXPANDTABLECELL, _requestId, windowName, componentName, str (position)) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return 1 except LdtpExecutionError, msg: logFailures ('expandtablecell failed: %s' % str(msg)) raise def getcharcount (windowName, componentName): """ INPUT: getcharcount ('', '') OUTPUT: Character count on success, LdtpExecutionError on failure""" try: _requestId = threading.currentThread ().getName () + str (command.GETCHARCOUNT) _message = generatexml (command.GETCHARCOUNT, _requestId, windowName, componentName) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return int (_responseData [1]) except LdtpExecutionError, msg: logFailures ('getcharcount failed: %s' % str(msg)) raise def getlabel (windowName, componentName): """ INPUT: getlabel ('', '') OUTPUT: 1 on success, LdtpExecutionError on failure""" try: _requestId = threading.currentThread ().getName () + str (command.GETLABEL) _message = generatexml (command.GETLABEL, _requestId, windowName, componentName) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return _responseData [1] except LdtpExecutionError, msg: logFailures ('getlabel failed: %s' % str(msg)) raise def getlabelatindex (windowName, componentName, index): """ INPUT: getlabelatindex ('', '', ) OUTPUT: Label from the given index on success, LdtpExecutionError on failure""" try: _requestId = threading.currentThread ().getName () + str (command.GETLABELATINDEX) _message = generatexml (command.GETLABELATINDEX, _requestId, windowName, componentName, index) sendpacket (_message) _responseStatus, _responseData = getresponse (_requestId) if _responseStatus [0] != 0: raise LdtpExecutionError (_responseStatus [1]) return _responseData [1] except LdtpExecutionError, msg: logFailures ('getlabelatindex failed: %s' % str(msg)) raise def selectlabelspanelbyname (windowName, labelName): """ INPUT: selectlabelspanelbyname ('', '