Skip to content

Commit a5826f6

Browse files
authored
Merge pull request #379 from seleniumbase/update-requirements-and-methods
Update requirements and methods
2 parents 53f313e + 7fd9dae commit a5826f6

File tree

6 files changed

+89
-38
lines changed

6 files changed

+89
-38
lines changed

help_docs/method_summary.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,14 @@ self.assert_element_not_visible(selector, by=By.CSS_SELECTOR,
411411

412412
########
413413

414+
self.wait_for_text_not_visible(text, selector="html", by=By.CSS_SELECTOR,
415+
timeout=settings.LARGE_TIMEOUT)
416+
417+
self.assert_text_not_visible(text, selector="html", by=By.CSS_SELECTOR,
418+
timeout=settings.SMALL_TIMEOUT)
419+
420+
########
421+
414422
self.wait_for_and_accept_alert(timeout=settings.LARGE_TIMEOUT)
415423

416424
self.wait_for_and_dismiss_alert(timeout=settings.LARGE_TIMEOUT)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ requests>=2.22.0
1111
selenium==3.141.0
1212
pluggy>=0.12.0
1313
pytest>=4.6.5;python_version<"3"
14-
pytest>=5.1.2;python_version>="3"
14+
pytest>=5.1.3;python_version>="3"
1515
pytest-cov>=2.7.1
1616
pytest-forked>=1.0.2
1717
pytest-html==1.22.0

seleniumbase/core/browser_launcher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,13 @@ def _create_firefox_profile(
178178
profile.set_preference("pdfjs.disabled", True)
179179
profile.set_preference("app.update.auto", False)
180180
profile.set_preference("app.update.enabled", False)
181-
profile.set_preference("extensions.update.enabled", False)
182181
profile.set_preference("browser.privatebrowsing.autostart", True)
182+
profile.set_preference("devtools.errorconsole.enabled", True)
183183
profile.set_preference("extensions.allowPrivateBrowsingByDefault", True)
184184
profile.set_preference("extensions.PrivateBrowsing.notification", False)
185185
profile.set_preference("extensions.systemAddon.update.enabled", False)
186186
profile.set_preference("extensions.update.autoUpdateDefault", False)
187187
profile.set_preference("extensions.update.enabled", False)
188-
profile.set_preference("devtools.errorconsole.enabled", True)
189188
profile.set_preference(
190189
"datareporting.healthreport.logging.consoleEnabled", False)
191190
profile.set_preference("datareporting.healthreport.service.enabled", False)
@@ -195,6 +194,7 @@ def _create_firefox_profile(
195194
profile.set_preference("datareporting.policy.dataSubmissionEnabled", False)
196195
profile.set_preference(
197196
"datareporting.policy.dataSubmissionPolicyAccepted", False)
197+
profile.set_preference("toolkit.telemetry.unified", False)
198198
if proxy_string:
199199
proxy_server = proxy_string.split(':')[0]
200200
proxy_port = proxy_string.split(':')[1]

seleniumbase/fixtures/base_case.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2884,6 +2884,27 @@ def assert_element_not_visible(self, selector, by=By.CSS_SELECTOR,
28842884

28852885
############
28862886

2887+
def wait_for_text_not_visible(self, text, selector="html",
2888+
by=By.CSS_SELECTOR,
2889+
timeout=settings.LARGE_TIMEOUT):
2890+
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
2891+
timeout = self.__get_new_timeout(timeout)
2892+
selector, by = self.__recalculate_selector(selector, by)
2893+
return page_actions.wait_for_text_not_visible(
2894+
self.driver, text, selector, by, timeout)
2895+
2896+
def assert_text_not_visible(self, text, selector="html",
2897+
by=By.CSS_SELECTOR,
2898+
timeout=settings.SMALL_TIMEOUT):
2899+
""" Similar to wait_for_text_not_visible()
2900+
Raises an exception if the element or the text is not found.
2901+
Returns True if successful. Default timeout = SMALL_TIMEOUT. """
2902+
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
2903+
timeout = self.__get_new_timeout(timeout)
2904+
self.wait_for_text_not_visible(text, selector, by=by, timeout=timeout)
2905+
2906+
############
2907+
28872908
def wait_for_and_accept_alert(self, timeout=settings.LARGE_TIMEOUT):
28882909
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
28892910
timeout = self.__get_new_timeout(timeout)

seleniumbase/fixtures/page_actions.py

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def is_element_present(driver, selector, by=By.CSS_SELECTOR):
3939
Returns whether the specified element selector is present on the page.
4040
@Params
4141
driver - the webdriver object (required)
42-
selector - the locator that is used (required)
43-
by - the method to search for the locator (Default: By.CSS_SELECTOR)
42+
selector - the locator for identifying the page element (required)
43+
by - the type of selector being used (Default: By.CSS_SELECTOR)
4444
@Returns
4545
Boolean (is element present)
4646
"""
@@ -56,8 +56,8 @@ def is_element_visible(driver, selector, by=By.CSS_SELECTOR):
5656
Returns whether the specified element selector is visible on the page.
5757
@Params
5858
driver - the webdriver object (required)
59-
selector - the locator that is used (required)
60-
by - the method to search for the locator (Default: By.CSS_SELECTOR)
59+
selector - the locator for identifying the page element (required)
60+
by - the type of selector being used (Default: By.CSS_SELECTOR)
6161
@Returns
6262
Boolean (is element visible)
6363
"""
@@ -74,8 +74,8 @@ def is_text_visible(driver, text, selector, by=By.CSS_SELECTOR):
7474
@Params
7575
driver - the webdriver object (required)
7676
text - the text string to search for
77-
selector - the locator that is used (required)
78-
by - the method to search for the locator (Default: By.CSS_SELECTOR)
77+
selector - the locator for identifying the page element (required)
78+
by - the type of selector being used (Default: By.CSS_SELECTOR)
7979
@Returns
8080
Boolean (is text visible)
8181
"""
@@ -91,8 +91,8 @@ def hover_on_element(driver, selector, by=By.CSS_SELECTOR):
9191
Fires the hover event for the specified element by the given selector.
9292
@Params
9393
driver - the webdriver object (required)
94-
selector - the locator (css selector) that is used (required)
95-
by - the method to search for the locator (Default: By.CSS_SELECTOR)
94+
selector - the locator for identifying the page element (required)
95+
by - the type of selector being used (Default: By.CSS_SELECTOR)
9696
"""
9797
element = driver.find_element(by=by, value=selector)
9898
hover = ActionChains(driver).move_to_element(element)
@@ -117,8 +117,8 @@ def hover_and_click(driver, hover_selector, click_selector,
117117
driver - the webdriver object (required)
118118
hover_selector - the css selector to hover over (required)
119119
click_selector - the css selector to click on (required)
120-
hover_by - the method to search by (Default: By.CSS_SELECTOR)
121-
click_by - the method to search by (Default: By.CSS_SELECTOR)
120+
hover_by - the hover selector type to search by (Default: By.CSS_SELECTOR)
121+
click_by - the click selector type to search by (Default: By.CSS_SELECTOR)
122122
timeout - number of seconds to wait for click element to appear after hover
123123
"""
124124
start_ms = time.time() * 1000.0
@@ -200,13 +200,12 @@ def wait_for_element_present(driver, selector, by=By.CSS_SELECTOR,
200200
specified timeout.
201201
@Params
202202
driver - the webdriver object
203-
selector - the locator that is used (required)
204-
by - the method to search for the locator (Default: By.CSS_SELECTOR)
203+
selector - the locator for identifying the page element (required)
204+
by - the type of selector being used (Default: By.CSS_SELECTOR)
205205
timeout - the time to wait for elements in seconds
206206
@Returns
207207
A web element object
208208
"""
209-
210209
element = None
211210
start_ms = time.time() * 1000.0
212211
stop_ms = start_ms + (timeout * 1000.0)
@@ -234,14 +233,13 @@ def wait_for_element_visible(driver, selector, by=By.CSS_SELECTOR,
234233
specified timeout.
235234
@Params
236235
driver - the webdriver object (required)
237-
selector - the locator that is used (required)
238-
by - the method to search for the locator (Default: By.CSS_SELECTOR)
236+
selector - the locator for identifying the page element (required)
237+
by - the type of selector being used (Default: By.CSS_SELECTOR)
239238
timeout - the time to wait for elements in seconds
240239
241240
@Returns
242241
A web element object
243242
"""
244-
245243
element = None
246244
start_ms = time.time() * 1000.0
247245
stop_ms = start_ms + (timeout * 1000.0)
@@ -281,13 +279,12 @@ def wait_for_text_visible(driver, text, selector, by=By.CSS_SELECTOR,
281279
@Params
282280
driver - the webdriver object (required)
283281
text - the text that is being searched for in the element (required)
284-
selector - the locator that is used (required)
285-
by - the method to search for the locator (Default: By.CSS_SELECTOR)
282+
selector - the locator for identifying the page element (required)
283+
by - the type of selector being used (Default: By.CSS_SELECTOR)
286284
timeout - the time to wait for elements in seconds
287285
@Returns
288286
A web element object that contains the text searched for
289287
"""
290-
291288
element = None
292289
start_ms = time.time() * 1000.0
293290
stop_ms = start_ms + (timeout * 1000.0)
@@ -324,13 +321,12 @@ def wait_for_exact_text_visible(driver, text, selector, by=By.CSS_SELECTOR,
324321
@Params
325322
driver - the webdriver object (required)
326323
text - the exact text that is expected for the element (required)
327-
selector - the locator that is used (required)
328-
by - the method to search for the locator (Default: By.CSS_SELECTOR)
324+
selector - the locator for identifying the page element (required)
325+
by - the type of selector being used (Default: By.CSS_SELECTOR)
329326
timeout - the time to wait for elements in seconds
330327
@Returns
331328
A web element object that contains the text searched for
332329
"""
333-
334330
element = None
335331
start_ms = time.time() * 1000.0
336332
stop_ms = start_ms + (timeout * 1000.0)
@@ -364,11 +360,10 @@ def wait_for_element_absent(driver, selector, by=By.CSS_SELECTOR,
364360
specified timeout.
365361
@Params
366362
driver - the webdriver object
367-
selector - the locator that is used (required)
368-
by - the method to search for the locator (Default: By.CSS_SELECTOR)
363+
selector - the locator for identifying the page element (required)
364+
by - the type of selector being used (Default: By.CSS_SELECTOR)
369365
timeout - the time to wait for elements in seconds
370366
"""
371-
372367
start_ms = time.time() * 1000.0
373368
stop_ms = start_ms + (timeout * 1000.0)
374369
for x in range(int(timeout * 10)):
@@ -395,11 +390,10 @@ def wait_for_element_not_visible(driver, selector, by=By.CSS_SELECTOR,
395390
specified timeout.
396391
@Params
397392
driver - the webdriver object (required)
398-
selector - the locator that is used (required)
399-
by - the method to search for the locator (Default: By.CSS_SELECTOR)
393+
selector - the locator for identifying the page element (required)
394+
by - the type of selector being used (Default: By.CSS_SELECTOR)
400395
timeout - the time to wait for the element in seconds
401396
"""
402-
403397
start_ms = time.time() * 1000.0
404398
stop_ms = start_ms + (timeout * 1000.0)
405399
for x in range(int(timeout * 10)):
@@ -422,14 +416,45 @@ def wait_for_element_not_visible(driver, selector, by=By.CSS_SELECTOR,
422416
selector, timeout, plural))
423417

424418

419+
def wait_for_text_not_visible(driver, text, selector, by=By.CSS_SELECTOR,
420+
timeout=settings.LARGE_TIMEOUT):
421+
"""
422+
Searches for the text in the element of the given selector on the page.
423+
Returns True if the text is not visible on the page within the timeout.
424+
Raises an exception if the text is still present after the timeout.
425+
@Params
426+
driver - the webdriver object (required)
427+
text - the text that is being searched for in the element (required)
428+
selector - the locator for identifying the page element (required)
429+
by - the type of selector being used (Default: By.CSS_SELECTOR)
430+
timeout - the time to wait for elements in seconds
431+
@Returns
432+
A web element object that contains the text searched for
433+
"""
434+
start_ms = time.time() * 1000.0
435+
stop_ms = start_ms + (timeout * 1000.0)
436+
for x in range(int(timeout * 10)):
437+
if not is_text_visible(driver, text, selector, by=by):
438+
return True
439+
now_ms = time.time() * 1000.0
440+
if now_ms >= stop_ms:
441+
break
442+
time.sleep(0.1)
443+
plural = "s"
444+
if timeout == 1:
445+
plural = ""
446+
raise Exception("Text {%s} in {%s} was still visible after %s "
447+
"second%s!" % (text, selector, timeout, plural))
448+
449+
425450
def find_visible_elements(driver, selector, by=By.CSS_SELECTOR):
426451
"""
427452
Finds all WebElements that match a selector and are visible.
428453
Similar to webdriver.find_elements.
429454
@Params
430455
driver - the webdriver object (required)
431-
selector - the locator that is used to search the DOM (required)
432-
by - the method to search for the locator (Default: By.CSS_SELECTOR)
456+
selector - the locator for identifying the page element (required)
457+
by - the type of selector being used (Default: By.CSS_SELECTOR)
433458
"""
434459
elements = driver.find_elements(by=by, value=selector)
435460
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):
534559
driver - the webdriver object (required)
535560
timeout - the time to wait for the alert in seconds
536561
"""
537-
538562
start_ms = time.time() * 1000.0
539563
stop_ms = start_ms + (timeout * 1000.0)
540564
for x in range(int(timeout * 10)):
@@ -560,7 +584,6 @@ def switch_to_frame(driver, frame, timeout=settings.SMALL_TIMEOUT):
560584
frame - the frame element, name, or index
561585
timeout - the time to wait for the alert in seconds
562586
"""
563-
564587
start_ms = time.time() * 1000.0
565588
stop_ms = start_ms + (timeout * 1000.0)
566589
for x in range(int(timeout * 10)):
@@ -584,7 +607,6 @@ def switch_to_window(driver, window, timeout=settings.SMALL_TIMEOUT):
584607
window - the window index or window handle
585608
timeout - the time to wait for the window in seconds
586609
"""
587-
588610
start_ms = time.time() * 1000.0
589611
stop_ms = start_ms + (timeout * 1000.0)
590612
if isinstance(window, int):

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
setup(
4747
name='seleniumbase',
48-
version='1.32.2',
48+
version='1.32.3',
4949
description='Fast, Easy, and Reliable Browser Automation & Testing.',
5050
long_description=long_description,
5151
long_description_content_type='text/markdown',
@@ -93,7 +93,7 @@
9393
'selenium==3.141.0',
9494
'pluggy>=0.12.0',
9595
'pytest>=4.6.5;python_version<"3"', # For Python 2 compatibility
96-
'pytest>=5.1.2;python_version>="3"',
96+
'pytest>=5.1.3;python_version>="3"',
9797
'pytest-cov>=2.7.1',
9898
'pytest-forked>=1.0.2',
9999
'pytest-html==1.22.0', # Keep at 1.22.0 unless tested on Windows

0 commit comments

Comments
 (0)