Skip to content

Commit 988e613

Browse files
committed
Refactor the integrations for CFT and CHS
1 parent 09faaf7 commit 988e613

File tree

6 files changed

+47
-6
lines changed

6 files changed

+47
-6
lines changed

seleniumbase/behave/behave_sb.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
-D edge (Shortcut for "-D browser=edge".)
1212
-D firefox (Shortcut for "-D browser=firefox".)
1313
-D safari (Shortcut for "-D browser=safari".)
14+
-D cft (Shortcut for using `Chrome for Testing`)
15+
-D chs (Shortcut for using `Chrome-Headless-Shell`)
1416
-D settings-file=FILE (Override default SeleniumBase settings.)
1517
-D env=ENV (Set the test env. Access with "self.env" in tests.)
1618
-D account=STR (Set account. Access with "self.account" in tests.)
@@ -176,6 +178,7 @@ def get_configured_sb(context):
176178
sb.extension_zip = None
177179
sb.extension_dir = None
178180
sb.binary_location = None
181+
sb_config.binary_location = None
179182
sb.driver_version = None
180183
sb.page_load_strategy = None
181184
sb.database_env = "test"
@@ -488,6 +491,19 @@ def get_configured_sb(context):
488491
if binary_location == "true":
489492
binary_location = sb.binary_location # revert to default
490493
sb.binary_location = binary_location
494+
sb_config.binary_location = binary_location
495+
continue
496+
# Handle: -D cft
497+
if low_key in ["cft"] and not sb_config.binary_location:
498+
binary_location = "cft"
499+
sb.binary_location = binary_location
500+
sb_config.binary_location = binary_location
501+
continue
502+
# Handle: -D chs
503+
if low_key in ["chs"] and not sb_config.binary_location:
504+
binary_location = "chs"
505+
sb.binary_location = binary_location
506+
sb_config.binary_location = binary_location
491507
continue
492508
# Handle: -D driver-version=VER / driver_version=VER
493509
if low_key in ["driver-version", "driver_version"]:

seleniumbase/core/browser_launcher.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2880,9 +2880,15 @@ def get_driver(
28802880
browser=None, # A duplicate of browser_name to avoid confusion
28812881
):
28822882
driver_dir = DRIVER_DIR
2883-
if sb_config.binary_location == "cft":
2883+
if (
2884+
hasattr(sb_config, "binary_location")
2885+
and sb_config.binary_location == "cft"
2886+
):
28842887
driver_dir = DRIVER_DIR_CFT
2885-
if sb_config.binary_location == "chs":
2888+
if (
2889+
hasattr(sb_config, "binary_location")
2890+
and sb_config.binary_location == "chs"
2891+
):
28862892
driver_dir = DRIVER_DIR_CHS
28872893
if (
28882894
hasattr(sb_config, "settings")
@@ -3827,10 +3833,16 @@ def get_local_driver(
38273833
downloads_path = DOWNLOADS_FOLDER
38283834
driver_dir = DRIVER_DIR
38293835
special_chrome = False
3830-
if sb_config.binary_location == "cft":
3836+
if (
3837+
hasattr(sb_config, "binary_location")
3838+
and sb_config.binary_location == "cft"
3839+
):
38313840
special_chrome = True
38323841
driver_dir = DRIVER_DIR_CFT
3833-
if sb_config.binary_location == "chs":
3842+
if (
3843+
hasattr(sb_config, "binary_location")
3844+
and sb_config.binary_location == "chs"
3845+
):
38343846
special_chrome = True
38353847
driver_dir = DRIVER_DIR_CHS
38363848
if (

seleniumbase/core/log_helper.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,11 @@ def log_test_failure_data(test, test_logpath, driver, browser, url=None):
228228
traceback_message = None
229229
if hasattr(test, "is_behave") and test.is_behave:
230230
if sb_config.behave_scenario.status.name == "failed":
231-
if sb_config.behave_step.error_message:
231+
if (
232+
hasattr(sb_config, "behave_step")
233+
and hasattr(sb_config.behave_step, "error_message")
234+
and sb_config.behave_step.error_message
235+
):
232236
traceback_message = sb_config.behave_step.error_message
233237
else:
234238
format_exception = traceback.format_exception(

seleniumbase/fixtures/base_case.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16905,7 +16905,11 @@ def tearDown(self):
1690516905
self._last_page_url = "(Error: Unknown URL)"
1690616906
if hasattr(self, "is_behave") and self.is_behave and has_exception:
1690716907
if hasattr(sb_config, "pdb_option") and sb_config.pdb_option:
16908-
self.__activate_behave_post_mortem_debug_mode()
16908+
if (
16909+
hasattr(sb_config, "behave_step")
16910+
and hasattr(sb_config.behave_step, "exc_traceback")
16911+
):
16912+
self.__activate_behave_post_mortem_debug_mode()
1690916913
if self._final_debug:
1691016914
self.__activate_debug_mode_in_teardown()
1691116915
elif (

seleniumbase/plugins/pytest_plugin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def pytest_addoption(parser):
2828
--edge (Shortcut for "--browser=edge".)
2929
--firefox (Shortcut for "--browser=firefox".)
3030
--safari (Shortcut for "--browser=safari".)
31+
--cft (Shortcut for using `Chrome for Testing`)
32+
--chs (Shortcut for using `Chrome-Headless-Shell`)
3133
--settings-file=FILE (Override default SeleniumBase settings.)
3234
--env=ENV (Set the test env. Access with "self.env" in tests.)
3335
--account=STR (Set account. Access with "self.account" in tests.)

seleniumbase/plugins/selenium_plugin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class SeleniumBrowser(Plugin):
1616
--edge (Shortcut for "--browser=edge".)
1717
--firefox (Shortcut for "--browser=firefox".)
1818
--safari (Shortcut for "--browser=safari".)
19+
--cft (Shortcut for using `Chrome for Testing`)
20+
--chs (Shortcut for using `Chrome-Headless-Shell`)
1921
--user-data-dir=DIR (Set the Chrome user data directory to use.)
2022
--protocol=PROTOCOL (The Selenium Grid protocol: http|https.)
2123
--server=SERVER (The Selenium Grid server/IP used for tests.)
@@ -1221,6 +1223,7 @@ def beforeTest(self, test):
12211223
test.test.binary_location = "cft"
12221224
elif self.options.use_chs and not test.test.binary_location:
12231225
test.test.binary_location = "chs"
1226+
sb_config.binary_location = test.test.binary_location
12241227
if (
12251228
test.test.binary_location
12261229
and test.test.binary_location.lower() == "chs"

0 commit comments

Comments
 (0)