How to use _get_appmap method in pyatom

Best Python code snippet using pyatom_python

utils.py

Source:utils.py Github

copy

Full Screen

...557 obj_name=u"%s" % obj_name558 stripped_obj_name=re.sub(strip, u"", obj_name)559 obj_name=fnmatch.translate(obj_name)560 stripped_obj_name=fnmatch.translate(stripped_obj_name)561 object_list=self._get_appmap(window_handle, ldtp_window_name, force_remap)562 def _internal_get_object_handle(object_list):563 # To handle retry this function has been introduced564 for obj in object_list:565 if obj_type and object_list[obj]["class"] != obj_type:566 # If object type is provided and doesn't match567 # don't proceed further, just continue searching568 # next element, even though the label matches569 continue570 label=object_list[obj]["label"]571 strip=r"( |:|\.|_|\n)"572 if not isinstance(label, unicode):573 # Convert to unicode string574 label=u"%s" % label575 stripped_label=re.sub(strip, u"", label)576 # FIXME: Find object name in LDTP format577 if re.match(obj_name, obj) or re.match(obj_name, label) or \578 re.match(obj_name, stripped_label) or \579 re.match(stripped_obj_name, obj) or \580 re.match(stripped_obj_name, label) or \581 re.match(stripped_obj_name, stripped_label):582 # Return object map583 return object_list[obj]584 if wait_for_object:585 obj_timeout=self._obj_timeout586 else:587 # don't wait for the object 588 obj_timeout=1589 for retry in range(0, obj_timeout):590 obj=_internal_get_object_handle(object_list)591 if obj:592 # If object found, return immediately593 return obj594 if obj_timeout <= 1:595 # Don't wait for the object596 break597 time.sleep(1)598 # Force remap599 object_list=self._get_appmap(window_handle,600 ldtp_window_name, True)601 # print(object_list)602 raise LdtpServerException("Unable to find object %s" % obj_name)603 def _populate_appmap(self, obj_dict, obj, parent, child_index):604 index=-1605 if obj:606 if child_index != -1:607 parent=self._insert_obj(obj_dict, obj, parent, child_index)608 try:609 if not obj.AXChildren:610 return611 except atomac._a11y.Error:612 return613 for child in obj.AXChildren:614 index += 1615 if not child:616 continue617 self._populate_appmap(obj_dict, child, parent, index)618 def _get_appmap(self, window_handle, window_name, force_remap=False):619 if not window_handle or not window_name:620 # If invalid argument return empty dict621 return {}622 if not force_remap and self._appmap.has_key(window_name):623 # If available in cache then use that624 # unless remap is forced625 return self._appmap[window_name]626 obj_dict={}627 self._ldtpized_obj_index={}628 # Populate the appmap and cache it629 self._populate_appmap(obj_dict, window_handle, "", -1)630 # Cache the object dictionary631 self._appmap[window_name]=obj_dict632 return obj_dict633 def _get_menu_handle(self, window_name, object_name,634 wait_for_window=True):635 window_handle, name, app=self._get_window_handle(window_name,636 wait_for_window)637 if not window_handle:638 raise LdtpServerException("Unable to find window %s" % window_name)639 # pyatom doesn't understand LDTP convention mnu, strip it off640 menu=re.sub("mnu", "", object_name)641 if re.match("^\d", menu):642 obj_dict=self._get_appmap(window_handle, name)643 return obj_dict[object_name]["obj"]644 menu_handle=app.menuItem(menu)645 if menu_handle:646 return menu_handle647 # Above one looks for menubar item648 # Following looks for menuitem inside the window649 menu_handle_list=window_handle.findAllR(AXRole="AXMenu")650 for menu_handle in menu_handle_list:651 sub_menu_handle=self._get_sub_menu_handle(menu_handle, object_name)652 if sub_menu_handle:653 return sub_menu_handle654 raise LdtpServerException("Unable to find menu %s" % object_name)655 def _get_sub_menu_handle(self, children, menu):656 strip=r"( |:|\.|_|\n)"...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pyatom automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful