seleniumbase 4.30.7__py3-none-any.whl → 4.31.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. sbase/__init__.py +1 -0
  2. seleniumbase/__init__.py +2 -3
  3. seleniumbase/__version__.py +1 -1
  4. seleniumbase/behave/behave_sb.py +47 -9
  5. seleniumbase/config/settings.py +4 -0
  6. seleniumbase/console_scripts/sb_behave_gui.py +5 -5
  7. seleniumbase/console_scripts/sb_caseplans.py +6 -6
  8. seleniumbase/console_scripts/sb_commander.py +5 -5
  9. seleniumbase/console_scripts/sb_install.py +10 -2
  10. seleniumbase/console_scripts/sb_recorder.py +4 -4
  11. seleniumbase/core/browser_launcher.py +153 -104
  12. seleniumbase/core/mysql.py +1 -4
  13. seleniumbase/core/recorder_helper.py +24 -5
  14. seleniumbase/core/sb_driver.py +2 -3
  15. seleniumbase/core/settings_parser.py +4 -0
  16. seleniumbase/fixtures/base_case.py +307 -492
  17. seleniumbase/fixtures/js_utils.py +19 -52
  18. seleniumbase/fixtures/page_actions.py +3 -6
  19. seleniumbase/fixtures/page_utils.py +20 -58
  20. seleniumbase/plugins/base_plugin.py +2 -3
  21. seleniumbase/plugins/driver_manager.py +169 -3
  22. seleniumbase/plugins/pytest_plugin.py +34 -21
  23. seleniumbase/plugins/sb_manager.py +170 -3
  24. seleniumbase/plugins/selenium_plugin.py +52 -6
  25. seleniumbase/undetected/__init__.py +13 -38
  26. seleniumbase/undetected/dprocess.py +4 -6
  27. seleniumbase/undetected/options.py +3 -6
  28. seleniumbase/undetected/patcher.py +2 -3
  29. {seleniumbase-4.30.7.dist-info → seleniumbase-4.31.0.dist-info}/METADATA +108 -123
  30. {seleniumbase-4.30.7.dist-info → seleniumbase-4.31.0.dist-info}/RECORD +34 -45
  31. {seleniumbase-4.30.7.dist-info → seleniumbase-4.31.0.dist-info}/WHEEL +1 -1
  32. sbase/ReadMe.txt +0 -2
  33. seleniumbase/ReadMe.md +0 -25
  34. seleniumbase/common/ReadMe.md +0 -71
  35. seleniumbase/console_scripts/ReadMe.md +0 -734
  36. seleniumbase/drivers/ReadMe.md +0 -27
  37. seleniumbase/extensions/ReadMe.md +0 -12
  38. seleniumbase/masterqa/ReadMe.md +0 -61
  39. seleniumbase/resources/ReadMe.md +0 -31
  40. seleniumbase/resources/favicon.ico +0 -0
  41. seleniumbase/utilities/selenium_grid/ReadMe.md +0 -84
  42. seleniumbase/utilities/selenium_ide/ReadMe.md +0 -111
  43. {seleniumbase-4.30.7.dist-info → seleniumbase-4.31.0.dist-info}/LICENSE +0 -0
  44. {seleniumbase-4.30.7.dist-info → seleniumbase-4.31.0.dist-info}/entry_points.txt +0 -0
  45. {seleniumbase-4.30.7.dist-info → seleniumbase-4.31.0.dist-info}/top_level.txt +0 -0
@@ -4,6 +4,7 @@ import os
4
4
  import pytest
5
5
  import sys
6
6
  import time
7
+ from contextlib import suppress
7
8
  from seleniumbase import config as sb_config
8
9
  from seleniumbase.config import settings
9
10
  from seleniumbase.core import log_helper
@@ -65,6 +66,7 @@ def pytest_addoption(parser):
65
66
  --headless2 (Use the new headless mode, which supports extensions.)
66
67
  --headed (Run tests in headed/GUI mode on Linux OS, where not default.)
67
68
  --xvfb (Run tests using the Xvfb virtual display server on Linux OS.)
69
+ --xvfb-metrics=STRING (Set Xvfb display size on Linux: "Width,Height".)
68
70
  --locale=LOCALE_CODE (Set the Language Locale Code for the web browser.)
