Best Python code snippet using pyatom_python
menu.py
Source:menu.py
...18import atomac19from utils import Utils20from server_exception import LdtpServerException21class Menu(Utils):22 def _get_menu_handle(self, window_name, object_name,23 wait_for_window=True):24 menu_list=re.split(";", object_name)25 # Call base class get_menu_handle26 try:27 menu_handle=Utils._get_menu_handle(self, window_name,28 menu_list[0], wait_for_window)29 except (atomac._a11y.ErrorCannotComplete, atomac._a11y.ErrorInvalidUIElement):30 # During the test, when the window closed and reopened31 # ErrorCannotComplete exception will be thrown32 self._windows={}33 # Call the method again, after updating apps34 menu_handle=Utils._get_menu_handle(self, window_name,35 menu_list[0], wait_for_window)36 if len(menu_list) <= 1:37 # If only first level menu is given, return the handle38 return menu_handle39 return self._internal_menu_handler(menu_handle, menu_list[1:])40 def selectmenuitem(self, window_name, object_name):41 """42 Select (click) a menu item.43 @param window_name: Window name to look for, either full name,44 LDTP's name convention, or a Unix glob.45 @type window_name: string46 @param object_name: Object name to look for, either full name,47 LDTP's name convention, or a Unix glob. Or menu heirarchy48 @type object_name: string49 @return: 1 on success.50 @rtype: integer51 """52 menu_handle=self._get_menu_handle(window_name, object_name)53 if not menu_handle.AXEnabled:54 raise LdtpServerException(u"Object %s state disabled" % object_name)55 menu_handle.Press()56 return 157 def doesmenuitemexist(self, window_name, object_name):58 """59 Check a menu item exist.60 @param window_name: Window name to look for, either full name,61 LDTP's name convention, or a Unix glob.62 @type window_name: string63 @param object_name: Object name to look for, either full name,64 LDTP's name convention, or a Unix glob. Or menu heirarchy65 @type object_name: string66 @param strict_hierarchy: Mandate menu hierarchy if set to True67 @type object_name: boolean68 @return: 1 on success.69 @rtype: integer70 """71 try:72 menu_handle=self._get_menu_handle(window_name, object_name,73 False)74 return 175 except LdtpServerException:76 return 077 def menuitemenabled(self, window_name, object_name):78 """79 Verify a menu item is enabled80 @param window_name: Window name to look for, either full name,81 LDTP's name convention, or a Unix glob.82 @type window_name: string83 @param object_name: Object name to look for, either full name,84 LDTP's name convention, or a Unix glob. Or menu heirarchy85 @type object_name: string86 @return: 1 on success.87 @rtype: integer88 """89 try:90 menu_handle=self._get_menu_handle(window_name, object_name,91 False)92 if menu_handle.AXEnabled:93 return 194 except LdtpServerException:95 pass96 return 097 def listsubmenus(self, window_name, object_name):98 """99 List children of menu item100 101 @param window_name: Window name to look for, either full name,102 LDTP's name convention, or a Unix glob.103 @type window_name: string104 @param object_name: Object name to look for, either full name,105 LDTP's name convention, or a Unix glob. Or menu heirarchy106 @type object_name: string107 @return: menu item in list on success.108 @rtype: list109 """110 menu_handle=self._get_menu_handle(window_name, object_name)111 role, label=self._ldtpize_accessible(menu_handle)112 menu_clicked=False113 try:114 if not menu_handle.AXChildren:115 menu_clicked=True116 try:117 menu_handle.Press()118 self.wait(1)119 except atomac._a11y.ErrorCannotComplete:120 pass121 if not menu_handle.AXChildren:122 raise LdtpServerException(u"Unable to find children under menu %s" % \123 label)124 children=menu_handle.AXChildren[0]125 sub_menus=[]126 for current_menu in children.AXChildren:127 role, label=self._ldtpize_accessible(current_menu)128 if not label:129 # All splitters have empty label130 continue131 sub_menus.append(u"%s%s" % (role, label))132 finally:133 if menu_clicked:134 menu_handle.Cancel()135 return sub_menus136 def verifymenucheck(self, window_name, object_name):137 """138 Verify a menu item is checked139 @param window_name: Window name to look for, either full name,140 LDTP's name convention, or a Unix glob.141 @type window_name: string142 @param object_name: Object name to look for, either full name,143 LDTP's name convention, or a Unix glob. Or menu heirarchy144 @type object_name: string145 @return: 1 on success.146 @rtype: integer147 """148 try:149 menu_handle=self._get_menu_handle(window_name, object_name,150 False)151 try:152 if menu_handle.AXMenuItemMarkChar:153 # Checked154 return 1155 except atomac._a11y.Error:156 pass157 except LdtpServerException:158 pass159 return 0160 def verifymenuuncheck(self, window_name, object_name):161 """162 Verify a menu item is un-checked163 @param window_name: Window name to look for, either full name,164 LDTP's name convention, or a Unix glob.165 @type window_name: string166 @param object_name: Object name to look for, either full name,167 LDTP's name convention, or a Unix glob. Or menu heirarchy168 @type object_name: string169 @return: 1 on success.170 @rtype: integer171 """172 try:173 menu_handle=self._get_menu_handle(window_name, object_name,174 False)175 try:176 if not menu_handle.AXMenuItemMarkChar:177 # Unchecked178 return 1179 except atomac._a11y.Error:180 return 1181 except LdtpServerException:182 pass183 return 0184 def menucheck(self, window_name, object_name):185 """186 Check (click) a menu item.187 @param window_name: Window name to look for, either full name,188 LDTP's name convention, or a Unix glob.189 @type window_name: string190 @param object_name: Object name to look for, either full name,191 LDTP's name convention, or a Unix glob. Or menu heirarchy192 @type object_name: string193 @return: 1 on success.194 @rtype: integer195 """196 menu_handle=self._get_menu_handle(window_name, object_name)197 if not menu_handle.AXEnabled:198 raise LdtpServerException(u"Object %s state disabled" % object_name)199 try:200 if menu_handle.AXMenuItemMarkChar:201 # Already checked202 return 1203 except atomac._a11y.Error:204 pass205 menu_handle.Press()206 return 1207 def menuuncheck(self, window_name, object_name):208 """209 Uncheck (click) a menu item.210 @param window_name: Window name to look for, either full name,211 LDTP's name convention, or a Unix glob.212 @type window_name: string213 @param object_name: Object name to look for, either full name,214 LDTP's name convention, or a Unix glob. Or menu heirarchy215 @type object_name: string216 @return: 1 on success.217 @rtype: integer218 """219 menu_handle=self._get_menu_handle(window_name, object_name)220 if not menu_handle.AXEnabled:221 raise LdtpServerException(u"Object %s state disabled" % object_name)222 try:223 if not menu_handle.AXMenuItemMarkChar:224 # Already unchecked225 return 1226 except atomac._a11y.Error:227 return 1228 menu_handle.Press()...
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!!