Skip to content

Commit 570910c

Browse files
authored
Merge pull request #2349 from seleniumbase/fix-bugs-refactor-and-upgrade-selenium
Fix bugs, refactor, and upgrade selenium
2 parents 01c98e2 + 144d536 commit 570910c

12 files changed

+50
-53
lines changed

examples/github_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ def test_github(self):
1717
self.assert_element("div.repository-content")
1818
self.assert_text("SeleniumBase", "strong a")
1919
self.click('a[title="seleniumbase"]')
20-
self.slow_click('a[aria-describedby="item-type-fixtures"]')
21-
self.assert_element('a[aria-describedby="item-type-base_case.py"]')
20+
self.slow_click('td[class*="large"] a[title="fixtures"]')
21+
self.assert_element('td[class*="large"] a[title="base_case.py"]')

examples/presenter/uc_presentation.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@ def test_presentation(self):
2929

3030
self.get_new_driver(undetectable=True)
3131
try:
32-
self.driver.uc_open_with_tab("https://nowsecure.nl/#relax")
32+
self.driver.uc_open_with_reconnect(
33+
"https://nowsecure.nl/#relax", reconnect_time=3
34+
)
3335
try:
3436
self.assert_text("OH YEAH, you passed!", "h1", timeout=4)
3537
self.post_message("Selenium wasn't detected!", duration=4)
3638
except Exception:
3739
self.clear_all_cookies()
38-
self.driver.uc_open_with_tab("https://nowsecure.nl/#relax")
40+
self.driver.uc_open_with_reconnect(
41+
"https://nowsecure.nl/#relax", reconnect_time=3
42+
)
3943
self.assert_text("OH YEAH, you passed!", "h1", timeout=4)
4044
self.post_message("Selenium wasn't detected!", duration=4)
4145
finally:
@@ -51,8 +55,7 @@ def test_presentation(self):
5155
"</mk-1></p>"
5256
)
5357
self.begin_presentation(filename="uc_presentation.html")
54-
subprocess.Popen("pytest multi_uc.py --uc -q -n3", shell=True)
55-
self.sleep(6)
58+
subprocess.Popen("pytest multi_uc.py --uc -n3", shell=True).wait()
5659
self.create_presentation(theme="serif", transition="fade")
5760
self.add_slide(
5861
"<p>Not just an army of bots, but an army of bots<br />"

examples/raw_uc_mode.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""SB Manager using UC Mode for evading bot-detection."""
22
from seleniumbase import SB
33

4-
with SB(uc=True) as sb:
4+
with SB(uc=True, test=True) as sb:
55
sb.driver.uc_open_with_tab("https://nowsecure.nl/#relax")
66
sb.sleep(1.2)
77
if not sb.is_text_visible("OH YEAH, you passed!", "h1"):

examples/test_hack_search.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_hack_search(self):
2626
self.highlight_click('[href="/seleniumbase/SeleniumBase"]')
2727
self.highlight_click('a[title="examples"]')
2828
self.assert_text("examples", "#file-name-id-wide")
29-
self.highlight('a[aria-describedby="item-type-test_hack_search.py"]')
30-
self.click('a[aria-describedby="item-type-test_hack_search.py"]')
29+
self.highlight('td[class*="large"] a[title="test_hack_search.py"]')
30+
self.click('td[class*="large"] a[title="test_hack_search.py"]')
3131
self.assert_text("test_hack_search.py", "#file-name-id-wide")
3232
self.highlight("#file-name-id-wide")

examples/test_shadow_dom.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def test_shadow_dom(self):
6363
)
6464
remove_button = (
6565
"downloads-manager::shadow #downloadsList"
66-
" downloads-item::shadow #remove"
66+
" downloads-item::shadow #remove-old"
6767
)
6868
no_downloads_area = "downloads-manager::shadow #no-downloads"
6969

examples/youtube_search_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ def test_youtube_autocomplete_results(self):
3232
'Actual text was "%s"!' % (search_term, top_result),
3333
)
3434
self.click(result_selector)
35-
self.assert_element_present('a[aria-label*="SeleniumBase"]')
35+
self.sleep(1)

mkdocs_build/requirements.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pymdown-extensions>=10.5
77
pipdeptree>=2.13.1
88
python-dateutil>=2.8.2
99
Markdown==3.5.1
10-
markdown2==2.4.10
10+
markdown2==2.4.11
1111
MarkupSafe==2.1.3
1212
Jinja2==3.1.2
1313
click==8.1.7
@@ -20,7 +20,7 @@ paginate==0.5.6
2020
pyquery==2.0.0
2121
readtime==3.0.0
2222
mkdocs==1.5.3
23-
mkdocs-material==9.4.14
24-
mkdocs-exclude-search==0.6.5
23+
mkdocs-material==9.5.0
24+
mkdocs-exclude-search==0.6.6
2525
mkdocs-simple-hooks==0.1.5
2626
mkdocs-material-extensions==1.3.1

requirements.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ attrs>=23.1.0
77
certifi>=2023.11.17
88
filelock>=3.12.2;python_version<"3.8"
99
filelock>=3.13.1;python_version>="3.8"
10-
platformdirs>=4.0.0
10+
platformdirs>=4.0.0;python_version<"3.8"
11+
platformdirs>=4.1.0;python_version>="3.8"
1112
parse>=1.20.0
1213
parse-type>=0.6.2
1314
six==1.16.0
@@ -26,7 +27,7 @@ trio==0.23.1;python_version>="3.8"
2627
trio-websocket==0.11.1
2728
wsproto==1.2.0
2829
selenium==4.11.2;python_version<"3.8"
29-
selenium==4.15.2;python_version>="3.8"
30+
selenium==4.16.0;python_version>="3.8"
3031
cssselect==1.2.0
3132
sortedcontainers==2.4.0
3233
fasteners==0.19

seleniumbase/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "4.21.7"
2+
__version__ = "4.22.0"

seleniumbase/core/proxy_helper.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ def create_proxy_ext(
2727
if not bypass_list:
2828
bypass_list = ""
2929
if proxy_string:
30-
proxy_host = proxy_string.split(":")[0]
30+
proxy_protocol = ""
31+
if proxy_string.count("://") == 1:
32+
proxy_protocol = proxy_string.split("://")[0] + "://"
33+
proxy_string = proxy_string.split("://")[1]
34+
proxy_host = proxy_protocol + proxy_string.split(":")[0]
3135
proxy_port = proxy_string.split(":")[1]
3236
background_js = (
3337
"""var config = {\n"""

seleniumbase/fixtures/base_case.py

+17-29
Original file line numberDiff line numberDiff line change
@@ -199,22 +199,17 @@ def test_example(self):
199199
Eg. "python my_test.py" instead of "pytest my_test.py"."""
200200
if name == "__main__": # Test called with "python"
201201
import subprocess
202-
from pytest import main as pytest_main
203202
all_args = []
204203
for arg in args:
205204
all_args.append(arg)
206205
for arg in sys.argv[1:]:
207206
all_args.append(arg)
208-
multi = False
209-
for arg in all_args:
210-
if arg.startswith("-n") or arg.startswith("--numprocesses"):
211-
multi = True
212-
if multi:
213-
subprocess.call(
214-
[sys.executable, "-m", "pytest", file, "-s", *all_args]
215-
)
216-
else:
217-
pytest_main([file, "-s", *all_args])
207+
# See: https://stackoverflow.com/a/54666289/7058266
208+
# from pytest import main as pytest_main
209+
# pytest_main([file, "-s", *all_args])
210+
subprocess.call(
211+
[sys.executable, "-m", "pytest", file, "-s", *all_args]
212+
)
218213

219214
def open(self, url):
220215
"""Navigates the current browser window to the specified page."""
@@ -7007,13 +7002,13 @@ def get_browser_downloads_folder(self):
70077002
# Can't change the system [Downloads Folder] on Safari or IE
70087003
return os.path.join(os.path.expanduser("~"), "downloads")
70097004
elif (
7010-
self.driver.capabilities["browserName"].lower() == "chrome"
7005+
"chrome" in self.driver.capabilities
70117006
and int(self.get_chromedriver_version().split(".")[0]) < 73
70127007
and self.headless
70137008
):
70147009
return os.path.join(os.path.expanduser("~"), "downloads")
70157010
elif (
7016-
self.driver.capabilities["browserName"].lower() == "chrome"
7011+
"chrome" in self.driver.capabilities
70177012
and int(self.get_chromedriver_version().split(".")[0]) >= 110
70187013
and int(self.get_chromedriver_version().split(".")[0]) <= 112
70197014
and self.headless
@@ -7711,17 +7706,19 @@ def is_chromium(self):
77117706
"""Return True if the browser is Chrome or Edge."""
77127707
self.__check_scope()
77137708
chromium = False
7714-
browser_name = self.driver.capabilities["browserName"]
7715-
if browser_name.lower() in ("chrome", "edge", "msedge"):
7709+
if (
7710+
"chrome" in self.driver.capabilities
7711+
or "msedge" in self.driver.capabilities
7712+
):
77167713
chromium = True
77177714
return chromium
77187715

77197716
def __fail_if_not_using_chrome(self, method):
77207717
chrome = False
7721-
browser_name = self.driver.capabilities["browserName"]
7722-
if browser_name.lower() == "chrome":
7718+
if "chrome" in self.driver.capabilities:
77237719
chrome = True
77247720
if not chrome:
7721+
browser_name = self.driver.capabilities["browserName"]
77257722
message = (
77267723
'Error: "%s" should only be called by tests '
77277724
'running with "--browser=chrome" / "--chrome"! '
@@ -7732,8 +7729,8 @@ def __fail_if_not_using_chrome(self, method):
77327729
raise NotUsingChromeException(message)
77337730

77347731
def __fail_if_not_using_chromium(self, method):
7735-
browser_name = self.driver.capabilities["browserName"]
77367732
if not self.is_chromium():
7733+
browser_name = self.driver.capabilities["browserName"]
77377734
message = (
77387735
'Error: "%s" should only be called by tests '
77397736
'running with a Chromium browser! (Chrome or Edge) '
@@ -13584,15 +13581,6 @@ def __disable_beforeunload_as_needed(self):
1358413581

1358513582
############
1358613583

13587-
@decorators.deprecated("The Driver Manager prevents old drivers.")
13588-
def is_chromedriver_too_old(self):
13589-
"""Before chromedriver 73, there was no version check, which
13590-
means it's possible to run a new Chrome with old drivers."""
13591-
self.__fail_if_not_using_chrome("is_chromedriver_too_old()")
13592-
if int(self.get_chromedriver_version().split(".")[0]) < 73:
13593-
return True # chromedriver is too old! Please upgrade!
13594-
return False
13595-
1359613584
@decorators.deprecated("You should use re.escape() instead.")
1359713585
def jq_format(self, code):
1359813586
# DEPRECATED - re.escape() already performs this action.
@@ -15578,12 +15566,12 @@ def _get_driver_name_and_version(self):
1557815566
else:
1557915567
return None
1558015568
driver = self.driver
15581-
if driver.capabilities["browserName"].lower() == "chrome":
15569+
if "chrome" in self.driver.capabilities:
1558215570
cap_dict = driver.capabilities["chrome"]
1558315571
return (
1558415572
"chromedriver", cap_dict["chromedriverVersion"].split(" ")[0]
1558515573
)
15586-
elif driver.capabilities["browserName"].lower() == "msedge":
15574+
elif "msedge" in self.driver.capabilities:
1558715575
cap_dict = driver.capabilities["msedge"]
1558815576
return (
1558915577
"msedgedriver", cap_dict["msedgedriverVersion"].split(" ")[0]

setup.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@
140140
"certifi>=2023.11.17",
141141
'filelock>=3.12.2;python_version<"3.8"',
142142
'filelock>=3.13.1;python_version>="3.8"',
143-
'platformdirs>=4.0.0',
143+
'platformdirs>=4.0.0;python_version<"3.8"',
144+
'platformdirs>=4.1.0;python_version>="3.8"',
144145
'parse>=1.20.0',
145146
'parse-type>=0.6.2',
146147
"six==1.16.0",
@@ -159,7 +160,7 @@
159160
'trio-websocket==0.11.1',
160161
'wsproto==1.2.0',
161162
'selenium==4.11.2;python_version<"3.8"',
162-
'selenium==4.15.2;python_version>="3.8"',
163+
'selenium==4.16.0;python_version>="3.8"',
163164
'cssselect==1.2.0',
164165
"sortedcontainers==2.4.0",
165166
'fasteners==0.19',
@@ -249,14 +250,14 @@
249250
# pip install -e .[selenium-wire]
250251
"selenium-wire": [
251252
'selenium-wire==5.1.0',
252-
'Brotli==1.0.9',
253-
'blinker==1.6.2',
253+
'Brotli==1.1.0',
254+
'blinker==1.7.0',
254255
'h2==4.1.0',
255256
'hpack==4.0.0',
256257
'hyperframe==6.0.1',
257258
'kaitaistruct==0.10',
258-
'pyasn1==0.5.0',
259-
'zstandard==0.21.0',
259+
'pyasn1==0.5.1',
260+
'zstandard==0.22.0',
260261
],
261262
},
262263
packages=[

0 commit comments

Comments
 (0)