Skip to content

Commit 5c31bbf

Browse files
authored
Merge pull request #3163 from seleniumbase/update-options-and-methods
Update options, methods, and docstrings
2 parents 4310a4d + 6ac2c0d commit 5c31bbf

File tree

17 files changed

+382
-194
lines changed

17 files changed

+382
-194
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,9 @@ pytest test_coffee_cart.py --trace
653653
--sjw # (Skip JS Waits for readyState to be "complete" or Angular to load.)
654654
--wfa # (Wait for AngularJS to be done loading after specific web actions.)
655655
--pls=PLS # (Set pageLoadStrategy on Chrome: "normal", "eager", or "none".)
656-
--headless # (Run tests in headless mode. The default arg on Linux OS.)
657-
--headless2 # (Use the new headless mode, which supports extensions.)
656+
--headless # (The default headless mode. Linux uses this mode by default.)
657+
--headless1 # (Use Chrome's old headless mode. Fast, but has limitations.)
658+
--headless2 # (Use Chrome's new headless mode, which supports extensions.)
658659
--headed # (Run tests in headed/GUI mode on Linux OS, where not default.)
659660
--xvfb # (Run tests using the Xvfb virtual display server on Linux OS.)
660661
--xvfb-metrics=STRING # (Set Xvfb display size on Linux: "Width,Height".)

examples/handle_alert_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ def test_alerts(self):
77
self.open("about:blank")
88
self.execute_script('window.alert("ALERT!!!");')
99
self.sleep(1) # Not needed (Lets you see the alert pop up)
10+
self.assert_true(self.is_alert_present())
1011
self.accept_alert()
1112
self.sleep(1) # Not needed (Lets you see the alert go away)
1213
self.execute_script('window.prompt("My Prompt","defaultText");')
@@ -15,6 +16,7 @@ def test_alerts(self):
1516
self.assert_equal(alert.text, "My Prompt") # Not input field
1617
self.dismiss_alert()
1718
self.sleep(1) # Not needed (Lets you see the alert go away)
19+
self.assert_false(self.is_alert_present())
1820
if self.browser == "safari" and self._reuse_session:
1921
# Alerts can freeze Safari if reusing the browser session
2022
self.driver.quit()

help_docs/customizing_test_runs.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ pytest my_first_test.py --settings-file=custom_settings.py
144144
--sjw # (Skip JS Waits for readyState to be "complete" or Angular to load.)
145145
--wfa # (Wait for AngularJS to be done loading after specific web actions.)
146146
--pls=PLS # (Set pageLoadStrategy on Chrome: "normal", "eager", or "none".)
147-
--headless # (Run tests in headless mode. The default arg on Linux OS.)
148-
--headless2 # (Use the new headless mode, which supports extensions.)
147+
--headless # (The default headless mode. Linux uses this mode by default.)
148+
--headless1 # (Use Chrome's old headless mode. Fast, but has limitations.)
149+
--headless2 # (Use Chrome's new headless mode, which supports extensions.)
149150
--headed # (Run tests in headed/GUI mode on Linux OS, where not default.)
150151
--xvfb # (Run tests using the Xvfb virtual display server on Linux OS.)
151152
--xvfb-metrics=STRING # (Set Xvfb display size on Linux: "Width,Height".)

help_docs/method_summary.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,8 @@ self.inspect_html()
550550

551551
self.is_valid_url(url)
552552

553+
self.is_alert_present()
554+
553555
self.is_online()
554556

555557
self.is_chromium()

mkdocs_build/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ lxml==5.3.0
2020
pyquery==2.0.1
2121
readtime==3.0.0
2222
mkdocs==1.6.1
23-
mkdocs-material==9.5.36
23+
mkdocs-material==9.5.37
2424
mkdocs-exclude-search==0.6.6
2525
mkdocs-simple-hooks==0.1.5
2626
mkdocs-material-extensions==1.3.1

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__ = "4.31.0"
2+
__version__ = "4.31.1"