69
71
  --interval=SECONDS (The autoplay interval for presentations & tour steps)
70
72
  --start-page=URL (The starting URL for the web browser when tests begin.)
@@ -109,6 +111,7 @@ def pytest_addoption(parser):
109
111
  --rcs | --reuse-class-session (Reuse session for tests in class.)
110
112
  --crumbs (Delete all cookies between tests reusing a session.)
111
113
  --disable-beforeunload (Disable the "beforeunload" event on Chrome.)
114
+ --window-position=X,Y (Set the browser's starting window position.)
112
115
  --window-size=WIDTH,HEIGHT (Set the browser's starting window size.)
113
116
  --maximize (Start tests with the browser window maximized.)
114
117
  --screenshot (Save a screenshot at the end of each test.)
@@ -728,6 +731,17 @@ def pytest_addoption(parser):
728
731
  will no longer be enabled by default on Linux.
729
732
  Default: False. (Linux-ONLY!)""",
730
733
  )
734
+ parser.addoption(
735
+ "--xvfb-metrics",
736
+ "--xvfb_metrics",
737
+ action="store",
738
+ dest="xvfb_metrics",
739
+ default=None,
740
+ help="""Customize the Xvfb metrics (Width,Height) on Linux.
741
+ Format: A comma-separated string with the 2 values.
742
+ Examples: "1920,1080" or "1366,768" or "1024,768".
743
+ Default: None. (None: "1366,768". Min: "1024,768".)""",
744
+ )
731
745
  parser.addoption(
732
746
  "--locale_code",
733
747
  "--locale-code",
@@ -1229,6 +1243,17 @@ def pytest_addoption(parser):
1229
1243
  on Chromium browsers (Chrome or Edge).
1230
1244
  This is already the default Firefox option.""",
1231
1245
  )
1246
+ parser.addoption(
1247
+ "--window-position",
1248
+ "--window_position",
1249
+ action="store",
1250
+ dest="window_position",
1251
+ default=None,
1252
+ help="""The option to set the starting window x,y position
1253
+ Format: A comma-separated string with the 2 values.
1254
+ Example: "55,66"
1255
+ Default: None. (Will use default values if None)""",
1256
+ )
1232
1257
  parser.addoption(
1233
1258
  "--window-size",
1234
1259
  "--window_size",
@@ -1516,6 +1541,7 @@ def pytest_configure(config):
1516
1541
  sb_config.headless2 = False # Only for Chromium browsers
1517
1542
  sb_config.headed = config.getoption("headed")
1518
1543
  sb_config.xvfb = config.getoption("xvfb")
1544
+ sb_config.xvfb_metrics = config.getoption("xvfb_metrics")
1519
1545
  sb_config.locale_code = config.getoption("locale_code")
1520
1546
  sb_config.interval = config.getoption("interval")
1521
1547
  sb_config.start_page = config.getoption("start_page")
@@ -1624,6 +1650,7 @@ def pytest_configure(config):
1624
1650
  sb_config.shared_driver = None # The default driver for session reuse
1625
1651
  sb_config.crumbs = config.getoption("crumbs")
1626
1652
  sb_config._disable_beforeunload = config.getoption("_disable_beforeunload")
1653
+ sb_config.window_position = config.getoption("window_position")
1627
1654
  sb_config.window_size = config.getoption("window_size")
1628
1655
  sb_config.maximize_option = config.getoption("maximize_option")
1629
1656
  sb_config.save_screenshot = config.getoption("save_screenshot")
@@ -1822,10 +1849,8 @@ def _create_dashboard_assets_():
1822
1849
  abs_path = os.path.abspath(".")
1823
1850
  assets_folder = os.path.join(abs_path, "assets")
1824
1851
  if not os.path.exists(assets_folder):
1825
- try:
1852
+ with suppress(Exception):
1826
1853
  os.makedirs(assets_folder, exist_ok=True)
1827
- except Exception:
1828
- pass
1829
1854
  pytest_style_css = os.path.join(assets_folder, "pytest_style.css")
1830
1855
  add_pytest_style_css = True
1831
1856
  if os.path.exists(pytest_style_css):
@@ -1897,12 +1922,10 @@ def pytest_collection_finish(session):
1897
1922
  dash_path = os.path.join(os.getcwd(), "dashboard.html")
1898
1923
  dash_url = "file://" + dash_path.replace("\\", "/")
1899
1924
  star_len = len("Dashboard: ") + len(dash_url)
1900
- try:
1925
+ with suppress(Exception):
1901
1926
  terminal_size = os.get_terminal_size().columns
1902
1927
  if terminal_size > 30 and star_len > terminal_size:
1903
1928
  star_len = terminal_size
1904
- except Exception:
1905
- pass
1906
1929
  stars = "*" * star_len
1907
1930
  c1 = ""
1908
1931
  cr = ""
@@ -1944,11 +1967,11 @@ def pytest_runtest_teardown(item):
1944
1967
  (Has zero effect on tests using --reuse-session / --rs)"""
1945
1968
  if "--co" in sys_argv or "--collect-only" in sys_argv:
1946
1969
  return
1947
- try:
1970
+ with suppress(Exception):
1948
1971
  if hasattr(item, "_testcase") or hasattr(sb_config, "_sb_pdb_driver"):
1949
1972
  if hasattr(item, "_testcase"):
1950
1973
  self = item._testcase
1951
- try:
1974
+ with suppress(Exception):
1952
1975
  if (
1953
1976
  hasattr(self, "driver")
1954
1977
  and self.driver
@@ -1956,22 +1979,18 @@ def pytest_runtest_teardown(item):
1956
1979
  ):
1957
1980
  if not (is_windows or self.driver.service.process):
1958
1981
  self.driver.quit()
1959
- except Exception:
1960
- pass
1961
1982
  elif (
1962
1983
  hasattr(sb_config, "_sb_pdb_driver")
1963
1984
  and sb_config._sb_pdb_driver
1964
1985
  ):
1965
- try:
1986
+ with suppress(Exception):
1966
1987
  if (
1967
1988
  not is_windows
1968
1989
  or sb_config._sb_pdb_driver.service.process
1969
1990
  ):
1970
1991
  sb_config._sb_pdb_driver.quit()
1971
1992
  sb_config._sb_pdb_driver = None
1972
- except Exception:
1973
- pass
1974
- try:
1993
+ with suppress(Exception):
1975
1994
  if (
1976
1995
  hasattr(self, "_xvfb_display")
1977
1996
  and self._xvfb_display
@@ -1988,10 +2007,6 @@ def pytest_runtest_teardown(item):
1988
2007
  ):
1989
2008
  sb_config._virtual_display.stop()
1990
2009
  sb_config._virtual_display = None
1991
- except Exception:
1992
- pass
1993
- except Exception:
1994
- pass
1995
2010
  if (
1996
2011
  (
1997
2012
  sb_config._has_exception
@@ -2372,7 +2387,7 @@ def pytest_runtest_makereport(item, call):
2372
2387
  )
2373
2388
  if log_path:
2374
2389
  sb_config._log_fail_data()
2375
- try:
2390
+ with suppress(Exception):
2376
2391
  extra_report = None
2377
2392
  if hasattr(item, "_testcase"):
2378
2393
  extra_report = item._testcase._html_report_extra
@@ -2417,5 +2432,3 @@ def pytest_runtest_makereport(item, call):
2417
2432
  "</script>" % constants.Dashboard.LIVE_JS
2418
2433
  )
2419
2434
  report.extra.append(pytest_html.extras.html(refresh_updates))
2420
- except Exception:
2421
- pass
@@ -7,7 +7,7 @@ Usage --> ``with SB() as sb:``
7
7
 
8
8
  Example -->
9
9
 
10
- ```
10
+ ```python
11
11
  from seleniumbase import SB
12
12
 
13
13
  with SB() as sb: # Many args! Eg. SB(browser="edge")
@@ -41,7 +41,7 @@ def SB(
41
41
  proxy=None, # Use proxy. Format: "SERVER:PORT" or "USER:PASS@SERVER:PORT".
42
42
  proxy_bypass_list=None, # Skip proxy when using the listed domains.
43
43
  proxy_pac_url=None, # Use PAC file. (Format: URL or USERNAME:PASSWORD@URL)
44
- multi_proxy=False, # Allow multiple proxies with auth when multi-threaded.
44
+ multi_proxy=None, # Allow multiple proxies with auth when multi-threaded.
45
45
  agent=None, # Modify the web browser's User-Agent string.
46
46
  cap_file=None, # The desired capabilities to use with a Selenium Grid.
47
47
  cap_string=None, # The desired capabilities to use with a Selenium Grid.
@@ -79,10 +79,13 @@ def SB(
79
79
  wait_for_angularjs=None, # Wait for AngularJS to load after some actions.
80
80
  use_wire=None, # Use selenium-wire's webdriver over selenium webdriver.
81
81
  external_pdf=None, # Set Chrome "plugins.always_open_pdf_externally":True.
82
+ window_position=None, # Set the browser's starting window position: "X,Y"
83
+ window_size=None, # Set the browser's starting window size: "Width,Height"
82
84
  is_mobile=None, # Use the mobile device emulator while running tests.
83
85
  mobile=None, # Shortcut / Duplicate of "is_mobile".
84
86
  device_metrics=None, # Set mobile metrics: "CSSWidth,CSSHeight,PixelRatio"
85
87
  xvfb=None, # Run tests using the Xvfb virtual display server on Linux OS.
88
+ xvfb_metrics=None, # Set Xvfb display size on Linux: "Width,Height".
86
89
  start_page=None, # The starting URL for the web browser when tests begin.
87
90
  rec_print=None, # If Recorder is enabled, prints output after tests end.
88
91
  rec_behave=None, # Like Recorder Mode, but also generates behave-gherkin.
@@ -124,6 +127,124 @@ def SB(
124
127
  interval=None, # SECONDS (Autoplay interval for SB Slides & Tour steps.)
125
128
  time_limit=None, # SECONDS (Safely fail tests that exceed the time limit.)
126
129
  ):
130
+ """
131
+ * SeleniumBase as a Python Context Manager *
132
+
133
+ Example:
134
+ --------
135
+ .. code-block:: python
136
+ from seleniumbase import SB
137
+
138
+ with SB() as sb: # Many args! Eg. SB(browser="edge")
139
+ sb.open("https://google.com/ncr")
140
+ sb.type('[name="q"]', "SeleniumBase on GitHub")
141
+ sb.submit('[name="q"]')
142
+ sb.click('a[href*="github.com/seleniumbase"]')
143
+ sb.highlight("div.Layout-main")
144
+ sb.highlight("div.Layout-sidebar")
145
+ sb.sleep(0.5)
146
+
147
+ Optional Parameters:
148
+ --------------------
149
+ test: Test Mode: Output, Logging, Continue on failure unless "rtf".
150
+ rtf: Shortcut / Duplicate of "raise_test_failure".
151
+ raise_test_failure: If "test" mode, raise Exception on 1st failure.
152
+ browser: Choose from "chrome", "edge", "firefox", or "safari".
153
+ headless: The original headless mode for Chromium and Firefox.
154
+ headless2: Chromium's new headless mode. (Has more features)
155
+ locale_code: Set the Language Locale Code for the web browser.
156
+ protocol: The Selenium Grid protocol: "http" or "https".
157
+ servername: The Selenium Grid server/IP used for tests.
158
+ port: The Selenium Grid port used by the test server.
159
+ proxy: Use proxy. Format: "SERVER:PORT" or "USER:PASS@SERVER:PORT".
160
+ proxy_bypass_list: Skip proxy when using the listed domains.
161
+ proxy_pac_url: Use PAC file. (Format: URL or USERNAME:PASSWORD@URL)
162
+ multi_proxy: # Allow multiple proxies with auth when multi-threaded.
163
+ agent: Modify the web browser's User-Agent string.
164
+ cap_file: The desired capabilities to use with a Selenium Grid.
165
+ cap_string: The desired capabilities to use with a Selenium Grid.
166
+ recorder_ext: Enables the SeleniumBase Recorder Chromium extension.
167
+ disable_js: Disable JavaScript on websites. Pages might break!
168
+ disable_csp: Disable the Content Security Policy of websites.
169
+ enable_ws: Enable Web Security on Chromium-based browsers.
170
+ enable_sync: Enable "Chrome Sync" on websites.
171
+ use_auto_ext: Use Chrome's automation extension.
172
+ undetectable: Use undetected-chromedriver to evade bot-detection.
173
+ uc_cdp_events: Capture CDP events in undetected-chromedriver mode.
174
+ uc_subprocess: Use undetected-chromedriver as a subprocess.
175
+ log_cdp_events: Capture {"performance": "ALL", "browser": "ALL"}
176
+ incognito: Enable Chromium's Incognito mode.
177
+ guest_mode: Enable Chromium's Guest mode.
178
+ dark_mode: Enable Chromium's Dark mode.
179
+ devtools: Open Chromium's DevTools when the browser opens.
180
+ remote_debug: Enable Chrome's Debugger on "http://localhost:9222".
181
+ enable_3d_apis: Enable WebGL and 3D APIs.
182
+ swiftshader: Chrome: --use-gl=angle / --use-angle=swiftshader-webgl
183
+ ad_block_on: Block some types of display ads from loading.
184
+ host_resolver_rules: Set host-resolver-rules, comma-separated.
185
+ block_images: Block images from loading during tests.
186
+ do_not_track: Tell websites that you don't want to be tracked.
187
+ chromium_arg: "ARG=N,ARG2" (Set Chromium args, ","-separated.)
188
+ firefox_arg: "ARG=N,ARG2" (Set Firefox args, comma-separated.)
189
+ firefox_pref: SET (Set Firefox PREFERENCE:VALUE set, ","-separated)
190
+ user_data_dir: Set the Chrome user data directory to use.
191
+ extension_zip: Load a Chrome Extension .zip|.crx, comma-separated.
192
+ extension_dir: Load a Chrome Extension directory, comma-separated.
193
+ disable_features: "F1,F2" (Disable Chrome features, ","-separated.)
194
+ binary_location: Set path of the Chromium browser binary to use.
195
+ driver_version: Set the chromedriver or uc_driver version to use.
196
+ skip_js_waits: Skip JS Waits (readyState=="complete" and Angular).
197
+ wait_for_angularjs: Wait for AngularJS to load after some actions.
198
+ use_wire: Use selenium-wire's webdriver over selenium webdriver.
199
+ external_pdf: Set Chrome "plugins.always_open_pdf_externally":True.
200
+ window_position: Set the browser's starting window position: "X,Y"
201
+ window_size: Set the browser's starting window size: "Width,Height"
202
+ is_mobile: Use the mobile device emulator while running tests.
203
+ mobile: Shortcut / Duplicate of "is_mobile".
204
+ device_metrics: Set mobile metrics: "CSSWidth,CSSHeight,PixelRatio"
205
+ xvfb: Run tests using the Xvfb virtual display server on Linux OS.
206
+ xvfb_metrics: Set Xvfb display size on Linux: "Width,Height".
207
+ start_page: The starting URL for the web browser when tests begin.
208
+ rec_print: If Recorder is enabled, prints output after tests end.
209
+ rec_behave: Like Recorder Mode, but also generates behave-gherkin.
210
+ record_sleep: If Recorder enabled, also records self.sleep calls.
211
+ data: Extra test data. Access with "self.data" in tests.
212
+ var1: Extra test data. Access with "self.var1" in tests.
213
+ var2: Extra test data. Access with "self.var2" in tests.
214
+ var3: Extra test data. Access with "self.var3" in tests.
215
+ variables: DICT (Extra test data. Access with "self.variables")
216
+ account: Set account. Access with "self.account" in tests.
217
+ environment: Set the test env. Access with "self.env" in tests.
218
+ headed: Run tests in headed/GUI mode on Linux, where not default.
219
+ maximize: Start tests with the browser window maximized.
220
+ disable_ws: Reverse of "enable_ws". (None and False are different)
221
+ disable_beforeunload: Disable the "beforeunload" event on Chromium.
222
+ settings_file: A file for overriding default SeleniumBase settings.
223
+ uc: Shortcut / Duplicate of "undetectable".
224
+ undetected: Shortcut / Duplicate of "undetectable".
225
+ uc_cdp: Shortcut / Duplicate of "uc_cdp_events".
226
+ uc_sub: Shortcut / Duplicate of "uc_subprocess".
227
+ log_cdp: Shortcut / Duplicate of "log_cdp_events".
228
+ ad_block: Shortcut / Duplicate of "ad_block_on".
229
+ server: Shortcut / Duplicate of "servername".
230
+ guest: Shortcut / Duplicate of "guest_mode".
231
+ wire: Shortcut / Duplicate of "use_wire".
232
+ pls: Shortcut / Duplicate of "page_load_strategy".
233
+ sjw: Shortcut / Duplicate of "skip_js_waits".
234
+ wfa: Shortcut / Duplicate of "wait_for_angularjs".
235
+ save_screenshot: Save a screenshot at the end of each test.
236
+ no_screenshot: No screenshots saved unless tests directly ask it.
237
+ page_load_strategy: Set Chrome PLS to "normal", "eager", or "none".
238
+ timeout_multiplier: Multiplies the default timeout values.
239
+ js_checking_on: Check for JavaScript errors after page loads.
240
+ slow: Slow down the automation. Faster than using Demo Mode.
241
+ demo: Slow down and visually see test actions as they occur.
242
+ demo_sleep: SECONDS (Set wait time after Slow & Demo Mode actions.)
243
+ message_duration: SECONDS (The time length for Messenger alerts.)
244
+ highlights: Number of highlight animations for Demo Mode actions.
245
+ interval: SECONDS (Autoplay interval for SB Slides & Tour steps.)
246
+ time_limit: SECONDS (Safely fail tests that exceed the time limit.)
247
+ """
127
248
  import os
128
249
  import sys
129
250
  import time
@@ -365,6 +486,48 @@ def SB(
365
486
  break
366
487
  count += 1
367
488
  disable_features = d_f
489
+ w_p = window_position
490
+ if w_p is None and "--window-position" in arg_join:
491
+ count = 0
492
+ for arg in sys_argv:
493
+ if arg.startswith("--window-position="):
494
+ w_p = arg.split("--window-position=")[1]
495
+ break
496
+ elif arg == "--window-position" and len(sys_argv) > count + 1:
497
+ w_p = sys_argv[count + 1]
498
+ if w_p.startswith("-"):
499
+ w_p = None
500
+ break
501
+ count += 1
502
+ window_position = w_p
503
+ w_s = window_size
504
+ if w_s is None and "--window-size" in arg_join:
505
+ count = 0
506
+ for arg in sys_argv:
507
+ if arg.startswith("--window-size="):
508
+ w_s = arg.split("--window-size=")[1]
509
+ break
510
+ elif arg == "--window-size" and len(sys_argv) > count + 1:
511
+ w_s = sys_argv[count + 1]
512
+ if w_s.startswith("-"):
513
+ w_s = None
514
+ break
515
+ count += 1
516
+ window_size = w_s
517
+ x_m = xvfb_metrics
518
+ if x_m is None and "--xvfb-metrics" in arg_join:
519
+ count = 0
520
+ for arg in sys_argv:
521
+ if arg.startswith("--xvfb-metrics="):
522
+ x_m = arg.split("--xvfb-metrics=")[1]
523
+ break
524
+ elif arg == "--xvfb-metrics" and len(sys_argv) > count + 1:
525
+ x_m = sys_argv[count + 1]
526
+ if x_m.startswith("-"):
527
+ x_m = None
528
+ break
529
+ count += 1
530
+ xvfb_metrics = x_m
368
531
  if agent is None and "--agent" in arg_join:
369
532
  count = 0
370
533
  for arg in sys_argv:
@@ -761,6 +924,7 @@ def SB(
761
924
  sb_config.headless2 = headless2
762
925
  sb_config.headed = headed
763
926
  sb_config.xvfb = xvfb
927
+ sb_config.xvfb_metrics = xvfb_metrics
764
928
  sb_config.start_page = start_page
765
929
  sb_config.locale_code = locale_code
766
930
  sb_config.protocol = protocol
@@ -803,7 +967,8 @@ def SB(
803
967
  sb_config.crumbs = False
804
968
  sb_config.final_debug = False
805
969
  sb_config.visual_baseline = False
806
- sb_config.window_size = None
970
+ sb_config.window_position = window_position
971
+ sb_config.window_size = window_size
807
972
  sb_config.maximize_option = maximize_option
808
973
  sb_config._disable_beforeunload = _disable_beforeunload
809
974
  sb_config.save_screenshot = save_screenshot
@@ -864,6 +1029,7 @@ def SB(
864
1029
  sb.headless2 = sb_config.headless2
865
1030
  sb.headed = sb_config.headed
866
1031
  sb.xvfb = sb_config.xvfb
1032
+ sb.xvfb_metrics = sb_config.xvfb_metrics
867
1033
  sb.start_page = sb_config.start_page
868
1034
  sb.locale_code = sb_config.locale_code
869
1035
  sb.protocol = sb_config.protocol
@@ -908,6 +1074,7 @@ def SB(
908
1074
  sb._crumbs = sb_config.crumbs
909
1075
  sb._final_debug = sb_config.final_debug
910
1076
  sb.visual_baseline = sb_config.visual_baseline
1077
+ sb.window_position = sb_config.window_position
911
1078
  sb.window_size = sb_config.window_size
912
1079
  sb.maximize_option = sb_config.maximize_option
913
1080
  sb._disable_beforeunload = sb_config._disable_beforeunload
@@ -1,5 +1,6 @@
1
1
  """Selenium Plugin for SeleniumBase tests that run with pynose / nosetests"""
2
2
  import sys
3
+ from contextlib import suppress
3
4
  from nose.plugins import Plugin
4
5
  from seleniumbase import config as sb_config
5
6
  from seleniumbase.config import settings
@@ -46,6 +47,7 @@ class SeleniumBrowser(Plugin):
46
47
  --headless2 (Use the new headless mode, which supports extensions.)
47
48
  --headed (Run tests in headed/GUI mode on Linux OS, where not default.)
48
49
  --xvfb (Run tests using the Xvfb virtual display server on Linux OS.)
50
+ --xvfb-metrics=STRING (Set Xvfb display size on Linux: "Width,Height".)
49
51
  --locale=LOCALE_CODE (Set the Language Locale Code for the web browser.)
50
52
  --interval=SECONDS (The autoplay interval for presentations & tour steps)
51
53
  --start-page=URL (The starting URL for the web browser when tests begin.)
@@ -82,6 +84,7 @@ class SeleniumBrowser(Plugin):
82
84
  --dark (Enable Chrome's Dark mode.)
83
85
  --devtools (Open Chrome's DevTools when the browser opens.)
84
86
  --disable-beforeunload (Disable the "beforeunload" event on Chrome.)
87
+ --window-position=X,Y (Set the browser's starting window position.)
85
88
  --window-size=WIDTH,HEIGHT (Set the browser's starting window size.)
86
89
  --maximize (Start tests with the browser window maximized.)
87
90
  --screenshot (Save a screenshot at the end of each test.)
@@ -465,6 +468,17 @@ class SeleniumBrowser(Plugin):
465
468
  will no longer be enabled by default on Linux.
466
469
  Default: False. (Linux-ONLY!)""",
467
470
  )
471
+ parser.addoption(
472
+ "--xvfb-metrics",
473
+ "--xvfb_metrics",
474
+ action="store",
475
+ dest="xvfb_metrics",
476
+ default=None,
477
+ help="""Customize the Xvfb metrics (Width,Height) on Linux.
478
+ Format: A comma-separated string with the 2 values.
479
+ Examples: "1920,1080" or "1366,768" or "1024,768".
480
+ Default: None. (None: "1366,768". Min: "1024,768".)""",
481
+ )
468
482
  parser.addoption(
469
483
  "--locale_code",
470
484
  "--locale-code",
@@ -886,6 +900,17 @@ class SeleniumBrowser(Plugin):
886
900
  on Chromium browsers (Chrome or Edge).
887
901
  This is already the default Firefox option.""",
888
902
  )
903
+ parser.addoption(
904
+ "--window-position",
905
+ "--window_position",
906
+ action="store",
907
+ dest="window_position",
908
+ default=None,
909
+ help="""The option to set the starting window x,y position.
910
+ Format: A comma-separated string with the 2 values.
911
+ Example: "55,66"
912
+ Default: None. (Will use default values if None)""",
913
+ )
889
914
  parser.addoption(
890
915
  "--window-size",
891
916
  "--window_size",
@@ -1060,6 +1085,29 @@ class SeleniumBrowser(Plugin):
1060
1085
  '\n (Your browser choice was: "%s")\n' % browser
1061
1086
  )
1062
1087
  raise Exception(message)
1088
+ window_position = self.options.window_position
1089
+ if window_position:
1090
+ if window_position.count(",") != 1:
1091
+ message = (
1092
+ '\n\n window_position expects an "x,y" string!'
1093
+ '\n (Your input was: "%s")\n' % window_position
1094
+ )
1095
+ raise Exception(message)
1096
+ window_position = window_position.replace(" ", "")
1097
+ win_x = None
1098
+ win_y = None
1099
+ try:
1100
+ win_x = int(window_position.split(",")[0])
1101
+ win_y = int(window_position.split(",")[1])
1102
+ except Exception:
1103
+ message = (
1104
+ '\n\n Expecting integer values for "x,y"!'
1105
+ '\n (window_position input was: "%s")\n'
1106
+ % window_position
1107
+ )
1108
+ raise Exception(message)
1109
+ settings.WINDOW_START_X = win_x
1110
+ settings.WINDOW_START_Y = win_y
1063
1111
  window_size = self.options.window_size
1064
1112
  if window_size:
1065
1113
  if window_size.count(",") != 1:
@@ -1112,6 +1160,7 @@ class SeleniumBrowser(Plugin):
1112
1160
  self.options.headless2 = False
1113
1161
  test.test.headed = self.options.headed
1114
1162
  test.test.xvfb = self.options.xvfb
1163
+ test.test.xvfb_metrics = self.options.xvfb_metrics
1115
1164
  test.test.locale_code = self.options.locale_code
1116
1165
  test.test.interval = self.options.interval
1117
1166
  test.test.start_page = self.options.start_page
@@ -1192,6 +1241,7 @@ class SeleniumBrowser(Plugin):
1192
1241
  test.test.dark_mode = self.options.dark_mode
1193
1242
  test.test.devtools = self.options.devtools
1194
1243
  test.test._disable_beforeunload = self.options._disable_beforeunload
1244
+ test.test.window_position = self.options.window_position
1195
1245
  test.test.window_size = self.options.window_size
1196
1246
  test.test.maximize_option = self.options.maximize_option
1197
1247
  if self.options.save_screenshot and self.options.no_screenshot:
@@ -1259,7 +1309,7 @@ class SeleniumBrowser(Plugin):
1259
1309
  ):
1260
1310
  width = settings.HEADLESS_START_WIDTH
1261
1311
  height = settings.HEADLESS_START_HEIGHT
1262
- try:
1312
+ with suppress(Exception):
1263
1313
  from sbvirtualdisplay import Display
1264
1314
 
1265
1315
  self._xvfb_display = Display(visible=0, size=(width, height))
@@ -1267,8 +1317,6 @@ class SeleniumBrowser(Plugin):
1267
1317
  sb_config._virtual_display = self._xvfb_display
1268
1318
  self.headless_active = True
1269
1319
  sb_config.headless_active = True
1270
- except Exception:
1271
- pass
1272
1320
  sb_config._is_timeout_changed = False
1273
1321
  sb_config._SMALL_TIMEOUT = settings.SMALL_TIMEOUT
1274
1322
  sb_config._LARGE_TIMEOUT = settings.LARGE_TIMEOUT
@@ -1301,7 +1349,7 @@ class SeleniumBrowser(Plugin):
1301
1349
  pass
1302
1350
  except Exception:
1303
1351
  pass
1304
- try:
1352
+ with suppress(Exception):
1305
1353
  if (
1306
1354
  hasattr(self, "_xvfb_display")
1307
1355
  and self._xvfb_display
@@ -1318,5 +1366,3 @@ class SeleniumBrowser(Plugin):
1318
1366
  ):
1319
1367
  sb_config._virtual_display.stop()
1320
1368
  sb_config._virtual_display = None
1321
- except Exception:
1322
- pass