Skip to content

Commit 186456c

Browse files
authored
Merge pull request #1248 from seleniumbase/add-some-type-checking-and-update-dependencies
Add some type checking and update dependencies
2 parents d95073c + f80ddcc commit 186456c

File tree

9 files changed

+47
-23
lines changed

9 files changed

+47
-23
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ COMMANDS:
140140
141141
🔵 If you've cloned SeleniumBase, you can run tests from the [examples/](https://github.com/seleniumbase/SeleniumBase/tree/master/examples) folder.
142142
143-
<p align="left">Here's <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/my_first_test.py">my_first_test.py</a> in <code>--demo</code> mode:</p>
143+
<p align="left">Here's <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/my_first_test.py">my_first_test.py</a>:</p>
144144
145145
```bash
146146
cd examples/
147-
pytest my_first_test.py --demo
147+
pytest my_first_test.py
148148
```
149149
150150
> (Chrome is the default browser if not specified with ``--browser``. On Linux, ``--headless`` is the default behavior.)
@@ -951,7 +951,7 @@ pytest --reruns=1 --reruns-delay=1
951951
<p><div><a href="https://github.com/mdmintz">https://github.com/mdmintz</a></div></p>
952952
953953
<div><a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.io/cdn/img/fancy_logo_14.png" title="SeleniumBase" width="200" /></a></div> <div><a href="https://github.com/seleniumbase/SeleniumBase/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-22BBCC.svg" title="SeleniumBase" /></a> <a href="https://gitter.im/seleniumbase/SeleniumBase" target="_blank"><img src="https://badges.gitter.im/seleniumbase/SeleniumBase.svg" title="SeleniumBase" alt="Join the chat!" /></a></div> <div><a href="https://github.com/seleniumbase/SeleniumBase"><img src="https://img.shields.io/badge/tested%20with-SeleniumBase-04C38E.svg" alt="Tested with SeleniumBase" /></a></div> <div><a href="https://seleniumbase.io">
954-
<img src="https://img.shields.io/badge/docs-%20%20SeleniumBase.io-11BBDD.svg" alt="SeleniumBase.io Docs" /></a></div> <div><a href="https://pepy.tech/project/seleniumbase" target="_blank"><img src="https://pepy.tech/badge/seleniumbase" alt="SeleniumBase PyPI downloads" /></a> <a href="https://twitter.com/SeleniumBase" target="_blank"><img src="https://img.shields.io/twitter/follow/seleniumbase.svg?style=flat-rounded&logo=twitter&label=followers" alt="SeleniumBase Twitter followers" /></a></div>
954+
<img src="https://img.shields.io/badge/docs-%20%20SeleniumBase.io-11BBDD.svg" alt="SeleniumBase.io Docs" /></a></div> <div><a href="https://pepy.tech/project/seleniumbase" target="_blank"><img src="https://pepy.tech/badge/seleniumbase" alt="SeleniumBase PyPI downloads" /></a></div>
955955
956956
<p><div>
957957
<span><a href="https://github.com/seleniumbase/SeleniumBase"><img src="https://seleniumbase.io/img/social/share_github.svg" title="SeleniumBase on GitHub" alt="SeleniumBase on GitHub" width="38" /></a></span>

examples/hack_the_planet.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ def test_all_your_base_are_belong_to_us(self):
286286
self.highlight('h1', loops=6, scroll=False)
287287

288288
self.open("https://www.selenium.dev/")
289+
if self.is_element_visible('button[data-dismiss="alert"] span'):
290+
self.js_click('button[data-dismiss="alert"] span', scroll=False)
289291
self.set_attributes("a.dropdown-toggle", "class", "nav-link")
290292
self.set_text_content('li a:contains("About")', "ALL")
291293
self.set_text_content('li a:contains("Downloads")', "YOUR")
@@ -360,12 +362,12 @@ def test_all_your_base_are_belong_to_us(self):
360362
self.set_text_content('a[href="/software/jira/features"]', "")
361363
self.set_text_content('a[href="/software/jira/guides"]', "")
362364
self.set_text_content("h1", ayb)
363-
self.set_text_content('div.xs-none-bottom a[href*="free"]', abtu)
365+
self.set_text_content('[class*="link-button"] a[href*="free"]', abtu)
364366
self.highlight("ul.imkt-navbar__link-list", loops=2, scroll=False)
365367
self.highlight('a[href*="jira/pricing"]', loops=3, scroll=False)
366368
self.highlight('a[href*="jira/enterprise"]', loops=3, scroll=False)
367369
self.highlight("h1", loops=3, scroll=False)
368-
self.highlight('div.xs-none-bottom a[href*="free"]', scroll=False)
370+
self.highlight('[class*="link-button"] a[href*="free"]', scroll=False)
369371

370372
self.open("https://status.iboss.com/ibcloud/app/cloudStatus.html")
371373
self.set_text_content('div[translate*="cloudStatus"]', ayb)

examples/parameterized_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class GoogleTests(BaseCase):
1313
def test_parameterized_google_search(self, search_key, expected_text, img):
1414
self.open("https://google.com/ncr")
1515
self.type('input[title="Search"]', search_key + "\n")
16-
self.assert_element("#result-stats")
1716
self.assert_text(expected_text, "#search")
1817
self.click('a:contains("%s")' % expected_text)
1918
self.assert_element(img)

examples/test_hack_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_hack_search(self):
2020
if self.is_element_visible(help_docs_install_link):
2121
self.highlight_click(help_docs_install_link)
2222
self.assert_text("Install SeleniumBase", "h1")
23-
self.click_link_text("GitHub branch")
23+
self.click_link("GitHub branch")
2424
self.highlight_click('a[href*="/seleniumbase/SeleniumBase"]')
2525
self.assert_element('[href="/seleniumbase/SeleniumBase"]')
2626
self.assert_true("seleniumbase/SeleniumBase" in self.get_current_url())

mkdocs_build/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pkginfo==1.8.2;python_version>="3.6"
1313
Jinja2==3.0.3;python_version>="3.6"
1414
click==8.0.4;python_version>="3.6"
1515
zipp==3.7.0;python_version>="3.7"
16-
readme-renderer==33.0
16+
readme-renderer==34.0
1717
pymdown-extensions==9.2;python_version>="3.7"
1818
importlib-metadata==4.11.2;python_version>="3.7"
1919
bleach==4.1.0

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Pillow==8.4.0;python_version>="3.6" and python_version<"3.7"
116116
Pillow==9.0.1;python_version>="3.7"
117117
typing-extensions==3.10.0.2;python_version<"3.6"
118118
typing-extensions==4.0.0;python_version>="3.6" and python_version<"3.8"
119-
rich==11.2.0;python_version>="3.6" and python_version<"4.0"
119+
rich==12.0.0;python_version>="3.6" and python_version<"4.0"
120120
tornado==5.1.1;python_version<"3.5"
121121
tornado==6.1;python_version>="3.5"
122122
pdfminer.six==20191110;python_version<"3.5"

seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "2.4.18"
2+
__version__ = "2.4.19"