seleniumbase/behave/behave_sb.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@
4444
-D sjw (Skip JS Waits for readyState to be "complete" or Angular to load.)
4545
-D wfa (Wait for AngularJS to be done loading after specific web actions.)
4646
-D pls=PLS (Set pageLoadStrategy on Chrome: "normal", "eager", or "none".)
47-
-D headless (Run tests in headless mode. The default arg on Linux OS.)
48-
-D headless2 (Use the new headless mode, which supports extensions.)
47+
-D headless (The default headless mode. Linux uses this mode by default.)
48+
-D headless1 (Use Chrome's old headless mode. Fast, but has limitations.)
49+
-D headless2 (Use Chrome's new headless mode, which supports extensions.)
4950
-D headed (Run tests in headed/GUI mode on Linux OS, where not default.)
5051
-D xvfb (Run tests using the Xvfb virtual display server on Linux OS.)
5152
-D xvfb-metrics=STRING (Set Xvfb display size on Linux: "Width,Height".)
@@ -144,6 +145,7 @@ def get_configured_sb(context):
144145
sb.browser = "chrome"
145146
sb.is_behave = True
146147
sb.headless = False
148+
sb.headless1 = False
147149
sb.headless2 = False
148150
sb.headless_active = False
149151
sb.headed = False
@@ -296,6 +298,11 @@ def get_configured_sb(context):
296298
sb.headless = True
297299
continue
298300
# Handle: -D headless2
301+
if low_key == "headless1":
302+
sb.headless1 = True
303+
sb.headless = True
304+
continue
305+
# Handle: -D headless2
299306
if low_key == "headless2":
300307
sb.headless2 = True
301308
continue
@@ -864,6 +871,7 @@ def get_configured_sb(context):
864871
# Recorder Mode can still optimize scripts in "-D headless2" mode.
865872
if sb.recorder_ext and sb.headless:
866873
sb.headless = False
874+
sb.headless1 = False
867875
sb.headless2 = True
868876
if sb.headless2 and sb.browser == "firefox":
869877
sb.headless2 = False # Only for Chromium browsers
@@ -900,11 +908,13 @@ def get_configured_sb(context):
900908
# Recorder Mode can still optimize scripts in --headless2 mode.
901909
if sb.recorder_mode and sb.headless:
902910
sb.headless = False
911+
sb.headless1 = False
903912
sb.headless2 = True
904913
if not sb.headless and not sb.headless2:
905914
sb.headed = True
906915
if sb.browser == "safari" and sb.headless:
907916
sb.headless = False # Safari doesn't support headless mode
917+
sb.headless1 = False
908918
if sb.save_screenshot_after_test and sb.no_screenshot_after_test:
909919
sb.save_screenshot_after_test = False # "no_screenshot" has priority
910920
if sb.servername != "localhost":

seleniumbase/console_scripts/logo_helper.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
http://www.patorjk.com/software/taag/#p=display&f=Slant&t=SeleniumBase """
44

55
import colorama
6+
import os
67
import sys
8+
from contextlib import suppress
79

810
r"""
911
______ __ _ ____
@@ -66,4 +68,49 @@ def get_seleniumbase_logo():
6668
sb += " "
6769
sb += cr
6870
sb += cr
71+
with suppress(Exception):
72+
terminal_width = os.get_terminal_size().columns
73+
if isinstance(terminal_width, int) and terminal_width >= 66:
74+
return sb
75+
76+
# If the logo is wider than the screen width, use a smaller one:
77+
r"""
78+
___ _ _ ___
79+
/ __| ___| |___ _ _ (_)_ _ _ __ | _ ) __ _ ______
80+
\__ \/ -_) / -_) ' \| | \| | ' \ | _ \/ _` (_-< -_)
81+
|___/\___|_\___|_||_|_|\_,_|_|_|_\|___/\__,_/__|___|
82+
"""
83+
sb = " "
84+
sb += cr
85+
sb += "\n"
86+
sb += c1
87+
sb += " ___ _ _ "
88+
sb += c2
89+
sb += " ___ "
90+
sb += cr
91+
sb += "\n"
92+
sb += c1
93+
sb += "/ __| ___| |___ _ _ (_)_ _ _ __ "
94+
sb += c2
95+
sb += "| _ ) __ _ ______ "
96+
sb += cr
97+
sb += "\n"
98+
sb += c1
99+
sb += "\\__ \\/ -_) / -_) ' \\| | \\| | ' \\ "
100+
sb += c2
101+
sb += "| _ \\/ _` (_-< -_)"
102+
sb += cr
103+
sb += "\n"
104+
sb += c1
105+
sb += "|___/\\___|_\\___|_||_|_|\\_,_|_|_|_\\"
106+
sb += c2
107+
sb += "|___/\\__,_/__|___|"
108+
sb += cr
109+
sb += "\n"
110+
sb += c3
111+
sb += " "
112+
sb += c4
113+
sb += " "
114+
sb += cr
115+
sb += cr
69116
return sb

