Skip to content

Update options, methods, and docstrings #3163

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
Sep 26, 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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,9 @@ pytest test_coffee_cart.py --trace
--sjw # (Skip JS Waits for readyState to be "complete" or Angular to load.)
--wfa # (Wait for AngularJS to be done loading after specific web actions.)
--pls=PLS # (Set pageLoadStrategy on Chrome: "normal", "eager", or "none".)
--headless # (Run tests in headless mode. The default arg on Linux OS.)
--headless2 # (Use the new headless mode, which supports extensions.)
--headless # (The default headless mode. Linux uses this mode by default.)
--headless1 # (Use Chrome's old headless mode. Fast, but has limitations.)
--headless2 # (Use Chrome's new headless mode, which supports extensions.)
--headed # (Run tests in headed/GUI mode on Linux OS, where not default.)
--xvfb # (Run tests using the Xvfb virtual display server on Linux OS.)
--xvfb-metrics=STRING # (Set Xvfb display size on Linux: "Width,Height".)
Expand Down
2 changes: 2 additions & 0 deletions examples/handle_alert_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def test_alerts(self):
self.open("about:blank")
self.execute_script('window.alert("ALERT!!!");')
self.sleep(1) # Not needed (Lets you see the alert pop up)
self.assert_true(self.is_alert_present())
self.accept_alert()
self.sleep(1) # Not needed (Lets you see the alert go away)
self.execute_script('window.prompt("My Prompt","defaultText");')
Expand All @@ -15,6 +16,7 @@ def test_alerts(self):
self.assert_equal(alert.text, "My Prompt") # Not input field
self.dismiss_alert()
self.sleep(1) # Not needed (Lets you see the alert go away)
self.assert_false(self.is_alert_present())
if self.browser == "safari" and self._reuse_session:
# Alerts can freeze Safari if reusing the browser session
self.driver.quit()
5 changes: 3 additions & 2 deletions help_docs/customizing_test_runs.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ pytest my_first_test.py --settings-file=custom_settings.py
--sjw # (Skip JS Waits for readyState to be "complete" or Angular to load.)
--wfa # (Wait for AngularJS to be done loading after specific web actions.)
--pls=PLS # (Set pageLoadStrategy on Chrome: "normal", "eager", or "none".)
--headless # (Run tests in headless mode. The default arg on Linux OS.)
--headless2 # (Use the new headless mode, which supports extensions.)
--headless # (The default headless mode. Linux uses this mode by default.)
--headless1 # (Use Chrome's old headless mode. Fast, but has limitations.)
--headless2 # (Use Chrome's new headless mode, which supports extensions.)
--headed # (Run tests in headed/GUI mode on Linux OS, where not default.)
--xvfb # (Run tests using the Xvfb virtual display server on Linux OS.)
--xvfb-metrics=STRING # (Set Xvfb display size on Linux: "Width,Height".)
Expand Down
2 changes: 2 additions & 0 deletions help_docs/method_summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,8 @@ self.inspect_html()

self.is_valid_url(url)

self.is_alert_present()

self.is_online()