seleniumbase/fixtures/base_case.py

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,7 @@ def update_text(
530530
pass # Clearing the text field first might not be necessary
531531
self.__demo_mode_pause_if_active(tiny=True)
532532
pre_action_url = self.driver.current_url
533-
if type(text) is int or type(text) is float:
534-
text = str(text)
533+
text = self.__get_type_checked_text(text)
535534
try:
536535
if not text.endswith("\n"):
537536
element.send_keys(text)
@@ -590,8 +589,7 @@ def add_text(self, selector, text, by=By.CSS_SELECTOR, timeout=None):
590589
if not self.demo_mode and not self.slow_mode:
591590
self.__scroll_to_element(element, selector, by)
592591
pre_action_url = self.driver.current_url
593-
if type(text) is int or type(text) is float:
594-
text = str(text)
592+
text = self.__get_type_checked_text(text)
595593
try:
596594
if not text.endswith("\n"):
597595
element.send_keys(text)
@@ -988,6 +986,7 @@ def click_link_text(self, link_text, timeout=None):
988986
timeout = self.__get_new_timeout(timeout)
989987
pre_action_url = self.driver.current_url
990988
pre_window_count = len(self.driver.window_handles)
989+
link_text = self.__get_type_checked_text(link_text)
991990
if self.browser == "phantomjs":
992991
if self.is_link_text_visible(link_text):
993992
element = self.wait_for_link_text_visible(
@@ -1109,6 +1108,7 @@ def click_partial_link_text(self, partial_link_text, timeout=None):
11091108
timeout = settings.SMALL_TIMEOUT
11101109
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
11111110
timeout = self.__get_new_timeout(timeout)
1111+
partial_link_text = self.__get_type_checked_text(partial_link_text)
11121112
if self.browser == "phantomjs":
11131113
if self.is_partial_link_text_visible(partial_link_text):
11141114
element = self.wait_for_partial_link_text(partial_link_text)
@@ -4765,6 +4765,32 @@ def __fix_unicode_conversion(self, text):
47654765
text = text.replace("\xe2\xbd\x85", "\xe6\x96\xb9")
47664766
return text
47674767

4768+
def __get_type_checked_text(self, text):
4769+
""" Do type-checking on text. Then return it when valid.
4770+
If the text is acceptable, return the text or str(text).
4771+
If the text is not acceptable, raise a Python Exception.
4772+
"""
4773+
if type(text) is str:
4774+
return text
4775+
elif type(text) is int or type(text) is float:
4776+
return str(text) # Convert num to string
4777+
elif type(text) is bool:
4778+
raise Exception("text must be a string! Boolean found!")
4779+
elif type(text).__name__ == "NoneType":
4780+
raise Exception("text must be a string! NoneType found!")
4781+
elif type(text) is list:
4782+
raise Exception("text must be a string! List found!")
4783+
elif type(text) is tuple:
4784+
raise Exception("text must be a string! Tuple found!")
4785+
elif type(text) is set:
4786+
raise Exception("text must be a string! Set found!")
4787+
elif type(text) is dict:
4788+
raise Exception("text must be a string! Dict found!")
4789+
elif not python3 and type(text) is unicode: # noqa: F821
4790+
return text # (For old Python versions with unicode)
4791+
else:
4792+
return str(text)
4793+
47684794
def get_pdf_text(
47694795
self,
47704796
pdf,
@@ -5703,8 +5729,7 @@ def set_value(
57035729
self.__demo_mode_highlight_if_active(orginal_selector, by)
57045730
if scroll and not self.demo_mode and not self.slow_mode:
57055731
self.scroll_to(orginal_selector, by=by, timeout=timeout)
5706-
if type(text) is int or type(text) is float:
5707-
text = str(text)
5732+
text = self.__get_type_checked_text(text)
57085733
value = re.escape(text)
57095734
value = self.__escape_quotes_if_needed(value)
57105735
pre_escape_css_selector = css_selector
@@ -5765,8 +5790,7 @@ def js_update_text(self, selector, text, by=By.CSS_SELECTOR, timeout=None):
57655790
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
57665791
timeout = self.__get_new_timeout(timeout)
57675792
selector, by = self.__recalculate_selector(selector, by)
5768-
if type(text) is int or type(text) is float:
5769-
text = str(text)
5793+
text = self.__get_type_checked_text(text)
57705794
self.set_value(selector, text, by=by, timeout=timeout)
57715795
if not text.endswith("\n"):
57725796
try:
@@ -5838,8 +5862,7 @@ def set_text_content(
58385862
self.__demo_mode_highlight_if_active(orginal_selector, by)
58395863
if not self.demo_mode and not self.slow_mode:
58405864
self.scroll_to(orginal_selector, by=by, timeout=timeout)
5841-
if type(text) is int or type(text) is float:
5842-
text = str(text)
5865+
text = self.__get_type_checked_text(text)
58435866
value = re.escape(text)
58445867
value = self.__escape_quotes_if_needed(value)
58455868
css_selector = re.escape(css_selector) # Add "\\" to special chars
@@ -6185,8 +6208,7 @@ def __shadow_type(self, selector, text, timeout, clear_first=True):
61856208
element.send_keys(backspaces)
61866209
except Exception:
61876210
pass
6188-
if type(text) is int or type(text) is float:
6189-
text = str(text)
6211+
text = self.__get_type_checked_text(text)
61906212
if not text.endswith("\n"):
61916213
element.send_keys(text)
61926214
if settings.WAIT_FOR_RSC_ON_PAGE_LOADS:
@@ -9390,6 +9412,7 @@ def wait_for_text_visible(
93909412
timeout = settings.LARGE_TIMEOUT
93919413
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
93929414
timeout = self.__get_new_timeout(timeout)
9415+
text = self.__get_type_checked_text(text)
93939416
selector, by = self.__recalculate_selector(selector, by)
93949417
if self.__is_shadow_selector(selector):
93959418
return self.__wait_for_shadow_text_visible(

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@
241241
'Pillow==9.0.1;python_version>="3.7"',
242242
'typing-extensions==3.10.0.2;python_version<"3.6"', # <3.8 for "rich"
243243
'typing-extensions==4.0.0;python_version>="3.6" and python_version<"3.8"', # noqa: E501
244-
'rich==11.2.0;python_version>="3.6" and python_version<"4.0"',
244+
'rich==12.0.0;python_version>="3.6" and python_version<"4.0"',
245245
'tornado==5.1.1;python_version<"3.5"',
246246
'tornado==6.1;python_version>="3.5"',
247247
'pdfminer.six==20191110;python_version<"3.5"',

0 commit comments

Comments
 (0)