seleniumbase/console_scripts/run.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
def show_usage():
5555
show_basic_usage()
5656
sc = ""
57-
sc += ' Type "sbase help [COMMAND]" for specific command info.\n'
58-
sc += ' For info on all commands, type: "seleniumbase --help".\n'
57+
sc += ' Type "sbase help [COMMAND]" for specific info.\n'
58+
sc += ' For all commands, type: "seleniumbase --help".\n'
5959
sc += ' Use "pytest" for running tests.\n'
6060
if "linux" not in sys.platform:
6161
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
@@ -76,12 +76,15 @@ def show_basic_usage():
7676

7777
seleniumbase_logo = logo_helper.get_seleniumbase_logo()
7878
print(seleniumbase_logo)
79+
time.sleep(0.044)
7980
print("")
80-
time.sleep(0.28) # Enough time to see the logo
81+
time.sleep(0.033)
8182
show_package_location()
83+
time.sleep(0.032)
8284
show_version_info()
85+
time.sleep(0.031)
8386
print("")
84-
time.sleep(0.62) # Enough time to see the version
87+
time.sleep(0.68) # Enough time to see the logo & version
8588
sc = ""
8689
sc += ' * USAGE: "seleniumbase [COMMAND] [PARAMETERS]"\n'
8790
sc += ' * OR: "sbase [COMMAND] [PARAMETERS]"\n'

