Best Python code snippet using SeleniumBase
webdriver_test.py
Source:webdriver_test.py
...5538 return True5539 except Exception:5540 self.__add_deferred_assert_failure()5541 return False5542 def deferred_check_window(5543 self,5544 name="default",5545 level=0,5546 baseline=False,5547 check_domain=True,5548 full_diff=False,5549 ):5550 """A non-terminating assertion for the check_window() method.5551 Failures will be saved until the process_deferred_asserts()5552 method is called from inside a test, likely at the end of it."""5553 self.__check_scope__()5554 self.__deferred_assert_count += 15555 try:5556 self.check_window(5557 name=name,5558 level=level,5559 baseline=baseline,5560 check_domain=check_domain,5561 full_diff=full_diff,5562 )5563 return True5564 except Exception:5565 self.__add_deferred_assert_failure()5566 return False5567 def process_deferred_asserts(self, print_only=False):5568 """To be used with any test that uses deferred_asserts, which are5569 non-terminating verifications that only raise exceptions5570 after this method is called.5571 This is useful for pages with multiple elements to be checked when5572 you want to find as many bugs as possible in a single test run5573 before having all the exceptions get raised simultaneously.5574 Might be more useful if this method is called after processing all5575 the deferred asserts on a single html page so that the failure5576 screenshot matches the location of the deferred asserts.5577 If "print_only" is set to True, the exception won't get raised."""5578 if self.__deferred_assert_failures:5579 exception_output = ""5580 exception_output += "\n***** DEFERRED ASSERTION FAILURES:\n"5581 exception_output += "TEST: %s\n\n" % self.id()5582 all_failing_checks = self.__deferred_assert_failures5583 self.__deferred_assert_failures = []5584 for tb in all_failing_checks:5585 exception_output += "%s\n" % tb5586 if print_only:5587 print(exception_output)5588 else:5589 raise Exception(exception_output.replace("\\n", "\n"))5590 ############5591 # Alternate naming scheme for the "deferred_assert" methods.5592 def delayed_assert_element(5593 self, selector, by=By.CSS_SELECTOR, timeout=None5594 ):5595 """ Same as self.deferred_assert_element() """5596 return self.deferred_assert_element(5597 selector=selector, by=by, timeout=timeout5598 )5599 def delayed_assert_text(5600 self, text, selector="html", by=By.CSS_SELECTOR, timeout=None5601 ):5602 """ Same as self.deferred_assert_text() """5603 return self.deferred_assert_text(5604 text=text, selector=selector, by=by, timeout=timeout5605 )5606 def delayed_assert_exact_text(5607 self, text, selector="html", by=By.CSS_SELECTOR, timeout=None5608 ):5609 """ Same as self.deferred_assert_exact_text() """5610 return self.deferred_assert_exact_text(5611 text=text, selector=selector, by=by, timeout=timeout5612 )5613 def delayed_check_window(5614 self,5615 name="default",5616 level=0,5617 baseline=False,5618 check_domain=True,5619 full_diff=False5620 ):5621 """ Same as self.deferred_check_window() """5622 return self.deferred_check_window(5623 name=name,5624 level=level,5625 baseline=baseline,5626 check_domain=check_domain,5627 full_diff=full_diff,5628 )5629 def process_delayed_asserts(self, print_only=False):5630 """ Same as self.process_deferred_asserts() """5631 self.process_deferred_asserts(print_only=print_only)5632 ############5633 def __js_click(self, selector, by=By.CSS_SELECTOR):5634 """ Clicks an element using pure JS. Does not use jQuery. """5635 selector, by = self.__recalculate_selector(selector, by)5636 css_selector = self.convert_to_css_selector(selector, by=by)...
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!!