Skip to content

Add options for disabling chromium features, and more #2441

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 7 commits into from
Jan 19, 2024
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ pytest test_coffee_cart.py --trace
--firefox-pref=SET # (Set a Firefox preference:value set, comma-separated.)
--extension-zip=ZIP # (Load a Chrome Extension .zip|.crx, comma-separated.)
--extension-dir=DIR # (Load a Chrome Extension directory, comma-separated.)
--disable-features="F1,F2" # (Disable features, comma-separated, no spaces.)
--binary-location=PATH # (Set path of the Chromium browser binary to use.)
--driver-version=VER # (Set the chromedriver or uc_driver version to use.)
--sjw # (Skip JS Waits for readyState to be "complete" or Angular to load.)
Expand Down
9 changes: 7 additions & 2 deletions examples/boilerplates/boilerplate_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from .base_test_case import BaseTestCase
from .page_objects import Page
try: # Run with "pytest" (relative imports are valid)
from .base_test_case import BaseTestCase
from .page_objects import Page
except (ImportError, ValueError): # Run with "python"
from base_test_case import BaseTestCase
from page_objects import Page
BaseTestCase.main(__name__, __file__)


class MyTestClass(BaseTestCase):
Expand Down
1 change: 1 addition & 0 deletions examples/raw_parameter_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
sb.window_size = None
sb.maximize_option = False
sb.visual_baseline = False
sb.disable_features = None
sb._disable_beforeunload = False
sb.save_screenshot_after_test = False
sb.no_screenshot_after_test = False
Expand Down
6 changes: 3 additions & 3 deletions examples/test_todomvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class TodoMVC(BaseCase):
def test_todomvc(self, framework):
self.open("https://todomvc.com/")
self.clear_local_storage()
self.click('a[href="examples/%s"]' % framework)
self.click('a[href*="examples/%s/dist"]' % framework)
self.assert_element("section.todoapp")
self.assert_text("todos", "header h1")
self.wait_for_ready_state_complete()
Expand All @@ -25,5 +25,5 @@ def test_todomvc(self, framework):
self.check_if_unchecked("ul.todo-list li:nth-of-type(2) input")
self.check_if_unchecked("ul.todo-list li:nth-of-type(3) input")
self.assert_text("0 items left", todo_count_span)
self.click('label[for="toggle-all"]')
self.assert_text("3 items left", todo_count_span)
self.click("button.clear-completed")
self.assert_element_not_visible(todo_count_span)
2 changes: 1 addition & 1 deletion examples/translations/russian_test_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class МойТестовыйКласс(ТестНаСелен):
def test_пример_1(self):
self.открыть("https://ru.wikipedia.org/wiki/")
self.подтвердить_элемент('[title="Русский язык"]')
self.подтвердить_текст("Википедия", "h2.main-wikimedia-header")
self.подтвердить_текст("Википедия", "div.main-wikimedia-header")
self.введите("#searchInput", "МГУ")
self.нажмите("#searchButton")
self.подтвердить_текст("университет", "#firstHeading")
Expand Down
1 change: 1 addition & 0 deletions help_docs/customizing_test_runs.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ pytest my_first_test.py --settings-file=custom_settings.py
--firefox-pref=SET # (Set a Firefox preference:value set, comma-separated.)
--extension-zip=ZIP # (Load a Chrome Extension .zip|.crx, comma-separated.)
--extension-dir=DIR # (Load a Chrome Extension directory, comma-separated.)
--disable-features="F1,F2" # (Disable features, comma-separated, no spaces.)
--binary-location=PATH # (Set path of the Chromium browser binary to use.)
--driver-version=VER # (Set the chromedriver or uc_driver version to use.)
--sjw # (Skip JS Waits for readyState to be "complete" or Angular to load.)
Expand Down
10 changes: 5 additions & 5 deletions mkdocs_build/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@