self.is_chromium()
Expand Down
2 changes: 1 addition & 1 deletion mkdocs_build/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ lxml==5.3.0
pyquery==2.0.1
readtime==3.0.0
mkdocs==1.6.1
mkdocs-material==9.5.36
mkdocs-material==9.5.37
mkdocs-exclude-search==0.6.6
mkdocs-simple-hooks==0.1.5
mkdocs-material-extensions==1.3.1
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.31.0"
__version__ = "4.31.1"
14 changes: 12 additions & 2 deletions seleniumbase/behave/behave_sb.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@
-D sjw (Skip JS Waits for readyState to be "complete" or Angular to load.)
-D wfa (Wait for AngularJS to be done loading after specific web actions.)
-D pls=PLS (Set pageLoadStrategy on Chrome: "normal", "eager", or "none".)
-D headless (Run tests in headless mode. The default arg on Linux OS.)
-D headless2 (Use the new headless mode, which supports extensions.)
-D headless (The default headless mode. Linux uses this mode by default.)
-D headless1 (Use Chrome's old headless mode. Fast, but has limitations.)
-D headless2 (Use Chrome's new headless mode, which supports extensions.)
-D headed (Run tests in headed/GUI mode on Linux OS, where not default.)
-D xvfb (Run tests using the Xvfb virtual display server on Linux OS.)
-D xvfb-metrics=STRING (Set Xvfb display size on Linux: "Width,Height".)
Expand Down Expand Up @@ -144,6 +145,7 @@ def get_configured_sb(context):
sb.browser = "chrome"
sb.is_behave = True
sb.headless = False
sb.headless1 = False
sb.headless2 = False
sb.headless_active = False
sb.headed = False
Expand Down Expand Up @@ -296,6 +298,11 @@ def get_configured_sb(context):
sb.headless = True
continue
# Handle: -D headless2
if low_key == "headless1":
sb.headless1 = True
sb.headless = True
continue
# Handle: -D headless2
if low_key == "headless2":
sb.headless2 = True
continue
Expand Down Expand Up @@ -864,6 +871,7 @@ def get_configured_sb(context):
# Recorder Mode can still optimize scripts in "-D headless2" mode.
if sb.recorder_ext and sb.headless:
sb.headless = False
sb.headless1 = False
sb.headless2 = True
if sb.headless2 and sb.browser == "firefox":
sb.headless2 = False # Only for Chromium browsers
Expand Down Expand Up @@ -900,11 +908,13 @@ def get_configured_sb(context):
# Recorder Mode can still optimize scripts in --headless2 mode.
if sb.recorder_mode and sb.headless:
sb.headless = False
sb.headless1 = False
sb.headless2 = True
if not sb.headless and not sb.headless2:
sb.headed = True
if sb.browser == "safari" and sb.headless:
sb.headless = False # Safari doesn't support headless mode
sb.headless1 = False
if sb.save_screenshot_after_test and sb.no_screenshot_after_test:
sb.save_screenshot_after_test = False # "no_screenshot" has priority
if sb.servername != "localhost":
Expand Down
47 changes: 47 additions & 0 deletions seleniumbase/console_scripts/logo_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
http://www.patorjk.com/software/taag/#p=display&f=Slant&t=SeleniumBase """

import colorama
import os
import sys
from contextlib import suppress

r"""
______ __ _ ____
Expand Down Expand Up @@ -66,4 +68,49 @@ def get_seleniumbase_logo():
sb += " "
sb += cr
sb += cr
with suppress(Exception):
terminal_width = os.get_terminal_size().columns
if isinstance(terminal_width, int) and terminal_width >= 66:
return sb

# If the logo is wider than the screen width, use a smaller one:
r"""
___ _ _ ___
/ __| ___| |___ _ _ (_)_ _ _ __ | _ ) __ _ ______
\__ \/ -_) / -_) ' \| | \| | ' \ | _ \/ _` (_-< -_)
|___/\___|_\___|_||_|_|\_,_|_|_|_\|___/\__,_/__|___|
"""
sb = " "
sb += cr
sb += "\n"
sb += c1
sb += " ___ _ _ "
sb += c2
sb += " ___ "
sb += cr
sb += "\n"
sb += c1
sb += "/ __| ___| |___ _ _ (_)_ _ _ __ "
sb += c2
sb += "| _ ) __ _ ______ "
sb += cr
sb += "\n"
sb += c1
sb += "\\__ \\/ -_) / -_) ' \\| | \\| | ' \\ "
sb += c2
sb += "| _ \\/ _` (_-< -_)"
sb += cr
sb += "\n"
sb += c1
sb += "|___/\\___|_\\___|_||_|_|\\_,_|_|_|_\\"
sb += c2
sb += "|___/\\__,_/__|___|"
sb += cr
sb += "\n"
sb += c3
sb += " "
sb += c4
sb += " "
sb += cr
sb += cr
return sb
11 changes: 7 additions & 4 deletions seleniumbase/console_scripts/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
def show_usage():
show_basic_usage()
sc = ""
sc += ' Type "sbase help [COMMAND]" for specific command info.\n'
sc += ' For info on all commands, type: "seleniumbase --help".\n'
sc += ' Type "sbase help [COMMAND]" for specific info.\n'
sc += ' For all commands, type: "seleniumbase --help".\n'
sc += ' Use "pytest" for running tests.\n'
if "linux" not in sys.platform:
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
Expand All @@ -76,12 +76,15 @@ def show_basic_usage():

