How to use __add_deferred_assert_failure method in SeleniumBase

Best Python code snippet using SeleniumBase

webdriver_test.py

Source:webdriver_test.py Github

copy

Full Screen

...5457 exc_message = exception_info.message5458 else:5459 exc_message = sys.exc_info()5460 return exc_message5461 def __add_deferred_assert_failure(self):5462 """ Add a deferred_assert failure to a list for future processing. """5463 self.__check_scope__()5464 current_url = self.driver.current_url5465 message = self.__get_exception_message()5466 self.__deferred_assert_failures.append(5467 "CHECK #%s: (%s) %s\n"5468 % (self.__deferred_assert_count, current_url, message)5469 )5470 ############5471 def deferred_assert_element(5472 self, selector, by=By.CSS_SELECTOR, timeout=None5473 ):5474 """A non-terminating assertion for an element on a page.5475 Failures will be saved until the process_deferred_asserts()5476 method is called from inside a test, likely at the end of it."""5477 self.__check_scope__()5478 timeout = self.get_timeout(timeout, constants.MINI_TIMEOUT)5479 self.__deferred_assert_count += 15480 try:5481 url = self.get_current_url()5482 if url == self.__last_url_of_deferred_assert:5483 timeout = 1 # Was already on page (full wait not needed)5484 else:5485 self.__last_url_of_deferred_assert = url5486 except Exception:5487 pass5488 try:5489 self.wait_for_element_visible(selector, by=by, timeout=timeout)5490 return True5491 except Exception:5492 self.__add_deferred_assert_failure()5493 return False5494 def deferred_assert_text(5495 self, text, selector="html", by=By.CSS_SELECTOR, timeout=None5496 ):5497 """A non-terminating assertion for text from an element on a page.5498 Failures will be saved until the process_deferred_asserts()5499 method is called from inside a test, likely at the end of it."""5500 self.__check_scope__()5501 timeout = self.get_timeout(timeout, constants.MINI_TIMEOUT)5502 self.__deferred_assert_count += 15503 try:5504 url = self.get_current_url()5505 if url == self.__last_url_of_deferred_assert:5506 timeout = 1 # Was already on page (full wait not needed)5507 else:5508 self.__last_url_of_deferred_assert = url5509 except Exception:5510 pass5511 try:5512 self.wait_for_text_visible(text, selector, by=by, timeout=timeout)5513 return True5514 except Exception:5515 self.__add_deferred_assert_failure()5516 return False5517 def deferred_assert_exact_text(5518 self, text, selector="html", by=By.CSS_SELECTOR, timeout=None5519 ):5520 """A non-terminating assertion for exact text from an element.5521 Failures will be saved until the process_deferred_asserts()5522 method is called from inside a test, likely at the end of it."""5523 self.__check_scope__()5524 timeout = self.get_timeout(timeout, constants.MINI_TIMEOUT)5525 self.__deferred_assert_count += 15526 try:5527 url = self.get_current_url()5528 if url == self.__last_url_of_deferred_assert:5529 timeout = 1 # Was already on page (full wait not needed)5530 else:5531 self.__last_url_of_deferred_assert = url5532 except Exception:5533 pass5534 try:5535 self.wait_for_exact_text_visible(5536 text, selector, by=by, timeout=timeout5537 )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 = ""...

Full Screen

Full Screen

base_case.py

Source:base_case.py Github

copy

Full Screen

...4413 "Or use: ``seleniumbase install chromedriver`` . "4414 "Original Exception Message: %s" % exc_message)4415 exc_message = update4416 return exc_message4417 def __add_deferred_assert_failure(self):4418 """ Add a deferred_assert failure to a list for future processing. """4419 current_url = self.driver.current_url4420 message = self.__get_exception_message()4421 self.__deferred_assert_failures.append(4422 "CHECK #%s: (%s)\n %s" % (4423 self.__deferred_assert_count, current_url, message))4424 ############4425 def deferred_assert_element(self, selector, by=By.CSS_SELECTOR,4426 timeout=None):4427 """ A non-terminating assertion for an element on a page.4428 Failures will be saved until the process_deferred_asserts()4429 method is called from inside a test, likely at the end of it. """4430 if not timeout:4431 timeout = settings.MINI_TIMEOUT4432 if self.timeout_multiplier and timeout == settings.MINI_TIMEOUT:4433 timeout = self.__get_new_timeout(timeout)4434 self.__deferred_assert_count += 14435 try:4436 url = self.get_current_url()4437 if url == self.__last_url_of_deferred_assert:4438 timeout = 14439 else:4440 self.__last_url_of_deferred_assert = url4441 except Exception:4442 pass4443 try:4444 self.wait_for_element_visible(selector, by=by, timeout=timeout)4445 return True4446 except Exception:4447 self.__add_deferred_assert_failure()4448 return False4449 def deferred_assert_text(self, text, selector="html", by=By.CSS_SELECTOR,4450 timeout=None):4451 """ A non-terminating assertion for text from an element on a page.4452 Failures will be saved until the process_deferred_asserts()4453 method is called from inside a test, likely at the end of it. """4454 if not timeout:4455 timeout = settings.MINI_TIMEOUT4456 if self.timeout_multiplier and timeout == settings.MINI_TIMEOUT:4457 timeout = self.__get_new_timeout(timeout)4458 self.__deferred_assert_count += 14459 try:4460 url = self.get_current_url()4461 if url == self.__last_url_of_deferred_assert:4462 timeout = 14463 else:4464 self.__last_url_of_deferred_assert = url4465 except Exception:4466 pass4467 try:4468 self.wait_for_text_visible(text, selector, by=by, timeout=timeout)4469 return True4470 except Exception:4471 self.__add_deferred_assert_failure()4472 return False4473 def process_deferred_asserts(self, print_only=False):4474 """ To be used with any test that uses deferred_asserts, which are4475 non-terminating verifications that only raise exceptions4476 after this method is called.4477 This is useful for pages with multiple elements to be checked when4478 you want to find as many bugs as possible in a single test run4479 before having all the exceptions get raised simultaneously.4480 Might be more useful if this method is called after processing all4481 the deferred asserts on a single html page so that the failure4482 screenshot matches the location of the deferred asserts.4483 If "print_only" is set to True, the exception won't get raised. """4484 if self.__deferred_assert_failures:4485 exception_output = ''...

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 SeleniumBase 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