Skip to content

Fix bugs, refactor, and upgrade selenium #2349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/github_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ def test_github(self):
self.assert_element("div.repository-content")
self.assert_text("SeleniumBase", "strong a")
self.click('a[title="seleniumbase"]')
self.slow_click('a[aria-describedby="item-type-fixtures"]')
self.assert_element('a[aria-describedby="item-type-base_case.py"]')
self.slow_click('td[class*="large"] a[title="fixtures"]')
self.assert_element('td[class*="large"] a[title="base_case.py"]')
11 changes: 7 additions & 4 deletions examples/presenter/uc_presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ def test_presentation(self):

self.get_new_driver(undetectable=True)
try:
self.driver.uc_open_with_tab("https://nowsecure.nl/#relax")
self.driver.uc_open_with_reconnect(
"https://nowsecure.nl/#relax", reconnect_time=3
)
try:
self.assert_text("OH YEAH, you passed!", "h1", timeout=4)
self.post_message("Selenium wasn't detected!", duration=4)
except Exception:
self.clear_all_cookies()
self.driver.uc_open_with_tab("https://nowsecure.nl/#relax")
self.driver.uc_open_with_reconnect(
"https://nowsecure.nl/#relax", reconnect_time=3
)
self.assert_text("OH YEAH, you passed!", "h1", timeout=4)
self.post_message("Selenium wasn't detected!", duration=4)
finally:
Expand All @@ -51,8 +55,7 @@ def test_presentation(self):
"</mk-1></p>"
)
self.begin_presentation(filename="uc_presentation.html")
subprocess.Popen("pytest multi_uc.py --uc -q -n3", shell=True)
self.sleep(6)
subprocess.Popen("pytest multi_uc.py --uc -n3", shell=True).wait()
self.create_presentation(theme="serif", transition="fade")
self.add_slide(
"<p>Not just an army of bots, but an army of bots<br />"
Expand Down
2 changes: 1 addition & 1 deletion examples/raw_uc_mode.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""SB Manager using UC Mode for evading bot-detection."""
from seleniumbase import SB

with SB(uc=True) as sb:
with SB(uc=True, test=True) as sb:
sb.driver.uc_open_with_tab("https://nowsecure.nl/#relax")
sb.sleep(1.2)
if not sb.is_text_visible("OH YEAH, you passed!", "h1"):
Expand Down
4 changes: 2 additions & 2 deletions examples/test_hack_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_hack_search(self):
self.highlight_click('[href="/seleniumbase/SeleniumBase"]')
self.highlight_click('a[title="examples"]')
self.assert_text("examples", "#file-name-id-wide")
self.highlight('a[aria-describedby="item-type-test_hack_search.py"]')
self.click('a[aria-describedby="item-type-test_hack_search.py"]')
self.highlight('td[class*="large"] a[title="test_hack_search.py"]')
self.click('td[class*="large"] a[title="test_hack_search.py"]')
self.assert_text("test_hack_search.py", "#file-name-id-wide")
self.highlight("#file-name-id-wide")
2 changes: 1 addition & 1 deletion examples/test_shadow_dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_shadow_dom(self):
)
remove_button = (
"downloads-manager::shadow #downloadsList"
" downloads-item::shadow #remove"
" downloads-item::shadow #remove-old"
)
no_downloads_area = "downloads-manager::shadow #no-downloads"

Expand Down
2 changes: 1 addition & 1 deletion examples/youtube_search_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ def test_youtube_autocomplete_results(self):
'Actual text was "%s"!' % (search_term, top_result),
)
self.click(result_selector)
self.assert_element_present('a[aria-label*="SeleniumBase"]')
self.sleep(1)
6 changes: 3 additions & 3 deletions mkdocs_build/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pymdown-extensions>=10.5
pipdeptree>=2.13.1
python-dateutil>=2.8.2
Markdown==3.5.1
markdown2==2.4.10
markdown2==2.4.11
MarkupSafe==2.1.3
Jinja2==3.1.2
click==8.1.7
Expand All @@ -20,7 +20,7 @@ paginate==0.5.6
pyquery==2.0.0
readtime==3.0.0
mkdocs==1.5.3
mkdocs-material==9.4.14
mkdocs-exclude-search==0.6.5
mkdocs-material==9.5.0
mkdocs-exclude-search==0.6.6
mkdocs-simple-hooks==0.1.5
mkdocs-material-extensions==1.3.1
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ attrs>=23.1.0
certifi>=2023.11.17
filelock>=3.12.2;python_version<"3.8"
filelock>=3.13.1;python_version>="3.8"
platformdirs>=4.0.0
platformdirs>=4.0.0;python_version<"3.8"
platformdirs>=4.1.0;python_version>="3.8"
parse>=1.20.0
parse-type>=0.6.2
six==1.16.0
Expand All @@ -26,7 +27,7 @@ trio==0.23.1;python_version>="3.8"
trio-websocket==0.11.1
wsproto==1.2.0
selenium==4.11.2;python_version<"3.8"
selenium==4.15.2;python_version>="3.8"
selenium==4.16.0;python_version>="3.8"
cssselect==1.2.0
sortedcontainers==2.4.0
fasteners==0.19
Expand Down
2 changes: 1 addition & 1 deletion seleniumbase/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "4.21.7"
__version__ = "4.22.0"
6 changes: 5 additions & 1 deletion seleniumbase/core/proxy_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ def create_proxy_ext(
if not bypass_list:
bypass_list = ""
if proxy_string:
proxy_host = proxy_string.split(":")[0]
proxy_protocol = ""
if proxy_string.count("://") == 1:
proxy_protocol = proxy_string.split("://")[0] + "://"
proxy_string = proxy_string.split("://")[1]
proxy_host = proxy_protocol + proxy_string.split(":")[0]
proxy_port = proxy_string.split(":")[1]
background_js = (
"""var config = {\n"""
Expand Down
46 changes: 17 additions & 29 deletions seleniumbase/fixtures/base_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,22 +199,17 @@ def test_example(self):
Eg. "python my_test.py" instead of "pytest my_test.py"."""
if name == "__main__": # Test called with "python"
import subprocess
from pytest import main as pytest_main
all_args = []
for arg in args:
all_args.append(arg)
for arg in sys.argv[1:]:
all_args.append(arg)
multi = False
for arg in all_args:
if arg.startswith("-n") or arg.startswith("--numprocesses"):
multi = True
if multi:
subprocess.call(
[sys.executable, "-m", "pytest", file, "-s", *all_args]
)
else:
pytest_main([file, "-s", *all_args])
# See: https://stackoverflow.com/a/54666289/7058266
# from pytest import main as pytest_main
# pytest_main([file, "-s", *all_args])
subprocess.call(
[sys.executable, "-m", "pytest", file, "-s", *all_args]
)

def open(self, url):
"""Navigates the current browser window to the specified page."""
Expand Down Expand Up @@ -7007,13 +7002,13 @@ def get_browser_downloads_folder(self):
# Can't change the system [Downloads Folder] on Safari or IE
return os.path.join(os.path.expanduser("~"), "downloads")
elif (
self.driver.capabilities["browserName"].lower() == "chrome"
"chrome" in self.driver.capabilities
and int(self.get_chromedriver_version().split(".")[0]) < 73
and self.headless
):
return os.path.join(os.path.expanduser("~"), "downloads")
elif (
self.driver.capabilities["browserName"].lower() == "chrome"
"chrome" in self.driver.capabilities
and int(self.get_chromedriver_version().split(".")[0]) >= 110
and int(self.get_chromedriver_version().split(".")[0]) <= 112
and self.headless
Expand Down Expand Up @@ -7711,17 +7706,19 @@ def is_chromium(self):
"""Return True if the browser is Chrome or Edge."""
self.__check_scope()
chromium = False
browser_name = self.driver.capabilities["browserName"]
if browser_name.lower() in ("chrome", "edge", "msedge"):
if (
"chrome" in self.driver.capabilities
or "msedge" in self.driver.capabilities
):
chromium = True
return chromium

def __fail_if_not_using_chrome(self, method):
chrome = False
browser_name = self.driver.capabilities["browserName"]
if browser_name.lower() == "chrome":
if "chrome" in self.driver.capabilities:
chrome = True
if not chrome:
browser_name = self.driver.capabilities["browserName"]
message = (
'Error: "%s" should only be called by tests '
'running with "--browser=chrome" / "--chrome"! '
Expand All @@ -7732,8 +7729,8 @@ def __fail_if_not_using_chrome(self, method):
raise NotUsingChromeException(message)

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

############

@decorators.deprecated("The Driver Manager prevents old drivers.")
def is_chromedriver_too_old(self):
"""Before chromedriver 73, there was no version check, which
means it's possible to run a new Chrome with old drivers."""
self.__fail_if_not_using_chrome("is_chromedriver_too_old()")
if int(self.get_chromedriver_version().split(".")[0]) < 73:
return True # chromedriver is too old! Please upgrade!
return False

@decorators.deprecated("You should use re.escape() instead.")
def jq_format(self, code):
# DEPRECATED - re.escape() already performs this action.
Expand Down Expand Up @@ -15578,12 +15566,12 @@ def _get_driver_name_and_version(self):
else:
return None
driver = self.driver
if driver.capabilities["browserName"].lower() == "chrome":
if "chrome" in self.driver.capabilities:
cap_dict = driver.capabilities["chrome"]
return (
"chromedriver", cap_dict["chromedriverVersion"].split(" ")[0]
)
elif driver.capabilities["browserName"].lower() == "msedge":
elif "msedge" in self.driver.capabilities:
cap_dict = driver.capabilities["msedge"]
return (
"msedgedriver", cap_dict["msedgedriverVersion"].split(" ")[0]
Expand Down
13 changes: 7 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@
"certifi>=2023.11.17",
'filelock>=3.12.2;python_version<"3.8"',
'filelock>=3.13.1;python_version>="3.8"',
'platformdirs>=4.0.0',
'platformdirs>=4.0.0;python_version<"3.8"',
'platformdirs>=4.1.0;python_version>="3.8"',
'parse>=1.20.0',
'parse-type>=0.6.2',
"six==1.16.0",
Expand All @@ -159,7 +160,7 @@
'trio-websocket==0.11.1',
'wsproto==1.2.0',
'selenium==4.11.2;python_version<"3.8"',
'selenium==4.15.2;python_version>="3.8"',
'selenium==4.16.0;python_version>="3.8"',
'cssselect==1.2.0',
"sortedcontainers==2.4.0",
'fasteners==0.19',
Expand Down Expand Up @@ -249,14 +250,14 @@
# pip install -e .[selenium-wire]
"selenium-wire": [
'selenium-wire==5.1.0',
'Brotli==1.0.9',
'blinker==1.6.2',
'Brotli==1.1.0',
'blinker==1.7.0',
'h2==4.1.0',
'hpack==4.0.0',
'hyperframe==6.0.1',
'kaitaistruct==0.10',
'pyasn1==0.5.0',
'zstandard==0.21.0',
'pyasn1==0.5.1',
'zstandard==0.22.0',
],
},
packages=[
Expand Down