seleniumbase_logo = logo_helper.get_seleniumbase_logo()
print(seleniumbase_logo)
time.sleep(0.044)
print("")
time.sleep(0.28) # Enough time to see the logo
time.sleep(0.033)
show_package_location()
time.sleep(0.032)
show_version_info()
time.sleep(0.031)
print("")
time.sleep(0.62) # Enough time to see the version
time.sleep(0.68) # Enough time to see the logo & version
sc = ""
sc += ' * USAGE: "seleniumbase [COMMAND] [PARAMETERS]"\n'
sc += ' * OR: "sbase [COMMAND] [PARAMETERS]"\n'
Expand Down
46 changes: 41 additions & 5 deletions seleniumbase/core/browser_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ def extend_driver(driver):
driver.is_exact_text_visible = DM.is_exact_text_visible
driver.is_attribute_present = DM.is_attribute_present
driver.is_non_empty_text_visible = DM.is_non_empty_text_visible
driver.is_valid_url = DM.is_valid_url
driver.is_alert_present = DM.is_alert_present
driver.is_online = DM.is_online
driver.js_click = DM.js_click
driver.get_text = DM.get_text
Expand Down Expand Up @@ -1553,6 +1555,7 @@ def _set_chrome_options(
log_cdp_events,
no_sandbox,
disable_gpu,
headless1,
headless2,
incognito,
guest_mode,
Expand Down Expand Up @@ -1771,7 +1774,10 @@ def _set_chrome_options(
pass # Processed After Version Check
elif headless:
if not undetectable:
chrome_options.add_argument("--headless")
if headless1:
chrome_options.add_argument("--headless=old")
else:
chrome_options.add_argument("--headless")
if undetectable and servername and servername != "localhost":
# The Grid Node will need Chrome 109 or newer
chrome_options.add_argument("--headless=new")
Expand Down Expand Up @@ -2193,6 +2199,7 @@ def get_driver(
log_cdp_events=False,
no_sandbox=False,
disable_gpu=False,
headless1=False,
headless2=False,
incognito=False,
guest_mode=False,
Expand Down Expand Up @@ -2406,6 +2413,7 @@ def get_driver(
log_cdp_events,
no_sandbox,
disable_gpu,
headless1,
headless2,
incognito,
guest_mode,
Expand Down Expand Up @@ -2462,6 +2470,7 @@ def get_driver(
log_cdp_events,
no_sandbox,
disable_gpu,
headless1,
headless2,
incognito,
guest_mode,
Expand Down Expand Up @@ -2522,6 +2531,7 @@ def get_remote_driver(
log_cdp_events,
no_sandbox,
disable_gpu,
headless1,
headless2,
incognito,
guest_mode,
Expand Down Expand Up @@ -2657,6 +2667,7 @@ def get_remote_driver(
log_cdp_events,
no_sandbox,
disable_gpu,
headless1,
headless2,
incognito,
guest_mode,
Expand Down Expand Up @@ -2829,6 +2840,7 @@ def get_remote_driver(
log_cdp_events,
no_sandbox,
disable_gpu,
headless1,
headless2,
incognito,
guest_mode,
Expand Down Expand Up @@ -2948,6 +2960,7 @@ def get_local_driver(
log_cdp_events,
no_sandbox,
disable_gpu,
headless1,
headless2,
incognito,
guest_mode,
Expand Down Expand Up @@ -3425,8 +3438,14 @@ def get_local_driver(
else:
pass # Will need Xvfb on Linux
elif headless:
if "--headless" not in edge_options.arguments:
edge_options.add_argument("--headless")
if (
"--headless" not in edge_options.arguments
and "--headless=old" not in edge_options.arguments
):
if headless1:
edge_options.add_argument("--headless=old")
else:
edge_options.add_argument("--headless")
if mobile_emulator and not is_using_uc(undetectable, browser_name):
emulator_settings = {}
device_metrics = {}
Expand Down Expand Up @@ -3788,6 +3807,7 @@ def get_local_driver(
log_cdp_events,
no_sandbox,
disable_gpu,
headless1,
headless2,
incognito,
guest_mode,
Expand Down Expand Up @@ -3960,8 +3980,14 @@ def get_local_driver(
except Exception:
pass # Will need Xvfb on Linux
elif headless:
if "--headless" not in chrome_options.arguments:
chrome_options.add_argument("--headless")
if (
"--headless" not in chrome_options.arguments
and "--headless=old" not in chrome_options.arguments
):
if headless1:
chrome_options.add_argument("--headless=old")
else:
chrome_options.add_argument("--headless")
if LOCAL_CHROMEDRIVER and os.path.exists(LOCAL_CHROMEDRIVER):
try:
make_driver_executable_if_not(LOCAL_CHROMEDRIVER)
Expand Down Expand Up @@ -4227,6 +4253,12 @@ def get_local_driver(
chrome_options.arguments.remove(
"--headless"
)
if "--headless=old" in (
chrome_options.arguments
):
chrome_options.arguments.remove(
"--headless=old"
)
uc_chrome_version = None
if (
use_version.isnumeric()
Expand Down Expand Up @@ -4300,6 +4332,7 @@ def get_local_driver(
False, # log_cdp_events
no_sandbox,
disable_gpu,
False, # headless1
False, # headless2
incognito,
guest_mode,
Expand Down Expand Up @@ -4541,6 +4574,7 @@ def get_local_driver(
False, # log_cdp_events
no_sandbox,
disable_gpu,
False, # headless1
False, # headless2
incognito,
guest_mode,
Expand Down Expand Up @@ -4792,6 +4826,8 @@ def get_local_driver(
)
if "--headless" in chrome_options.arguments:
chrome_options.arguments.remove("--headless")
if "--headless=old" in chrome_options.arguments:
chrome_options.arguments.remove("--headless=old")
service = ChromeService(
log_output=os.devnull,
service_args=["--disable-build-check"]
Expand Down
11 changes: 11 additions & 0 deletions seleniumbase/core/sb_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ def is_non_empty_text_visible(self, *args, **kwargs):
self.driver, *args, **kwargs
)

def is_valid_url(self, url):
"""Return True if the url is a valid url."""
return page_utils.is_valid_url(url)

def is_alert_present(self):
try:
self.driver.switch_to.alert
return True
except Exception:
return False

def is_online(self):
return self.driver.execute_script("return navigator.onLine;")

Expand Down
Loading