Add method: assert_title_contains(substring)
This commit is contained in:
parent
900cb3e3cc
commit
e085517c29
|
@ -458,6 +458,8 @@ self.assert_attribute(
|
||||||
|
|
||||||
self.assert_title(title)
|
self.assert_title(title)
|
||||||
|
|
||||||
|
self.assert_title_contains(substring)
|
||||||
|
|
||||||
self.assert_no_js_errors()
|
self.assert_no_js_errors()
|
||||||
|
|
||||||
self.inspect_html()
|
self.inspect_html()
|
||||||
|
|
|
@ -604,3 +604,11 @@ def assert_text_not_visible(context, text):
|
||||||
sb = context.sb
|
sb = context.sb
|
||||||
text = normalize_text(text)
|
text = normalize_text(text)
|
||||||
sb.assert_text_not_visible(text)
|
sb.assert_text_not_visible(text)
|
||||||
|
|
||||||
|
|
||||||
|
@step("Assert title contains '{substring}'")
|
||||||
|
@step('Assert title contains "{substring}"')
|
||||||
|
def assert_title_contains(context, substring):
|
||||||
|
sb = context.sb
|
||||||
|
substring = normalize_text(substring)
|
||||||
|
sb.assert_title_contains(substring)
|
||||||
|
|
|
@ -244,6 +244,12 @@ def generate_gherkin(srt_actions):
|
||||||
sb_actions.append('%s "%s"' % (method, action[1]))
|
sb_actions.append('%s "%s"' % (method, action[1]))
|
||||||
else:
|
else:
|
||||||
sb_actions.append("%s '%s'" % (method, action[1]))
|
sb_actions.append("%s '%s'" % (method, action[1]))
|
||||||
|
elif action[0] == "as_tc":
|
||||||
|
method = "Assert title contains"
|
||||||
|
if '"' not in action[1]:
|
||||||
|
sb_actions.append('%s "%s"' % (method, action[1]))
|
||||||
|
else:
|
||||||
|
sb_actions.append("%s '%s'" % (method, action[1]))
|
||||||
elif action[0] == "as_df":
|
elif action[0] == "as_df":
|
||||||
method = "Assert downloaded file"
|
method = "Assert downloaded file"
|
||||||
if '"' not in action[1]:
|
if '"' not in action[1]:
|
||||||
|
|
|
@ -4075,6 +4075,7 @@ class BaseCase(unittest.TestCase):
|
||||||
ext_actions.append("hi_li")
|
ext_actions.append("hi_li")
|
||||||
ext_actions.append("as_lt")
|
ext_actions.append("as_lt")
|
||||||
ext_actions.append("as_ti")
|
ext_actions.append("as_ti")
|
||||||
|
ext_actions.append("as_tc")
|
||||||
ext_actions.append("as_df")
|
ext_actions.append("as_df")
|
||||||
ext_actions.append("do_fi")
|
ext_actions.append("do_fi")
|
||||||
ext_actions.append("as_at")
|
ext_actions.append("as_at")
|
||||||
|
@ -4406,6 +4407,12 @@ class BaseCase(unittest.TestCase):
|
||||||
sb_actions.append('self.%s("%s")' % (method, action[1]))
|
sb_actions.append('self.%s("%s")' % (method, action[1]))
|
||||||
else:
|
else:
|
||||||
sb_actions.append("self.%s('%s')" % (method, action[1]))
|
sb_actions.append("self.%s('%s')" % (method, action[1]))
|
||||||
|
elif action[0] == "as_tc":
|
||||||
|
method = "assert_title_contains"
|
||||||
|
if '"' not in action[1]:
|
||||||
|
sb_actions.append('self.%s("%s")' % (method, action[1]))
|
||||||
|
else:
|
||||||
|
sb_actions.append("self.%s('%s')" % (method, action[1]))
|
||||||
elif action[0] == "as_df":
|
elif action[0] == "as_df":
|
||||||
method = "assert_downloaded_file"
|
method = "assert_downloaded_file"
|
||||||
if '"' not in action[1]:
|
if '"' not in action[1]:
|
||||||
|
@ -6354,7 +6361,7 @@ class BaseCase(unittest.TestCase):
|
||||||
from seleniumbase.fixtures.words import SD
|
from seleniumbase.fixtures.words import SD
|
||||||
|
|
||||||
a_t = SD.translate_assert_title(self._language)
|
a_t = SD.translate_assert_title(self._language)
|
||||||
messenger_post = "%s: {%s}" % (a_t, title)
|
messenger_post = "%s: {%s}" % (a_t, expected)
|
||||||
self.__highlight_with_assert_success(messenger_post, "html")
|
self.__highlight_with_assert_success(messenger_post, "html")
|
||||||
if self.recorder_mode:
|
if self.recorder_mode:
|
||||||
url = self.get_current_url()
|
url = self.get_current_url()
|
||||||
|
@ -6363,7 +6370,50 @@ class BaseCase(unittest.TestCase):
|
||||||
if self.get_session_storage_item("pause_recorder") == "no":
|
if self.get_session_storage_item("pause_recorder") == "no":
|
||||||
time_stamp = self.execute_script("return Date.now();")
|
time_stamp = self.execute_script("return Date.now();")
|
||||||
origin = self.get_origin()
|
origin = self.get_origin()
|
||||||
action = ["as_ti", title, origin, time_stamp]
|
action = ["as_ti", expected, origin, time_stamp]
|
||||||
|
self.__extra_actions.append(action)
|
||||||
|
return True
|
||||||
|
|
||||||
|
def assert_title_contains(self, substring):
|
||||||
|
"""Asserts that the title substring appears in the web page title.
|
||||||
|
When a web page initially loads, the title starts as the URL,
|
||||||
|
but then the title switches over to the actual page title.
|
||||||
|
In Recorder Mode, this assertion is skipped because the Recorder
|
||||||
|
changes the page title to the selector of the hovered element.
|
||||||
|
"""
|
||||||
|
self.wait_for_ready_state_complete()
|
||||||
|
expected = substring.strip()
|
||||||
|
actual = self.get_page_title().strip()
|
||||||
|
error = (
|
||||||
|
"Expected title substring [%s] does not appear "
|
||||||
|
"in the actual page title [%s]!"
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
if not self.recorder_mode:
|
||||||
|
self.assertIn(expected, actual, error % (expected, actual))
|
||||||
|
except Exception:
|
||||||
|
self.wait_for_ready_state_complete()
|
||||||
|
time.sleep(2)
|
||||||
|
actual = self.get_page_title().strip()
|
||||||
|
try:
|
||||||
|
self.assertIn(expected, actual, error % (expected, actual))
|
||||||
|
except Exception:
|
||||||
|
self.wait_for_ready_state_complete()
|
||||||
|
time.sleep(2)
|
||||||
|
actual = self.get_page_title().strip()
|
||||||
|
self.assertIn(expected, actual, error % (expected, actual))
|
||||||
|
if self.demo_mode and not self.recorder_mode:
|
||||||
|
a_t = "ASSERT TITLE CONTAINS"
|
||||||
|
messenger_post = "%s: {%s}" % (a_t, expected)
|
||||||
|
self.__highlight_with_assert_success(messenger_post, "html")
|
||||||
|
if self.recorder_mode:
|
||||||
|
url = self.get_current_url()
|
||||||
|
if url and len(url) > 0:
|
||||||
|
if ("http:") in url or ("https:") in url or ("file:") in url:
|
||||||
|
if self.get_session_storage_item("pause_recorder") == "no":
|
||||||
|
time_stamp = self.execute_script("return Date.now();")
|
||||||
|
origin = self.get_origin()
|
||||||
|
action = ["as_tc", expected, origin, time_stamp]
|
||||||
self.__extra_actions.append(action)
|
self.__extra_actions.append(action)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue