Skip to content

Commit 270d409

Browse files
authored
Merge pull request #3454 from seleniumbase/add-shortcuts-and-error-handling
Add shortcuts and error-handling
2 parents 36bdf14 + 6343194 commit 270d409

9 files changed

+90
-5
lines changed

help_docs/customizing_test_runs.md

+24-2
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ pytest --headless -n8 --dashboard --html=report.html -v --rs --crumbs
337337

338338
The above not only runs tests in parallel processes, but it also tells tests in the same process to share the same browser session, runs the tests in headless mode, displays the full name of each test on a separate line, creates a real-time dashboard of the test results, and creates a full report after all tests complete.
339339

340+
--------
341+
340342
🎛️ For extra speed, run your tests using `chrome-headless-shell`:
341343

342344
First, get `chrome-headless-shell` if you don't already have it:
@@ -345,10 +347,10 @@ First, get `chrome-headless-shell` if you don't already have it:
345347
sbase get chs
346348
```
347349

348-
Then, run scripts with `binary_location` / `bl` set to `"chs"`:
350+
Then, run scripts with `--chs` / `chs=True`:
349351

350352
```bash
351-
pytest --bl="chs" -n8 --dashboard --html=report.html -v --rs
353+
pytest --chs -n8 --dashboard --html=report.html -v --rs
352354
```
353355

354356
That makes your tests run very quickly in headless mode.
@@ -486,6 +488,26 @@ With the `SB()` and `Driver()` formats, the binary location is set via the `bina
486488

487489
--------
488490

491+
🎛️ To use the special `Chrome for Testing` binary:
492+
493+
```bash
494+
sbase get cft
495+
```
496+
497+
Then, run scripts with `--cft` / `cft=True`:
498+
499+
```bash
500+
pytest --cft -n8 --dashboard --html=report.html -v --rs --headless
501+
```
502+
503+
--------
504+
505+
(Note that `--chs` / `chs=True` activates `Chrome-Headless-Shell`)
506+
507+
`Chrome-Headless-Shell` is the fastest version of Chrome, designed specifically for headless automation. (This mode is NOT compatible with UC Mode!)
508+
509+
--------
510+
489511
<h3><img src="https://seleniumbase.github.io/img/green_logo.png" title="SeleniumBase" width="32" /> Customizing default settings:</h3>
490512

491513
🎛️ An easy way to override [seleniumbase/config/settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py) is by using a custom settings file.

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ packaging>=24.2
33
setuptools~=70.2;python_version<"3.10"
44
setuptools>=75.8.0;python_version>="3.10"
55
wheel>=0.45.1
6-
attrs>=24.3.0
6+
attrs>=25.1.0
77
certifi>=2024.12.14
88
exceptiongroup>=1.2.2
99
websockets~=13.1;python_version<"3.9"

seleniumbase/__version__.py

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

seleniumbase/core/browser_launcher.py

+7
Original file line numberDiff line numberDiff line change
@@ -2651,6 +2651,13 @@ def get_driver(
26512651
if headless2 and browser_name == constants.Browser.FIREFOX:
26522652
headless2 = False # Only for Chromium
26532653
headless = True
2654+
if (
2655+
is_using_uc(undetectable, browser_name)
2656+
and binary_location
2657+
and isinstance(binary_location, str)
2658+
and binary_location.lower() == "chs"
2659+
):
2660+
raise Exception("UC Mode can't be used with Chrome-Headless-Shell!")
26542661
if (
26552662
binary_location
26562663
and isinstance(binary_location, str)

seleniumbase/plugins/driver_manager.py

+10
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ def Driver(
137137
guest=None, # Shortcut / Duplicate of "guest_mode".
138138
wire=None, # Shortcut / Duplicate of "use_wire".
139139
pls=None, # Shortcut / Duplicate of "page_load_strategy".
140+
cft=None, # Use "Chrome for Testing"
141+
chs=None, # Use "Chrome-Headless-Shell"
140142
):
141143
"""
142144
* SeleniumBase Driver as a Python Context Manager or a returnable object. *
@@ -550,6 +552,14 @@ def Driver(
550552
if arg.startswith("--bl="):
551553
binary_location = arg.split("--bl=")[1]
552554
break
555+
if cft and not binary_location:
556+
binary_location = "cft"
557+
elif chs and not binary_location:
558+
binary_location = "chs"
559+
if "--cft" in sys_argv and not binary_location:
560+
binary_location = "cft"
561+
elif "--chs" in sys_argv and not binary_location:
562+
binary_location = "chs"
553563
if (
554564
binary_location
555565
and binary_location.lower() == "chs"

seleniumbase/plugins/pytest_plugin.py

+18
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,20 @@ def pytest_addoption(parser):
184184
default=False,
185185
help="""Shortcut for --browser=safari""",
186186
)
187+
parser.addoption(
188+
"--cft",
189+
action="store_true",
190+
dest="use_cft",
191+
default=False,
192+
help="""Shortcut for using `Chrome for Testing`""",
193+
)
194+
parser.addoption(
195+
"--chs",
196+
action="store_true",
197+
dest="use_chs",
198+
default=False,
199+
help="""Shortcut for using `Chrome-Headless-Shell`""",
200+
)
187201
parser.addoption(
188202
"--with-selenium",
189203
action="store_true",
@@ -1575,6 +1589,10 @@ def pytest_configure(config):
15751589
sb_config.extension_dir = config.getoption("extension_dir")
15761590
sb_config.disable_features = config.getoption("disable_features")
15771591
sb_config.binary_location = config.getoption("binary_location")
1592+
if config.getoption("use_cft") and not sb_config.binary_location:
1593+
sb_config.binary_location = "cft"
1594+
elif config.getoption("use_chs") and not sb_config.binary_location:
1595+
sb_config.binary_location = "chs"
15781596
if (
15791597
sb_config.binary_location
15801598
and sb_config.binary_location.lower() == "chs"

seleniumbase/plugins/sb_manager.py

+10
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ def SB(
119119
pls=None, # Shortcut / Duplicate of "page_load_strategy".
120120
sjw=None, # Shortcut / Duplicate of "skip_js_waits".
121121
wfa=None, # Shortcut / Duplicate of "wait_for_angularjs".
122+
cft=None, # Use "Chrome for Testing"
123+
chs=None, # Use "Chrome-Headless-Shell"
122124
save_screenshot=None, # Save a screenshot at the end of each test.
123125
no_screenshot=None, # No screenshots saved unless tests directly ask it.
124126
page_load_strategy=None, # Set Chrome PLS to "normal", "eager", or "none".
@@ -588,6 +590,14 @@ def SB(
588590
if arg.startswith("--bl="):
589591
binary_location = arg.split("--bl=")[1]
590592
break
593+
if cft and not binary_location:
594+
binary_location = "cft"
595+
elif chs and not binary_location:
596+
binary_location = "chs"
597+
if "--cft" in sys_argv and not binary_location:
598+
binary_location = "cft"
599+
elif "--chs" in sys_argv and not binary_location:
600+
binary_location = "chs"
591601
if (
592602
binary_location
593603
and binary_location.lower() == "chs"

seleniumbase/plugins/selenium_plugin.py

+18
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,20 @@ def options(self, parser, env):
144144
default=False,
145145
help="""Shortcut for --browser=safari""",
146146
)
147+
parser.addoption(
148+
"--cft",
149+
action="store_true",
150+
dest="use_cft",
151+
default=False,
152+
help="""Shortcut for using `Chrome for Testing`""",
153+
)
154+
parser.addoption(
155+
"--chs",
156+
action="store_true",
157+
dest="use_chs",
158+
default=False,
159+
help="""Shortcut for using `Chrome-Headless-Shell`""",
160+
)
147161
parser.addoption(
148162
"--cap_file",
149163
"--cap-file",
@@ -1203,6 +1217,10 @@ def beforeTest(self, test):
12031217
test.test.extension_dir = self.options.extension_dir
12041218
test.test.disable_features = self.options.disable_features
12051219
test.test.binary_location = self.options.binary_location
1220+
if self.options.use_cft and not test.test.binary_location:
1221+
test.test.binary_location = "cft"
1222+
elif self.options.use_chs and not test.test.binary_location:
1223+
test.test.binary_location = "chs"
12061224
if (
12071225
test.test.binary_location
12081226
and test.test.binary_location.lower() == "chs"

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
'setuptools~=70.2;python_version<"3.10"', # Newer ones had issues
153153
'setuptools>=75.8.0;python_version>="3.10"',
154154
'wheel>=0.45.1',
155-
'attrs>=24.3.0',
155+
'attrs>=25.1.0',
156156
"certifi>=2024.12.14",
157157
"exceptiongroup>=1.2.2",
158158
'websockets~=13.1;python_version<"3.9"',

0 commit comments

Comments
 (0)