Merge pull request #379 from seleniumbase/update-requirements-and-methods

Update requirements and methods
This commit is contained in:
Michael Mintz 2019-09-22 04:04:59 -04:00 committed by GitHub
commit a5826f63c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 89 additions and 38 deletions

View File

@ -411,6 +411,14 @@ self.assert_element_not_visible(selector, by=By.CSS_SELECTOR,
########
self.wait_for_text_not_visible(text, selector="html", by=By.CSS_SELECTOR,
timeout=settings.LARGE_TIMEOUT)
self.assert_text_not_visible(text, selector="html", by=By.CSS_SELECTOR,
timeout=settings.SMALL_TIMEOUT)
########
self.wait_for_and_accept_alert(timeout=settings.LARGE_TIMEOUT)
self.wait_for_and_dismiss_alert(timeout=settings.LARGE_TIMEOUT)

View File

@ -11,7 +11,7 @@ requests>=2.22.0
selenium==3.141.0
pluggy>=0.12.0
pytest>=4.6.5;python_version<"3"
pytest>=5.1.2;python_version>="3"
pytest>=5.1.3;python_version>="3"
pytest-cov>=2.7.1
pytest-forked>=1.0.2
pytest-html==1.22.0

View File

@ -178,14 +178,13 @@ def _create_firefox_profile(
profile.set_preference("pdfjs.disabled", True)
profile.set_preference("app.update.auto", False)
profile.set_preference("app.update.enabled", False)
profile.set_preference("extensions.update.enabled", False)
profile.set_preference("browser.privatebrowsing.autostart", True)
profile.set_preference("devtools.errorconsole.enabled", True)
profile.set_preference("extensions.allowPrivateBrowsingByDefault", True)
profile.set_preference("extensions.PrivateBrowsing.notification", False)
profile.set_preference("extensions.systemAddon.update.enabled", False)
profile.set_preference("extensions.update.autoUpdateDefault", False)
profile.set_preference("extensions.update.enabled", False)
profile.set_preference("devtools.errorconsole.enabled", True)
profile.set_preference(
"datareporting.healthreport.logging.consoleEnabled", False)
profile.set_preference("datareporting.healthreport.service.enabled", False)
@ -195,6 +194,7 @@ def _create_firefox_profile(
profile.set_preference("datareporting.policy.dataSubmissionEnabled", False)
profile.set_preference(
"datareporting.policy.dataSubmissionPolicyAccepted", False)
profile.set_preference("toolkit.telemetry.unified", False)
if proxy_string:
proxy_server = proxy_string.split(':')[0]
proxy_port = proxy_string.split(':')[1]

View File

@ -2884,6 +2884,27 @@ class BaseCase(unittest.TestCase):
############
def wait_for_text_not_visible(self, text, selector="html",
by=By.CSS_SELECTOR,
timeout=settings.LARGE_TIMEOUT):
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
timeout = self.__get_new_timeout(timeout)
selector, by = self.__recalculate_selector(selector, by)
return page_actions.wait_for_text_not_visible(
self.driver, text, selector, by, timeout)
def assert_text_not_visible(self, text, selector="html",
by=By.CSS_SELECTOR,
timeout=settings.SMALL_TIMEOUT):
""" Similar to wait_for_text_not_visible()
Raises an exception if the element or the text is not found.
Returns True if successful. Default timeout = SMALL_TIMEOUT. """
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
timeout = self.__get_new_timeout(timeout)
self.wait_for_text_not_visible(text, selector, by=by, timeout=timeout)
############
def wait_for_and_accept_alert(self, timeout=settings.LARGE_TIMEOUT):
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
timeout = self.__get_new_timeout(timeout)

View File

@ -39,8 +39,8 @@ def is_element_present(driver, selector, by=By.CSS_SELECTOR):
Returns whether the specified element selector is present on the page.
@Params
driver - the webdriver object (required)
selector - the locator that is used (required)
by - the method to search for the locator (Default: By.CSS_SELECTOR)
selector - the locator for identifying the page element (required)
by - the type of selector being used (Default: By.CSS_SELECTOR)
@Returns
Boolean (is element present)
"""
@ -56,8 +56,8 @@ def is_element_visible(driver, selector, by=By.CSS_SELECTOR):
Returns whether the specified element selector is visible on the page.
@Params
driver - the webdriver object (required)
selector - the locator that is used (required)
by - the method to search for the locator (Default: By.CSS_SELECTOR)
selector - the locator for identifying the page element (required)
by - the type of selector being used (Default: By.CSS_SELECTOR)
@Returns
Boolean (is element visible)
"""
@ -74,8 +74,8 @@ def is_text_visible(driver, text, selector, by=By.CSS_SELECTOR):
@Params
driver - the webdriver object (required)
text - the text string to search for
selector - the locator that is used (required)
by - the method to search for the locator (Default: By.CSS_SELECTOR)
selector - the locator for identifying the page element (required)
by - the type of selector being used (Default: By.CSS_SELECTOR)
@Returns
Boolean (is text visible)
"""
@ -91,8 +91,8 @@ def hover_on_element(driver, selector, by=By.CSS_SELECTOR):
Fires the hover event for the specified element by the given selector.
@Params
driver - the webdriver object (required)
selector - the locator (css selector) that is used (required)
by - the method to search for the locator (Default: By.CSS_SELECTOR)
selector - the locator for identifying the page element (required)
by - the type of selector being used (Default: By.CSS_SELECTOR)
"""
element = driver.find_element(by=by, value=selector)
hover = ActionChains(driver).move_to_element(element)
@ -117,8 +117,8 @@ def hover_and_click(driver, hover_selector, click_selector,
driver - the webdriver object (required)
hover_selector - the css selector to hover over (required)
click_selector - the css selector to click on (required)
hover_by - the method to search by (Default: By.CSS_SELECTOR)
click_by - the method to search by (Default: By.CSS_SELECTOR)
hover_by - the hover selector type to search by (Default: By.CSS_SELECTOR)
click_by - the click selector type to search by (Default: By.CSS_SELECTOR)
timeout - number of seconds to wait for click element to appear after hover
"""
start_ms = time.time() * 1000.0
@ -200,13 +200,12 @@ def wait_for_element_present(driver, selector, by=By.CSS_SELECTOR,
specified timeout.
@Params
driver - the webdriver object
selector - the locator that is used (required)
by - the method to search for the locator (Default: By.CSS_SELECTOR)
selector - the locator for identifying the page element (required)
by - the type of selector being used (Default: By.CSS_SELECTOR)
timeout - the time to wait for elements in seconds
@Returns
A web element object
"""
element = None
start_ms = time.time() * 1000.0
stop_ms = start_ms + (timeout * 1000.0)
@ -234,14 +233,13 @@ def wait_for_element_visible(driver, selector, by=By.CSS_SELECTOR,
specified timeout.
@Params
driver - the webdriver object (required)
selector - the locator that is used (required)
by - the method to search for the locator (Default: By.CSS_SELECTOR)
selector - the locator for identifying the page element (required)
by - the type of selector being used (Default: By.CSS_SELECTOR)
timeout - the time to wait for elements in seconds
@Returns
A web element object
"""
element = None
start_ms = time.time() * 1000.0
stop_ms = start_ms + (timeout * 1000.0)
@ -281,13 +279,12 @@ def wait_for_text_visible(driver, text, selector, by=By.CSS_SELECTOR,
@Params
driver - the webdriver object (required)
text - the text that is being searched for in the element (required)
selector - the locator that is used (required)
by - the method to search for the locator (Default: By.CSS_SELECTOR)
selector - the locator for identifying the page element (required)
by - the type of selector being used (Default: By.CSS_SELECTOR)
timeout - the time to wait for elements in seconds
@Returns
A web element object that contains the text searched for
"""
element = None
start_ms = time.time() * 1000.0
stop_ms = start_ms + (timeout * 1000.0)
@ -324,13 +321,12 @@ def wait_for_exact_text_visible(driver, text, selector, by=By.CSS_SELECTOR,
@Params
driver - the webdriver object (required)
text - the exact text that is expected for the element (required)
selector - the locator that is used (required)
by - the method to search for the locator (Default: By.CSS_SELECTOR)
selector - the locator for identifying the page element (required)
by - the type of selector being used (Default: By.CSS_SELECTOR)
timeout - the time to wait for elements in seconds
@Returns
A web element object that contains the text searched for
"""
element = None
start_ms = time.time() * 1000.0
stop_ms = start_ms + (timeout * 1000.0)
@ -364,11 +360,10 @@ def wait_for_element_absent(driver, selector, by=By.CSS_SELECTOR,
specified timeout.
@Params
driver - the webdriver object
selector - the locator that is used (required)
by - the method to search for the locator (Default: By.CSS_SELECTOR)
selector - the locator for identifying the page element (required)
by - the type of selector being used (Default: By.CSS_SELECTOR)
timeout - the time to wait for elements in seconds
"""
start_ms = time.time() * 1000.0
stop_ms = start_ms + (timeout * 1000.0)
for x in range(int(timeout * 10)):
@ -395,11 +390,10 @@ def wait_for_element_not_visible(driver, selector, by=By.CSS_SELECTOR,
specified timeout.
@Params
driver - the webdriver object (required)
selector - the locator that is used (required)
by - the method to search for the locator (Default: By.CSS_SELECTOR)
selector - the locator for identifying the page element (required)
by - the type of selector being used (Default: By.CSS_SELECTOR)
timeout - the time to wait for the element in seconds
"""
start_ms = time.time() * 1000.0
stop_ms = start_ms + (timeout * 1000.0)
for x in range(int(timeout * 10)):
@ -422,14 +416,45 @@ def wait_for_element_not_visible(driver, selector, by=By.CSS_SELECTOR,
selector, timeout, plural))
def wait_for_text_not_visible(driver, text, selector, by=By.CSS_SELECTOR,
timeout=settings.LARGE_TIMEOUT):
"""
Searches for the text in the element of the given selector on the page.
Returns True if the text is not visible on the page within the timeout.
Raises an exception if the text is still present after the timeout.
@Params
driver - the webdriver object (required)
text - the text that is being searched for in the element (required)
selector - the locator for identifying the page element (required)
by - the type of selector being used (Default: By.CSS_SELECTOR)
timeout - the time to wait for elements in seconds
@Returns
A web element object that contains the text searched for
"""
start_ms = time.time() * 1000.0
stop_ms = start_ms + (timeout * 1000.0)
for x in range(int(timeout * 10)):
if not is_text_visible(driver, text, selector, by=by):
return True
now_ms = time.time() * 1000.0
if now_ms >= stop_ms:
break
time.sleep(0.1)
plural = "s"
if timeout == 1:
plural = ""
raise Exception("Text {%s} in {%s} was still visible after %s "
"second%s!" % (text, selector, timeout, plural))
def find_visible_elements(driver, selector, by=By.CSS_SELECTOR):
"""
Finds all WebElements that match a selector and are visible.
Similar to webdriver.find_elements.
@Params
driver - the webdriver object (required)
selector - the locator that is used to search the DOM (required)
by - the method to search for the locator (Default: By.CSS_SELECTOR)
selector - the locator for identifying the page element (required)
by - the type of selector being used (Default: By.CSS_SELECTOR)
"""
elements = driver.find_elements(by=by, value=selector)
return [element for element in elements if element.is_displayed()]
@ -534,7 +559,6 @@ def wait_for_and_switch_to_alert(driver, timeout=settings.LARGE_TIMEOUT):
driver - the webdriver object (required)
timeout - the time to wait for the alert in seconds
"""
start_ms = time.time() * 1000.0
stop_ms = start_ms + (timeout * 1000.0)
for x in range(int(timeout * 10)):
@ -560,7 +584,6 @@ def switch_to_frame(driver, frame, timeout=settings.SMALL_TIMEOUT):
frame - the frame element, name, or index
timeout - the time to wait for the alert in seconds
"""
start_ms = time.time() * 1000.0
stop_ms = start_ms + (timeout * 1000.0)
for x in range(int(timeout * 10)):
@ -584,7 +607,6 @@ def switch_to_window(driver, window, timeout=settings.SMALL_TIMEOUT):
window - the window index or window handle
timeout - the time to wait for the window in seconds
"""
start_ms = time.time() * 1000.0
stop_ms = start_ms + (timeout * 1000.0)
if isinstance(window, int):

View File

@ -45,7 +45,7 @@ if sys.argv[-1] == 'publish':
setup(
name='seleniumbase',
version='1.32.2',
version='1.32.3',
description='Fast, Easy, and Reliable Browser Automation & Testing.',
long_description=long_description,
long_description_content_type='text/markdown',
@ -93,7 +93,7 @@ setup(
'selenium==3.141.0',
'pluggy>=0.12.0',
'pytest>=4.6.5;python_version<"3"', # For Python 2 compatibility
'pytest>=5.1.2;python_version>="3"',
'pytest>=5.1.3;python_version>="3"',
'pytest-cov>=2.7.1',
'pytest-forked>=1.0.2',
'pytest-html==1.22.0', # Keep at 1.22.0 unless tested on Windows