Refactor link_text methods
This commit is contained in:
parent
004010d943
commit
70a083a028
|
@ -781,6 +781,8 @@ self.find_link_text(link_text, timeout=None)
|
|||
# self.wait_for_link_text_visible(link_text, timeout=None)
|
||||
|
||||
self.assert_link_text(link_text, timeout=None)
|
||||
# Duplicates:
|
||||
# self.assert_link(link_text, timeout=None)
|
||||
|
||||
############
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
""" SeleniumBase Exceptions
|
||||
LinkTextNotFoundException => Called when expected link text is not visible.
|
||||
NoSuchFileException => Called when self.assert_downloaded_file(...) fails.
|
||||
NoSuchOptionException => Called when select_option_by_*() lacks the option.
|
||||
NotConnectedException => Called when Internet is not reachable when needed.
|
||||
|
@ -6,13 +7,17 @@
|
|||
NotUsingChromiumException => Used by Chromium-only methods if not Chromium.
|
||||
OutOfScopeException => Used by BaseCase methods when setUp() is skipped.
|
||||
ProxyConnectionException => Called when the proxy connection failed.
|
||||
TextNotVisibleException => Called when expected text fails to appear.
|
||||
TextNotVisibleException => Called when the expected text is not visible.
|
||||
TimeLimitExceededException => Called when exceeding "--time-limit=SECONDS".
|
||||
TimeoutException => Called when some timeout limit has been exceeded.
|
||||
VisualException => Called when there's a Visual Diff Assertion Failure.
|
||||
"""
|
||||
|
||||
|
||||
class LinkTextNotFoundException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class NoSuchFileException(Exception):
|
||||
pass
|
||||
|
||||
|
|
|
@ -1450,9 +1450,8 @@ class BaseCase(unittest.TestCase):
|
|||
else:
|
||||
return None
|
||||
if hard_fail:
|
||||
raise Exception(
|
||||
"Partial Link text {%s} was not found!" % link_text
|
||||
)
|
||||
msg = "Partial Link text {%s} was not found!" % link_text
|
||||
page_actions.timeout_exception("LinkTextNotFoundException", msg)
|
||||
else:
|
||||
return None
|
||||
|
||||
|
@ -8200,6 +8199,15 @@ class BaseCase(unittest.TestCase):
|
|||
original_selector=original_selector,
|
||||
)
|
||||
|
||||
def assert_link(self, link_text, timeout=None):
|
||||
"""Same as self.assert_link_text()"""
|
||||
self.__check_scope()
|
||||
if not timeout:
|
||||
timeout = settings.SMALL_TIMEOUT
|
||||
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
|
||||
timeout = self.__get_new_timeout(timeout)
|
||||
self.assert_link_text(link_text, timeout=timeout)
|
||||
|
||||
def assert_element_not_present(
|
||||
self, selector, by="css selector", timeout=None
|
||||
):
|
||||
|
@ -9009,11 +9017,11 @@ class BaseCase(unittest.TestCase):
|
|||
if now_ms >= stop_ms:
|
||||
break
|
||||
time.sleep(0.2)
|
||||
message = "Link text {%s} was not present after %s seconds!" % (
|
||||
message = "Link text {%s} was not found after %s seconds!" % (
|
||||
link_text,
|
||||
timeout,
|
||||
)
|
||||
page_actions.timeout_exception("NoSuchElementException", message)
|
||||
page_actions.timeout_exception("LinkTextNotFoundException", message)
|
||||
|
||||
def wait_for_partial_link_text_present(self, link_text, timeout=None):
|
||||
self.__check_scope()
|
||||
|
@ -9035,10 +9043,10 @@ class BaseCase(unittest.TestCase):
|
|||
break
|
||||
time.sleep(0.2)
|
||||
message = (
|
||||
"Partial Link text {%s} was not present after %s seconds!"
|
||||
"Partial Link text {%s} was not found after %s seconds!"
|
||||
"" % (link_text, timeout)
|
||||
)
|
||||
page_actions.timeout_exception("NoSuchElementException", message)
|
||||
page_actions.timeout_exception("LinkTextNotFoundException", message)
|
||||
|
||||
def wait_for_link_text_visible(self, link_text, timeout=None):
|
||||
self.__check_scope()
|
||||
|
@ -13223,7 +13231,7 @@ class BaseCase(unittest.TestCase):
|
|||
text,
|
||||
selector,
|
||||
)
|
||||
page_actions.timeout_exception("ElementNotVisibleException", msg)
|
||||
page_actions.timeout_exception("TextNotVisibleException", msg)
|
||||
return True
|
||||
|
||||
def __wait_for_exact_shadow_text_visible(self, text, selector, timeout):
|
||||
|
@ -13242,7 +13250,7 @@ class BaseCase(unittest.TestCase):
|
|||
"" % (text, selector)
|
||||
)
|
||||
page_actions.timeout_exception(
|
||||
"ElementNotVisibleException", msg
|
||||
"TextNotVisibleException", msg
|
||||
)
|
||||
return True
|
||||
except Exception:
|
||||
|
|
|
@ -28,6 +28,7 @@ from selenium.common.exceptions import NoSuchElementException
|
|||
from selenium.common.exceptions import NoSuchWindowException
|
||||
from selenium.common.exceptions import StaleElementReferenceException
|
||||
from selenium.webdriver.common.action_chains import ActionChains
|
||||
from seleniumbase.common.exceptions import LinkTextNotFoundException
|
||||
from seleniumbase.common.exceptions import TextNotVisibleException
|
||||
from seleniumbase.config import settings
|
||||
from seleniumbase.fixtures import shared_utils
|
||||
|
@ -468,12 +469,12 @@ def wait_for_element_visible(
|
|||
)
|
||||
timeout_exception(ElementNotVisibleException, message)
|
||||
elif not element and by == "link text":
|
||||
message = "Link text {%s} was not visible after %s second%s!" % (
|
||||
message = "Link text {%s} was not found after %s second%s!" % (
|
||||
selector,
|
||||
timeout,
|
||||
plural,
|
||||
)
|
||||
timeout_exception(ElementNotVisibleException, message)
|
||||
timeout_exception(LinkTextNotFoundException, message)
|
||||
else:
|
||||
return element
|
||||
|
||||
|
@ -870,12 +871,12 @@ def wait_for_element_clickable(
|
|||
)
|
||||
timeout_exception(ElementNotInteractableException, message)
|
||||
elif not element and by == "link text" and not is_visible:
|
||||
message = "Link text {%s} was not visible after %s second%s!" % (
|
||||
message = "Link text {%s} was not found after %s second%s!" % (
|
||||
selector,
|
||||
timeout,
|
||||
plural,
|
||||
)
|
||||
timeout_exception(ElementNotVisibleException, message)
|
||||
timeout_exception(LinkTextNotFoundException, message)
|
||||
elif not element and by == "link text" and is_visible:
|
||||
message = "Link text {%s} was not clickable after %s second%s!" % (
|
||||
selector,
|
||||
|
|
|
@ -71,6 +71,7 @@ def format_exc(exception, message):
|
|||
from selenium.common.exceptions import NoSuchElementException
|
||||
from selenium.common.exceptions import NoSuchFrameException
|
||||
from selenium.common.exceptions import NoSuchWindowException
|
||||
from seleniumbase.common.exceptions import LinkTextNotFoundException
|
||||
from seleniumbase.common.exceptions import NoSuchFileException
|
||||
from seleniumbase.common.exceptions import NoSuchOptionException
|
||||
from seleniumbase.common.exceptions import TextNotVisibleException
|
||||
|
@ -83,6 +84,10 @@ def format_exc(exception, message):
|
|||
exc = exceptions.ElementNotVisibleException
|
||||
elif exception == "ElementNotVisibleException":
|
||||
exc = exceptions.ElementNotVisibleException
|
||||
elif exception == LinkTextNotFoundException:
|
||||
exc = exceptions.LinkTextNotFoundException
|
||||
elif exception == "LinkTextNotFoundException":
|
||||
exc = exceptions.LinkTextNotFoundException
|
||||
elif exception == NoSuchElementException:
|
||||
exc = exceptions.NoSuchElementException
|
||||
elif exception == "NoSuchElementException":
|
||||
|
|
Loading…
Reference in New Issue