regex>=2023.12.25
pymdown-extensions>=10.7
pipdeptree>=2.13.1
pipdeptree>=2.13.2
python-dateutil>=2.8.2
Markdown==3.5.1
Markdown==3.5.2
markdown2==2.4.12
MarkupSafe==2.1.3
Jinja2==3.1.2
Jinja2==3.1.3
click==8.1.7
ghp-import==2.1.0
watchdog==3.0.0
cairocffi==1.6.1
pathspec==0.12.1
Babel==2.14.0
paginate==0.5.6
lxml==5.0.0
lxml==5.1.0
pyquery==2.0.0
readtime==3.0.0
mkdocs==1.5.3
mkdocs-material==9.5.3
mkdocs-material==9.5.4
mkdocs-exclude-search==0.6.6
mkdocs-simple-hooks==0.1.5
mkdocs-material-extensions==1.3.1
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ sniffio==1.3.0
h11==0.14.0
outcome==1.3.0.post0
trio==0.22.2;python_version<"3.8"
trio==0.23.2;python_version>="3.8"
trio==0.24.0;python_version>="3.8"
trio-websocket==0.11.1
wsproto==1.2.0
selenium==4.11.2;python_version<"3.8"
Expand All @@ -48,7 +48,7 @@ sbvirtualdisplay==1.3.0
behave==1.2.6
soupsieve==2.4.1;python_version<"3.8"
soupsieve==2.5;python_version>="3.8"
beautifulsoup4==4.12.2
beautifulsoup4==4.12.3
pygments==2.17.2
pyreadline3==3.4.1;platform_system=="Windows"
tabcompleter==1.3.0
Expand All @@ -70,9 +70,9 @@ coverage==7.4.0;python_version>="3.8"
pytest-cov==4.0.0;python_version<"3.7"
pytest-cov==4.1.0;python_version>="3.7"
flake8==5.0.4;python_version<"3.9"
flake8==6.1.0;python_version>="3.9"
flake8==7.0.0;python_version>="3.9"
mccabe==0.7.0
pyflakes==2.5.0;python_version<"3.9"
pyflakes==3.1.0;python_version>="3.9"
pyflakes==3.2.0;python_version>="3.9"
pycodestyle==2.9.1;python_version<"3.9"
pycodestyle==2.11.1;python_version>="3.9"
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.22.5"
__version__ = "4.22.6"
8 changes: 8 additions & 0 deletions seleniumbase/behave/behave_sb.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ def get_configured_sb(context):
sb.chromium_arg = None
sb.firefox_arg = None
sb.firefox_pref = None
sb.disable_features = None
sb.proxy_string = None
sb.proxy_bypass_list = None
sb.proxy_pac_url = None
Expand Down Expand Up @@ -748,6 +749,13 @@ def get_configured_sb(context):
firefox_pref = sb.firefox_pref # revert to default
sb.firefox_pref = firefox_pref
continue
# Handle: -D disable-features="F1,F2" / disable_features="F1,F2"
if low_key in ["disable-features", "disable_features"]:
disable_features = userdata[key]
if disable_features == "true":
disable_features = sb.disable_features # revert to default
sb.disable_features = disable_features
continue
# Handle: -D proxy=SERVER:PORT / proxy=USERNAME:PASSWORD@SERVER:PORT
if low_key in ["proxy", "proxy-server", "proxy-string"]:
proxy_string = userdata[key]
Expand Down
3 changes: 2 additions & 1 deletion seleniumbase/console_scripts/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ def show_basic_usage():
seleniumbase_logo = logo_helper.get_seleniumbase_logo()
print(seleniumbase_logo)
print("")
time.sleep(0.25) # Enough time to see the logo
time.sleep(0.28) # Enough time to see the logo
show_package_location()
show_version_info()
print("")
time.sleep(0.72) # Enough time to see the version
sc = ""
sc += ' * USAGE: "seleniumbase [COMMAND] [PARAMETERS]"\n'
sc += ' * OR: "sbase [COMMAND] [PARAMETERS]"\n'
Expand Down
96 changes: 75 additions & 21 deletions seleniumbase/core/browser_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ def _set_chrome_options(
user_data_dir,
extension_zip,
extension_dir,
disable_features,
binary_location,
driver_version,
page_load_strategy,
Expand Down Expand Up @@ -1044,6 +1045,7 @@ def _set_chrome_options(
binary_loc = detect_b_ver.get_binary_location(br_app, True)
if os.path.exists(binary_loc):
binary_location = binary_loc
extra_disabled_features = []
if chromium_arg:
# Can be a comma-separated list of Chromium args
chromium_arg_list = chromium_arg.split(",")
Expand All @@ -1069,8 +1071,13 @@ def _set_chrome_options(
)
if os.path.exists(binary_loc):
binary_location = binary_loc
elif "disable-features=" in chromium_arg_item:
d_f = chromium_arg_item.split("disable-features=")[-1]
extra_disabled_features.append(d_f)
elif len(chromium_arg_item) >= 3:
chrome_options.add_argument(chromium_arg_item)
if disable_features:
extra_disabled_features.extend(disable_features.split(","))
if devtools and not headless:
chrome_options.add_argument("--auto-open-devtools-for-tabs")
if user_agent:
Expand All @@ -1089,19 +1096,36 @@ def _set_chrome_options(
if headless or headless2 or is_using_uc(undetectable, browser_name):
chrome_options.add_argument("--disable-renderer-backgrounding")
chrome_options.add_argument("--disable-backgrounding-occluded-windows")
chrome_options.add_argument("--disable-client-side-phishing-detection")
chrome_options.add_argument("--disable-oopr-debug-crash-dump")
chrome_options.add_argument("--disable-top-sites")
chrome_options.add_argument("--ash-no-nudges")
chrome_options.add_argument("--no-crash-upload")
chrome_options.add_argument("--deny-permission-prompts")
included_disabled_features = []
if user_data_dir:
chrome_options.add_argument(
"--disable-features=OptimizationHintsFetching,Translate,"
"OptimizationTargetPrediction,PrivacySandboxSettings4,"
"DownloadBubble,DownloadBubbleV2"
)
included_disabled_features.append("OptimizationHintsFetching")
included_disabled_features.append("Translate")
included_disabled_features.append("OptimizationTargetPrediction")
included_disabled_features.append("PrivacySandboxSettings4")
included_disabled_features.append("DownloadBubble")
included_disabled_features.append("DownloadBubbleV2")
for item in extra_disabled_features:
if item not in included_disabled_features:
included_disabled_features.append(item)
d_f_string = ",".join(included_disabled_features)
chrome_options.add_argument("--disable-features=%s" % d_f_string)
else:
chrome_options.add_argument(
"--disable-features=OptimizationHintsFetching,Translate,"
"OptimizationTargetPrediction,DownloadBubble,DownloadBubbleV2"
)
included_disabled_features.append("OptimizationHintsFetching")
included_disabled_features.append("Translate")
included_disabled_features.append("OptimizationTargetPrediction")
included_disabled_features.append("DownloadBubble")
included_disabled_features.append("DownloadBubbleV2")
for item in extra_disabled_features:
if item not in included_disabled_features:
included_disabled_features.append(item)
d_f_string = ",".join(included_disabled_features)
chrome_options.add_argument("--disable-features=%s" % d_f_string)
if (
is_using_uc(undetectable, browser_name)
and (
Expand Down Expand Up @@ -1338,6 +1362,7 @@ def get_driver(
user_data_dir=None,
extension_zip=None,
extension_dir=None,
disable_features=None,
binary_location=None,
driver_version=None,
page_load_strategy=None,
Expand Down Expand Up @@ -1550,6 +1575,7 @@ def get_driver(
user_data_dir,
extension_zip,
extension_dir,
disable_features,
binary_location,
driver_version,
page_load_strategy,
Expand Down Expand Up @@ -1605,6 +1631,7 @@ def get_driver(
user_data_dir,
extension_zip,
extension_dir,
disable_features,
binary_location,
driver_version,
page_load_strategy,
Expand Down Expand Up @@ -1664,6 +1691,7 @@ def get_remote_driver(
user_data_dir,
extension_zip,
extension_dir,
disable_features,
binary_location,
driver_version,
page_load_strategy,
Expand Down Expand Up @@ -1784,6 +1812,7 @@ def get_remote_driver(
user_data_dir,
extension_zip,
extension_dir,
disable_features,
binary_location,
driver_version,
page_load_strategy,
Expand Down Expand Up @@ -1955,6 +1984,7 @@ def get_remote_driver(
user_data_dir,
extension_zip,
extension_dir,
disable_features,
binary_location,
driver_version,
page_load_strategy,
Expand Down Expand Up @@ -2075,6 +2105,7 @@ def get_local_driver(
user_data_dir,
extension_zip,
extension_dir,
disable_features,
binary_location,
driver_version,
page_load_strategy,
Expand Down Expand Up @@ -2570,18 +2601,6 @@ def get_local_driver(
edge_options.add_argument(
"--disable-autofill-keyboard-accessory-view[8]"
)
edge_options.add_argument("--ash-no-nudges")
edge_options.add_argument("--deny-permission-prompts")
if user_data_dir:
edge_options.add_argument(
"--disable-features=OptimizationHintsFetching,Translate,"
"OptimizationTargetPrediction,PrivacySandboxSettings4"
)
else:
edge_options.add_argument(
"--disable-features=OptimizationHintsFetching,Translate,"
"OptimizationTargetPrediction"
)
edge_options.add_argument("--disable-browser-side-navigation")
edge_options.add_argument("--disable-translate")
if not enable_ws:
Expand All @@ -2596,6 +2615,12 @@ def get_local_driver(
if headless or headless2 or is_using_uc(undetectable, browser_name):
edge_options.add_argument("--disable-renderer-backgrounding")
edge_options.add_argument("--disable-backgrounding-occluded-windows")
edge_options.add_argument("--disable-client-side-phishing-detection")
edge_options.add_argument("--disable-oopr-debug-crash-dump")
edge_options.add_argument("--disable-top-sites")
edge_options.add_argument("--ash-no-nudges")
edge_options.add_argument("--no-crash-upload")
edge_options.add_argument("--deny-permission-prompts")
if (
page_load_strategy
and page_load_strategy.lower() in ["eager", "none"]
Expand Down Expand Up @@ -2677,6 +2702,7 @@ def get_local_driver(
edge_options.add_argument("--disable-gpu")
if IS_LINUX:
edge_options.add_argument("--disable-dev-shm-usage")
extra_disabled_features = []
set_binary = False
if chromium_arg:
# Can be a comma-separated list of Chromium args
Expand All @@ -2690,8 +2716,33 @@ def get_local_driver(
chromium_arg_item = "--" + chromium_arg_item
if "set-binary" in chromium_arg_item:
set_binary = True
elif "disable-features=" in chromium_arg_item:
d_f = chromium_arg_item.split("disable-features=")[-1]
extra_disabled_features.append(d_f)
elif len(chromium_arg_item) >= 3:
edge_options.add_argument(chromium_arg_item)
if disable_features:
extra_disabled_features.extend(disable_features.split(","))
included_disabled_features = []
if user_data_dir:
included_disabled_features.append("OptimizationHintsFetching")
included_disabled_features.append("Translate")
included_disabled_features.append("OptimizationTargetPrediction")
included_disabled_features.append("PrivacySandboxSettings4")
for item in extra_disabled_features:
if item not in included_disabled_features:
included_disabled_features.append(item)
d_f_string = ",".join(included_disabled_features)
edge_options.add_argument("--disable-features=%s" % d_f_string)
else:
included_disabled_features.append("OptimizationHintsFetching")
included_disabled_features.append("Translate")
included_disabled_features.append("OptimizationTargetPrediction")
for item in extra_disabled_features:
if item not in included_disabled_features:
included_disabled_features.append(item)
d_f_string = ",".join(included_disabled_features)
edge_options.add_argument("--disable-features=%s" % d_f_string)
if (set_binary or IS_LINUX) and not binary_location:
br_app = "edge"
binary_loc = detect_b_ver.get_binary_location(br_app)
Expand Down Expand Up @@ -2831,6 +2882,7 @@ def get_local_driver(
user_data_dir,
extension_zip,
extension_dir,
disable_features,
binary_location,
driver_version,
page_load_strategy,
Expand Down Expand Up @@ -3348,6 +3400,7 @@ def get_local_driver(
None, # user_data_dir
None, # extension_zip
None, # extension_dir
None, # disable_features
binary_location,
driver_version,
page_load_strategy,
Expand Down Expand Up @@ -3565,6 +3618,7 @@ def get_local_driver(
None, # user_data_dir
None, # extension_zip
None, # extension_dir
None, # disable_features
binary_location,
driver_version,
page_load_strategy,
Expand Down
Loading