From c3fccbd34c9f1dbd975d2e8cd26ca52f7e817da8 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Thu, 9 Apr 2020 02:39:38 -0400 Subject: [PATCH] Update comments and add assert_raises() --- help_docs/method_summary.md | 2 ++ seleniumbase/fixtures/base_case.py | 34 ++++++++++++++++-------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/help_docs/method_summary.md b/help_docs/method_summary.md index 006db721..befa7c2d 100755 --- a/help_docs/method_summary.md +++ b/help_docs/method_summary.md @@ -268,6 +268,8 @@ self.assert_equal(first, second, msg=None) self.assert_not_equal(first, second, msg=None) +self.assert_raises(*args, **kwargs) + self.assert_title(title) self.assert_no_js_errors() diff --git a/seleniumbase/fixtures/base_case.py b/seleniumbase/fixtures/base_case.py index 130ee9bf..9eea03e1 100755 --- a/seleniumbase/fixtures/base_case.py +++ b/seleniumbase/fixtures/base_case.py @@ -2422,32 +2422,34 @@ class BaseCase(unittest.TestCase): self.driver, messenger_post, self.message_duration) def assert_true(self, expr, msg=None): + """ Asserts that the expression is True. + Will raise an exception if the statement if False. """ self.assertTrue(expr, msg=msg) - '''if self.demo_mode: - messenger_post = ("ASSERT TRUE (See code)") - js_utils.post_messenger_success_message( - self.driver, messenger_post, self.message_duration)''' def assert_false(self, expr, msg=None): + """ Asserts that the expression is False. + Will raise an exception if the statement if True. """ self.assertFalse(expr, msg=msg) - '''if self.demo_mode: - messenger_post = ("ASSERT FALSE (See code)") - js_utils.post_messenger_success_message( - self.driver, messenger_post, self.message_duration)''' def assert_equal(self, first, second, msg=None): + """ Asserts that the two values are equal. + Will raise an exception if the values are not equal. """ self.assertEqual(first, second, msg=msg) - '''if self.demo_mode: - messenger_post = ("ASSERT EQUAL: {%s == %s}" % (first, second)) - js_utils.post_messenger_success_message( - self.driver, messenger_post, self.message_duration)''' def assert_not_equal(self, first, second, msg=None): + """ Asserts that the two values are not equal. + Will raise an exception if the values are equal. """ self.assertNotEqual(first, second, msg=msg) - '''if self.demo_mode: - messenger_post = ("ASSERT NOT EQUAL: {%s != %s}" % (first, second)) - js_utils.post_messenger_success_message( - self.driver, messenger_post, self.message_duration)''' + + def assert_raises(self, *args, **kwargs): + """ Asserts that the following block of code raises an exception. + Will raise an exception if the block of code has no exception. + Usage Example => + # Verify that the expected exception is raised. + with self.assert_raises(Exception): + raise Exception("Expected Exception!") + """ + self.assertRaises(*args, **kwargs) def assert_title(self, title): """ Asserts that the web page title matches the expected title. """