Best Python code snippet using pyatom_python
ldtpd.py
Source:ldtpd.py
...125 return object126 def _matches(self, pattern, item):127 return bool(re.match(fnmatch.translate(pattern), item, re.M | re.U | re.L))128 #this replicates the origional algorithm129 def _gettablerowindex(self, window, table, target):130 numrows = ldtp.getrowcount(window, table)131 numcols = len(ldtp.getobjectproperty(window, table, 'children').split())132 for i in range(0,numrows):133 for j in range(0,numcols):134 try:135 value = ldtp.getcellvalue(window, table, i, j)136 if self._matches(target,value):137 ldtp.selectrowindex(window, table, i)138 return i139 except:140 continue141 raise Exception("Item not found in table!")142 #this only searches the first column and is much quicker.143 def _quickgettablerowindex(self, window, table, target):144 numrows = ldtp.getrowcount(window, table)145 for i in range(0,numrows):146 try:147 value = ldtp.getcellvalue(window, table, i, 0)148 if self._matches(target,value):149 ldtp.selectrowindex(window, table, i)150 return i151 except:152 continue153 raise Exception("Item not found in table!")154 def _window_search(self,match,term):155 if re.search(fnmatch.translate(term),156 match,157 re.U | re.M | re.L) \158 or re.search(fnmatch.translate(re.sub("(^frm|^dlg)", "", term)),159 re.sub(" *(\t*)|(\n*)", "", match),160 re.U | re.M | re.L):161 return True162 else:163 return False164 def _closewindow(self,window_name):165 screen = wnck.screen_get_default()166 while gtk.events_pending():167 gtk.main_iteration()168 windows = screen.get_windows()169 success = 0170 for w in windows:171 current_window = w.get_name()172 if self._window_search(current_window,window_name):173 w.close(int(time.time()))174 success = 1175 break176 gobject.idle_add(gtk.main_quit)177 gtk.main()178 return success179 def _maximizewindow(self,window_name):180 screen = wnck.screen_get_default()181 while gtk.events_pending():182 gtk.main_iteration()183 windows = screen.get_windows()184 success = 0185 for w in windows:186 current_window = w.get_name()187 if self._window_search(current_window,window_name):188 w.maximize()189 success = 1190 break191 gobject.idle_add(gtk.main_quit)192 gtk.main()193 return success194 def _dispatch(self,method,params):195 if method in _supported_methods:196 paramslist = list(params)197 if method == "hasstate":198 paramslist[2]=self._translate_state(paramslist[2])199 params = tuple(paramslist)200 elif method == "closewindow":201 return self._closewindow(paramslist[0])202 elif method == "maximizewindow":203 return self._maximizewindow(paramslist[0])204 elif method == "getobjectproperty":205 paramslist[1] = self._getobjectproperty(paramslist[0],paramslist[1])206 params = tuple(paramslist)207 function = getattr(ldtp,method)208 retval = function(*params)209 if (method == "gettextvalue") and not (isinstance(retval, str) or210 isinstance(retval, unicode)):211 retval = ""212 elif (retval == -1) and (method == "gettablerowindex"):213 paramslist = list(params)214 #use quick method for now215 retval = self._quickgettablerowindex(paramslist[0],216 paramslist[1],217 paramslist[2])218 elif method == "getallstates":219 retval = [self._translate_number(state) for state in retval]220 if retval == None:221 retval = 0222 return retval223 pass224for name in _supported_methods:225 if not item in _additional_methods:226 setattr(AllMethods, name, getattr(ldtp, name))227def usage():228 print "Usage:"229 print "[-p, --port=] Port to listen on"...
table.py
Source:table.py
1#!/usr/bin/env python2#3# Linux Desktop Testing Project http://www.gnomebangalore.org/ldtp4#5# Description:6# This set of test scripts will test the LDTP framework for correct7# functioning of its APIs. This is a Regression Suite.8#9# Author:10# Prashanth Mohan <prashmohan@gmail.com>11#12#13# This test script is free software; you can redistribute it and/or14# modify it under the terms of the GNU Library General Public15# License as published by the Free Software Foundation; either16# version 2 of the License, or (at your option) any later version.17#18# This library is distributed in the hope that it will be useful,19# but WITHOUT ANY WARRANTY; without even the implied warranty of20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU21# Library General Public License for more details.22#23# You should have received a copy of the GNU Library General Public24# License along with this library; if not, write to the25# Free Software Foundation, Inc., 59 Temple Place - Suite 330,26# Boston, MA 02111-1307, USA.27#28from regression import *29import random, os30try:31 open_evo ()32except:33 raise34data_object = LdtpDataFileParser (datafilename)35rows = data_object.gettagvalue ('rowcount')36evo_win = '*Evolution*'37pref = '*EvolutionPreferences'38acnt_tab = 'tblMailAccounts'39log ('getrowcount','teststart')40try:41 selectmenuitem (evo_win, 'mnuEdit;mnuPreferences')42 if waittillguiexist (pref) == 0:43 log ('Preferences Window not open yet','cause')44 raise LdtpExecutionError (str (traceback.format_exc ()))45 row_count = getrowcount (pref, acnt_tab)46 if rows != [] and rows != row_count:47 log ('No of rows does not match with input','cause')48 raise LdtpExecutionError (str (traceback.format_exc ()))49except:50 testfail ('getrowcount')51 raise LdtpExecutionError (str (traceback.format_exc ()))52testpass ('getrowcount')53acnts = []54log ('getcellvalue', 'teststart')55try:56 for index in range (row_count):57 val = getcellvalue (pref, acnt_tab, index, 1)58## http://bugzilla.gnome.org/show_bug.cgi?id=35222059# if verifytablecell (pref, acnt_tab, index, 1, val) == 0:60# log ('problem in getcellvalue','cause')61# raise LdtpExecutionError (str (traceback.format_exc ()))62 acnts.append (val)63except:64 testfail ('getcellvalue')65 raise LdtpExecutionError (str (traceback.format_exc ()))66testpass ('getcellvalue')67log ('selectrowindex','teststart')68try:69 for index in range (row_count):70 if selectrowindex (pref, acnt_tab, index) != 1:71 log ('Unable to select index','cause')72 raise LdtpExecutionError (str (traceback.format_exc ()))73 #time.sleep (1)74 if gettablerowindex (pref, acnt_tab, acnts[index]) != index:75 log ('Index not selected','cause')76 raise LdtpExecutionError (str (traceback.format_exc ()))77except:78 testfail ('selectrowindex')79 raise LdtpExecutionError (str (traceback.format_exc ()))80testpass ('selectrowindex')81log ('selectrow','teststart')82try:83 index = 084 for acnt in acnts:85 if doesrowexist (pref, acnt_tab, acnt) == 1 and selectrow (pref, acnt_tab, acnt) != 1:86 log ('Unable to select row','cause')87 raise LdtpExecutionError (str (traceback.format_exc ()))88 #time.sleep (1)89 if gettablerowindex (pref, acnt_tab, acnt) != index:90 log ('Index not selected','cause')91 raise LdtpExecutionError (str (traceback.format_exc ()))92 index += 193except:94 testfail ('selectrow')95 raise LdtpExecutionError (str (traceback.format_exc ()))96testpass ('selectrow')97log ('selectlastrow','teststart')98try:99 if selectlastrow (pref,acnt_tab) != 1:100 log ('selectlastrow failed','cause')101 raise LdtpExecutionError (str (traceback.format_exc ()))102 #time.sleep (1)103 if gettablerowindex (pref, acnt_tab, acnt) != (len (acnts)-1):104 log ('Index not selected','cause')105 raise LdtpExecutionError (str (traceback.format_exc ()))106except:107 testfail ('selectlastrow')108 raise LdtpExecutionError (str (traceback.format_exc ()))109testpass ('selectlastrow')110log ('checkrow','teststart')111try:112 for index in range (row_count):113 if uncheckrow (pref, acnt_tab, index) == 0:114 log ('Unable to uncheck row','cause')115 raise LdtpExecutionError (str (traceback.format_exc ()))116 #time.sleep (2)117 if checkrow (pref, acnt_tab, index) == 0:118 log ('Unable to check row','cause')119 raise LdtpExecutionError (str (traceback.format_exc ()))120except:121 testfail ('checkrow')122 raise LdtpExecutionError (str (traceback.format_exc ()))123testpass ('checkrow')...
modifycontactlist.py
Source:modifycontactlist.py
1#!/usr/bin/env python2#3# Linux Desktop Testing Project http://ldtp.freedesktop.org4#5# Author:6# Prashanth Mohan <prashmohan@gmail.com>7#8# Copyright 2004 Novell, Inc.9#10# This test script is free software; you can redistribute it and/or11# modify it under the terms of the GNU Library General Public12# License as published by the Free Software Foundation; either13# version 2 of the License, or (at your option) any later version.14#15# This library is distributed in the hope that it will be useful,16# but WITHOUT ANY WARRANTY; without even the implied warranty of17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU18# Library General Public License for more details.19#20# You should have received a copy of the GNU Library General Public21# License along with this library; if not, write to the22# Free Software Foundation, Inc., 59 Temple Place - Suite 330,23# Boston, MA 02111-1307, USA.24#25from contact import *26def modcontactlist(datafilename):27 log ('Modify Contact List','teststart')28 try:29 ListName,AddEmailAddresses,DelEmailAddresses=getmodlistvals(datafilename)30 name = '*'+ListName[0]+'*'31 opencontactlist(ListName)32 addtocontactlist (AddEmailAddresses, name)33 delfromcontactlist (DelEmailAddresses, name)34 click (name,'btnOK')35 time.sleep (2)36 verifymodifylist(ListName,AddEmailAddresses,DelEmailAddresses)37 except:38 log ('Unable to modify Contact List','error')39 log ('Modify Contact List','testend')40 raise LdtpExecutionError(0)41 log ('Modify Contact List','testend')42 43def addtocontactlist(addList, name):44 try:45 for val in range(len (addList)):46 settextvalue (name,'txtTypeanemailaddressordragacontactintothelistbelow',addList[val])47 print 'set the list value'48 click (name,'btnAdd')49 time.sleep (1)50 if guiexist ('dlgEvolutionQuery')==1:51 click ('dlgEvolutionQuery','btnCancel')52 time.sleep (1)53 except:54 log ('error while adding contacts to contact list','error')55 raise LdtpExecutionError(0)56def delfromcontactlist (remList, name):57 try:58 for val in range(len(remList)):59 try:60 selectrow (name,'tbl0',remList[val])61 except:62 log (remList[val]+' not in List','error')63 time.sleep (1)64 click (name,'btnRemove')65 time.sleep (1)66 except:67 log ('Contact could not be deleted from contact list','error')68 raise LdtpExecutionError(0)69def verifymodifylist(ListName,InEmail,OutEmail):70 try:71 opencontactlist(ListName)72 name = '*'+ListName[0]+'*'73 setcontext ('Contact List Editor',ListName[0])74 waittillguiexist (name)75 for value in InEmail:76 if (gettablerowindex (name,'tbl0',value)) == -1:77 raise LdtpExecutionError(0)78# print "values in inemail perfect"79# raw_input ("input")80# for value in OutEmail:81# if (gettablerowindex ('dlgContactListEditor','tbl0',EmailAddresses[val])) != -1:82# raise LdtpExecutionError(0)83 click (name,'btnCancel')84 except:85 log ('Contact List Modification has failed verification','error')86 raise LdtpExecutionError(0)87 ...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!