@@ -6737,6 +6737,85 @@ def assert_title_contains(self, substring):
6737
6737
self.__extra_actions.append(action)
6738
6738
return True
6739
6739
6740
+ def assert_url(self, url):
6741
+ """Asserts that the web page URL matches the expected URL."""
6742
+ self.wait_for_ready_state_complete()
6743
+ expected = url.strip()
6744
+ actual = self.get_current_url().strip()
6745
+ error = "Expected URL [%s] does not match the actual URL [%s]!"
6746
+ try:
6747
+ self.assertEqual(expected, actual, error % (expected, actual))
6748
+ except Exception:
6749
+ self.wait_for_ready_state_complete()
6750
+ time.sleep(2)
6751
+ actual = self.get_current_url().strip()
6752
+ try:
6753
+ self.assertEqual(expected, actual, error % (expected, actual))
6754
+ except Exception:
6755
+ self.wait_for_ready_state_complete()
6756
+ time.sleep(2)
6757
+ actual = self.get_current_url().strip()
6758
+ self.assertEqual(expected, actual, error % (expected, actual))
6759
+ if self.demo_mode and not self.recorder_mode:
6760
+ a_u = "ASSERT URL"
6761
+ if self._language != "English":
6762
+ from seleniumbase.fixtures.words import SD
6763
+
6764
+ a_u = SD.translate_assert_url(self._language)
6765
+ messenger_post = "<b>%s</b>: {%s}" % (a_u, expected)
6766
+ self.__highlight_with_assert_success(messenger_post, "html")
6767
+ if self.recorder_mode:
6768
+ url = self.get_current_url()
6769
+ if url and len(url) > 0:
6770
+ if ("http:") in url or ("https:") in url or ("file:") in url:
6771
+ if self.get_session_storage_item("pause_recorder") == "no":
6772
+ time_stamp = self.execute_script("return Date.now();")
6773
+ origin = self.get_origin()
6774
+ action = ["a_url", expected, origin, time_stamp]
6775
+ self.__extra_actions.append(action)
6776
+ return True
6777
+
6778
+ def assert_url_contains(self, substring):
6779
+ """Asserts that the URL substring appears in the full URL."""
6780
+ self.wait_for_ready_state_complete()
6781
+ expected = substring.strip()
6782
+ actual = self.get_current_url().strip()
6783
+ error = (
6784
+ "Expected URL substring [%s] does not appear "
6785
+ "in the full URL [%s]!"
6786
+ )
6787
+ try:
6788
+ self.assertIn(expected, actual, error % (expected, actual))
6789
+ except Exception:
6790
+ self.wait_for_ready_state_complete()
6791
+ time.sleep(2)
6792
+ actual = self.get_current_url().strip()
6793
+ try:
6794
+ self.assertIn(expected, actual, error % (expected, actual))
6795
+ except Exception:
6796
+ self.wait_for_ready_state_complete()
6797
+ time.sleep(2)
6798
+ actual = self.get_current_url().strip()
6799
+ self.assertIn(expected, actual, error % (expected, actual))
6800
+ if self.demo_mode and not self.recorder_mode:
6801
+ a_u = "ASSERT URL CONTAINS"
6802
+ if self._language != "English":
6803
+ from seleniumbase.fixtures.words import SD
6804
+
6805
+ a_u = SD.translate_assert_url_contains(self._language)
6806
+ messenger_post = "<b>%s</b>: {%s}" % (a_u, expected)
6807
+ self.__highlight_with_assert_success(messenger_post, "html")
6808
+ if self.recorder_mode:
6809
+ url = self.get_current_url()
6810
+ if url and len(url) > 0:
6811
+ if ("http:") in url or ("https:") in url or ("file:") in url:
6812
+ if self.get_session_storage_item("pause_recorder") == "no":
6813
+ time_stamp = self.execute_script("return Date.now();")
6814
+ origin = self.get_origin()
6815
+ action = ["a_u_c", expected, origin, time_stamp]
6816
+ self.__extra_actions.append(action)
6817
+ return True
6818
+
6740
6819
def assert_no_js_errors(self, exclude=[]):
6741
6820
"""Asserts current URL has no "SEVERE"-level JavaScript errors.
6742
6821
Works ONLY on Chromium browsers (Chrome or Edge).
0 commit comments