@@ -4315,6 +4315,8 @@ def __process_recorded_actions(self):
43154315 ext_actions.append("as_lt")
43164316 ext_actions.append("as_ti")
43174317 ext_actions.append("as_tc")
4318+ ext_actions.append("a_url")
4319+ ext_actions.append("a_u_c")
43184320 ext_actions.append("as_df")
43194321 ext_actions.append("do_fi")
43204322 ext_actions.append("as_at")
@@ -4669,6 +4671,18 @@ def __process_recorded_actions(self):
46694671 sb_actions.append('self.%s("%s")' % (method, action[1]))
46704672 else:
46714673 sb_actions.append("self.%s('%s')" % (method, action[1]))
4674+ elif action[0] == "a_url":
4675+ method = "assert_url"
4676+ if '"' not in action[1]:
4677+ sb_actions.append('self.%s("%s")' % (method, action[1]))
4678+ else:
4679+ sb_actions.append("self.%s('%s')" % (method, action[1]))
4680+ elif action[0] == "a_u_c":
4681+ method = "assert_url_contains"
4682+ if '"' not in action[1]:
4683+ sb_actions.append('self.%s("%s")' % (method, action[1]))
4684+ else:
4685+ sb_actions.append("self.%s('%s')" % (method, action[1]))
46724686 elif action[0] == "as_df":
46734687 method = "assert_downloaded_file"
46744688 if '"' not in action[1]:
@@ -6724,6 +6738,10 @@ def assert_title_contains(self, substring):
67246738 self.assertIn(expected, actual, error % (expected, actual))
67256739 if self.demo_mode and not self.recorder_mode:
67266740 a_t = "ASSERT TITLE CONTAINS"
6741+ if self._language != "English":
6742+ from seleniumbase.fixtures.words import SD
6743+
6744+ a_t = SD.translate_assert_title_contains(self._language)
67276745 messenger_post = "<b>%s</b>: {%s}" % (a_t, expected)
67286746 self.__highlight_with_assert_success(messenger_post, "html")
67296747 if self.recorder_mode:
@@ -6737,6 +6755,85 @@ def assert_title_contains(self, substring):
67376755 self.__extra_actions.append(action)
67386756 return True
67396757
6758+ def assert_url(self, url):
6759+ """Asserts that the web page URL matches the expected URL."""
6760+ self.wait_for_ready_state_complete()
6761+ expected = url.strip()
6762+ actual = self.get_current_url().strip()
6763+ error = "Expected URL [%s] does not match the actual URL [%s]!"
6764+ try:
6765+ self.assertEqual(expected, actual, error % (expected, actual))
6766+ except Exception:
6767+ self.wait_for_ready_state_complete()
6768+ time.sleep(2)
6769+ actual = self.get_current_url().strip()
6770+ try:
6771+ self.assertEqual(expected, actual, error % (expected, actual))
6772+ except Exception:
6773+ self.wait_for_ready_state_complete()
6774+ time.sleep(2)
6775+ actual = self.get_current_url().strip()
6776+ self.assertEqual(expected, actual, error % (expected, actual))
6777+ if self.demo_mode and not self.recorder_mode:
6778+ a_u = "ASSERT URL"
6779+ if self._language != "English":
6780+ from seleniumbase.fixtures.words import SD
6781+
6782+ a_u = SD.translate_assert_url(self._language)
6783+ messenger_post = "<b>%s</b>: {%s}" % (a_u, expected)
6784+ self.__highlight_with_assert_success(messenger_post, "html")
6785+ if self.recorder_mode:
6786+ url = self.get_current_url()
6787+ if url and len(url) > 0:
6788+ if ("http:") in url or ("https:") in url or ("file:") in url:
6789+ if self.get_session_storage_item("pause_recorder") == "no":
6790+ time_stamp = self.execute_script("return Date.now();")
6791+ origin = self.get_origin()
6792+ action = ["a_url", expected, origin, time_stamp]
6793+ self.__extra_actions.append(action)
6794+ return True
6795+
6796+ def assert_url_contains(self, substring):
6797+ """Asserts that the URL substring appears in the full URL."""
6798+ self.wait_for_ready_state_complete()
6799+ expected = substring.strip()
6800+ actual = self.get_current_url().strip()
6801+ error = (
6802+ "Expected URL substring [%s] does not appear "
6803+ "in the full URL [%s]!"
6804+ )
6805+ try:
6806+ self.assertIn(expected, actual, error % (expected, actual))
6807+ except Exception:
6808+ self.wait_for_ready_state_complete()
6809+ time.sleep(2)
6810+ actual = self.get_current_url().strip()
6811+ try:
6812+ self.assertIn(expected, actual, error % (expected, actual))
6813+ except Exception:
6814+ self.wait_for_ready_state_complete()
6815+ time.sleep(2)
6816+ actual = self.get_current_url().strip()
6817+ self.assertIn(expected, actual, error % (expected, actual))
6818+ if self.demo_mode and not self.recorder_mode:
6819+ a_u = "ASSERT URL CONTAINS"
6820+ if self._language != "English":
6821+ from seleniumbase.fixtures.words import SD
6822+
6823+ a_u = SD.translate_assert_url_contains(self._language)
6824+ messenger_post = "<b>%s</b>: {%s}" % (a_u, expected)
6825+ self.__highlight_with_assert_success(messenger_post, "html")
6826+ if self.recorder_mode:
6827+ url = self.get_current_url()
6828+ if url and len(url) > 0:
6829+ if ("http:") in url or ("https:") in url or ("file:") in url:
6830+ if self.get_session_storage_item("pause_recorder") == "no":
6831+ time_stamp = self.execute_script("return Date.now();")
6832+ origin = self.get_origin()
6833+ action = ["a_u_c", expected, origin, time_stamp]
6834+ self.__extra_actions.append(action)
6835+ return True
6836+
67406837 def assert_no_js_errors(self, exclude=[]):
67416838 """Asserts current URL has no "SEVERE"-level JavaScript errors.
67426839 Works ONLY on Chromium browsers (Chrome or Edge).
0 commit comments