seleniumbase/core/browser_launcher.py

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ def extend_driver(driver):
203203
driver.is_exact_text_visible = DM.is_exact_text_visible
204204
driver.is_attribute_present = DM.is_attribute_present
205205
driver.is_non_empty_text_visible = DM.is_non_empty_text_visible
206+
driver.is_valid_url = DM.is_valid_url
207+
driver.is_alert_present = DM.is_alert_present
206208
driver.is_online = DM.is_online
207209
driver.js_click = DM.js_click
208210
driver.get_text = DM.get_text
@@ -1553,6 +1555,7 @@ def _set_chrome_options(
15531555
log_cdp_events,
15541556
no_sandbox,
15551557
disable_gpu,
1558+
headless1,
15561559
headless2,
15571560
incognito,
15581561
guest_mode,
@@ -1771,7 +1774,10 @@ def _set_chrome_options(
17711774
pass # Processed After Version Check
17721775
elif headless:
17731776
if not undetectable:
1774-
chrome_options.add_argument("--headless")
1777+
if headless1:
1778+
chrome_options.add_argument("--headless=old")
1779+
else:
1780+
chrome_options.add_argument("--headless")
17751781
if undetectable and servername and servername != "localhost":
17761782
# The Grid Node will need Chrome 109 or newer
17771783
chrome_options.add_argument("--headless=new")
@@ -2193,6 +2199,7 @@ def get_driver(
21932199
log_cdp_events=False,
21942200
no_sandbox=False,
21952201
disable_gpu=False,
2202+
headless1=False,
21962203
headless2=False,
21972204
incognito=False,
21982205
guest_mode=False,
@@ -2406,6 +2413,7 @@ def get_driver(
24062413
log_cdp_events,
24072414
no_sandbox,
24082415
disable_gpu,
2416+
headless1,
24092417
headless2,
24102418
incognito,
24112419
guest_mode,
@@ -2462,6 +2470,7 @@ def get_driver(
24622470
log_cdp_events,
24632471
no_sandbox,
24642472
disable_gpu,
2473+
headless1,
24652474
headless2,
24662475
incognito,
24672476
guest_mode,
@@ -2522,6 +2531,7 @@ def get_remote_driver(
25222531
log_cdp_events,
25232532
no_sandbox,
25242533
disable_gpu,
2534+
headless1,
25252535
headless2,
25262536
incognito,
25272537
guest_mode,
@@ -2657,6 +2667,7 @@ def get_remote_driver(
26572667
log_cdp_events,
26582668
no_sandbox,
26592669
disable_gpu,
2670+
headless1,
26602671
headless2,
26612672
incognito,
26622673
guest_mode,
@@ -2829,6 +2840,7 @@ def get_remote_driver(
28292840
log_cdp_events,
28302841
no_sandbox,
28312842
disable_gpu,
2843+
headless1,
28322844
headless2,
28332845
incognito,
28342846
guest_mode,
@@ -2948,6 +2960,7 @@ def get_local_driver(
29482960
log_cdp_events,
29492961
no_sandbox,
29502962
disable_gpu,
2963+
headless1,
29512964
headless2,
29522965
incognito,
29532966
guest_mode,
@@ -3425,8 +3438,14 @@ def get_local_driver(
34253438
else:
34263439
pass # Will need Xvfb on Linux
34273440
elif headless:
3428-
if "--headless" not in edge_options.arguments:
3429-
edge_options.add_argument("--headless")
3441+
if (
3442+
"--headless" not in edge_options.arguments
3443+
and "--headless=old" not in edge_options.arguments
3444+
):
3445+
if headless1:
3446+
edge_options.add_argument("--headless=old")
3447+
else:
3448+
edge_options.add_argument("--headless")
34303449
if mobile_emulator and not is_using_uc(undetectable, browser_name):
34313450
emulator_settings = {}
34323451
device_metrics = {}
@@ -3788,6 +3807,7 @@ def get_local_driver(
37883807
log_cdp_events,
37893808
no_sandbox,
37903809
disable_gpu,
3810+
headless1,
37913811
headless2,
37923812
incognito,
37933813
guest_mode,
@@ -3960,8 +3980,14 @@ def get_local_driver(
39603980
except Exception:
39613981
pass # Will need Xvfb on Linux
39623982
elif headless:
3963-
if "--headless" not in chrome_options.arguments:
3964-
chrome_options.add_argument("--headless")
3983+
if (
3984+
"--headless" not in chrome_options.arguments
3985+
and "--headless=old" not in chrome_options.arguments
3986+
):
3987+
if headless1:
3988+
chrome_options.add_argument("--headless=old")
3989+
else:
3990+
chrome_options.add_argument("--headless")
39653991
if LOCAL_CHROMEDRIVER and os.path.exists(LOCAL_CHROMEDRIVER):
39663992
try:
39673993
make_driver_executable_if_not(LOCAL_CHROMEDRIVER)
@@ -4227,6 +4253,12 @@ def get_local_driver(
42274253
chrome_options.arguments.remove(
42284254
"--headless"
42294255
)
4256+
if "--headless=old" in (
4257+
chrome_options.arguments
4258+
):
4259+
chrome_options.arguments.remove(
4260+
"--headless=old"
4261+
)
42304262
uc_chrome_version = None
42314263
if (
42324264
use_version.isnumeric()
@@ -4300,6 +4332,7 @@ def get_local_driver(
43004332
False, # log_cdp_events
43014333
no_sandbox,
43024334
disable_gpu,
4335+
False, # headless1
43034336
False, # headless2
43044337
incognito,
43054338
guest_mode,
@@ -4541,6 +4574,7 @@ def get_local_driver(
45414574
False, # log_cdp_events
45424575
no_sandbox,
45434576
disable_gpu,
4577+
False, # headless1
45444578
False, # headless2
45454579
incognito,
45464580
guest_mode,
@@ -4792,6 +4826,8 @@ def get_local_driver(
47924826
)
47934827
if "--headless" in chrome_options.arguments:
47944828
chrome_options.arguments.remove("--headless")
4829+
if "--headless=old" in chrome_options.arguments:
4830+
chrome_options.arguments.remove("--headless=old")
47954831
service = ChromeService(
47964832
log_output=os.devnull,
47974833
service_args=["--disable-build-check"]

0 commit comments

Comments
 (0)