Best Python code snippet using SeleniumBase
test_deferred_asserts.py
Source:test_deferred_asserts.py
1"""2This test demonstrates the use of deferred asserts.3Deferred asserts won't raise exceptions from failures until either4process_deferred_asserts() is called, or the test reaches the tearDown() step.5Requires version 2.1.6 or newer for the deferred_assert_exact_text() method.6"""7import pytest8from seleniumbase import BaseCase9class DeferredAssertTests(BaseCase):10 @pytest.mark.expected_failure11 def test_deferred_asserts(self):12 self.open("https://xkcd.com/993/")13 self.wait_for_element("#comic")14 print("\n(This test should fail)")15 self.deferred_assert_element('img[alt="Brand Identity"]')16 self.deferred_assert_element('img[alt="Rocket Ship"]') # Will Fail17 self.deferred_assert_element("#comicmap")18 self.deferred_assert_text("Fake Item", "#middleContainer") # Will Fail19 self.deferred_assert_text("Random", "#middleContainer")20 self.deferred_assert_element('a[name="Super Fake !!!"]') # Will Fail21 self.deferred_assert_exact_text("Brand Identity", "#ctitle")22 self.deferred_assert_exact_text("Fake Food", "#comic") # Will Fail...
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!!