-
| Hello everyone! Can you tell me if SeleniumBase has a Soft Assertions implementation? | 
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
| Hello, and welcome. Yes, SeleniumBase deferred asserts allow you to make multiple assertions on the same page without failing the test after the first failed assert. Instead, you can choose when to process those assertions by calling:  Methods: self.deferred_assert_element(selector, by="css selector", timeout=None, fs=False)
# Duplicates:
# self.delayed_assert_element(selector, by="css selector", timeout=None, fs=False)
self.deferred_assert_element_present(selector, by="css selector", timeout=None, fs=False)
# Duplicates:
# self.delayed_assert_element_present(selector, by="css selector", timeout=None, fs=False)
self.deferred_assert_text(text, selector="html", by="css selector", timeout=None, fs=False)
# Duplicates:
# self.delayed_assert_text(text, selector="html", by="css selector", timeout=None, fs=False)
self.deferred_assert_exact_text(text, selector="html", by="css selector", timeout=None, fs=False)
# Duplicates:
# self.delayed_assert_exact_text(text, selector="html", by="css selector", timeout=None, fs=False)
self.process_deferred_asserts(print_only=False)
# Duplicates:
# self.process_delayed_asserts(print_only=False)If the  See the example test: examples/test_deferred_asserts.py """This test shows the use of SeleniumBase deferred asserts.
Deferred asserts won't raise exceptions from failures until
process_deferred_asserts() is called, or the test completes."""
import pytest
from seleniumbase import BaseCase
BaseCase.main(__name__, __file__)
class DeferredAssertTests(BaseCase):
    @pytest.mark.expected_failure
    def test_deferred_asserts(self):
        self.open("https://xkcd.com/993/")
        self.wait_for_element("#comic")
        print("\n(This test should fail)")
        self.deferred_assert_element('img[alt="Brand Identity"]')
        self.deferred_assert_element('img[alt="Rocket Ship"]')  # Will Fail
        self.deferred_assert_element("#comicmap")
        self.deferred_assert_text("Fake Item", "ul.comicNav")  # Will Fail
        self.deferred_assert_text("Random", "ul.comicNav")
        self.deferred_assert_element('a[name="Super Fake !!!"]')  # Will Fail
        self.deferred_assert_exact_text("Brand Identity", "#ctitle")
        self.deferred_assert_exact_text("Fake Food", "#comic")  # Will Fail
        self.process_deferred_asserts() | 
Beta Was this translation helpful? Give feedback.
Hello, and welcome. Yes, SeleniumBase deferred asserts allow you to make multiple assertions on the same page without failing the test after the first failed assert. Instead, you can choose when to process those assertions by calling:
self.process_deferred_asserts().Methods: