How to use _internal_get_object_handle method in pyatom

Best Python code snippet using pyatom_python

utils.py

Source:utils.py Github

copy

Full Screen

...508 return window_obj509 def _get_object_handle(self, window_name, obj_name, obj_type=None,510 wait_for_object=True, force_remap=False):511 try:512 return self._internal_get_object_handle(window_name, obj_name,513 obj_type, wait_for_object,514 force_remap)515 except atomac._a11y.ErrorInvalidUIElement:516 # During the test, when the window closed and reopened517 # ErrorInvalidUIElement exception will be thrown518 self._windows={}519 # Call the method again, after updating apps520 return self._internal_get_object_handle(window_name, obj_name,521 obj_type, wait_for_object)522 def _internal_get_object_handle(self, window_name, obj_name, obj_type=None,523 wait_for_object=True, force_remap=False):524 try:525 obj=self._get_object_map(window_name, obj_name, obj_type,526 wait_for_object, force_remap)527 # Object might not exist, just check whether it exist528 object_handle=obj["obj"]529 # Look for Window's role, on stale windows this will530 # throw AttributeError exception, if so relookup windows531 # and search for the object532 object_handle.AXWindow.AXRole533 except (atomac._a11y.ErrorCannotComplete,534 atomac._a11y.ErrorUnsupported,535 atomac._a11y.ErrorInvalidUIElement, AttributeError):536 # During the test, when the window closed and reopened537 # ErrorCannotComplete exception will be thrown538 self._windows={}539 # Call the method again, after updating apps540 obj=self._get_object_map(window_name, obj_name, obj_type,541 wait_for_object, True)542 # Return object handle543 # FIXME: Check object validity before returning544 # if object state is invalid, then remap545 return obj["obj"]546 def _get_object_map(self, window_name, obj_name, obj_type=None,547 wait_for_object=True, force_remap=False):548 if not window_name:549 raise LdtpServerException("Unable to find window %s" % window_name)550 window_handle, ldtp_window_name, app=self._get_window_handle(window_name,551 wait_for_object)552 if not window_handle:553 raise LdtpServerException("Unable to find window %s" % window_name)554 strip=r"( |:|\.|_|\n)"555 if not isinstance(obj_name, unicode):556 # Convert to unicode string557 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=-1...

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