4848-D headless2 (Use the new headless mode, which supports extensions.)
4949-D headed (Run tests in headed/GUI mode on Linux OS, where not default.)
5050-D xvfb (Run tests using the Xvfb virtual display server on Linux OS.)
51+ -D xvfb-metrics=STRING (Set Xvfb display size on Linux: "Width,Height".)
5152-D locale=LOCALE_CODE (Set the Language Locale Code for the web browser.)
5253-D pdb (Activate Post Mortem Debug Mode if a test fails.)
5354-D interval=SECONDS (The autoplay interval for presentations & tour steps)
9091-D rcs | -D reuse-class-session (Reuse session for tests in class/feature)
9192-D crumbs (Delete all cookies between tests reusing a session.)
9293-D disable-beforeunload (Disable the "beforeunload" event on Chrome.)
94+ -D window-position=X,Y (Set the browser's starting window position.)
9395-D window-size=WIDTH,HEIGHT (Set the browser's starting window size.)
9496-D maximize (Start tests with the browser window maximized.)
9597-D screenshot (Save a screenshot at the end of each test.)
104106import os
105107import re
106108import sys
109+ from contextlib import suppress
107110from seleniumbase import config as sb_config
108111from seleniumbase .config import settings
109112from seleniumbase .core import download_helper
@@ -145,6 +148,7 @@ def get_configured_sb(context):
145148 sb .headless_active = False
146149 sb .headed = False
147150 sb .xvfb = False
151+ sb .xvfb_metrics = None
148152 sb .start_page = None
149153 sb .locale_code = None
150154 sb .pdb_option = False
@@ -193,6 +197,7 @@ def get_configured_sb(context):
193197 sb ._disable_beforeunload = False
194198 sb .visual_baseline = False
195199 sb .use_wire = False
200+ sb .window_position = None
196201 sb .window_size = None
197202 sb .maximize_option = False
198203 sb .is_context_manager = False
@@ -302,6 +307,13 @@ def get_configured_sb(context):
302307 if low_key == "xvfb" :
303308 sb .xvfb = True
304309 continue
310+ # Handle: -D xvfb-metrics=STR / xvfb_metrics=STR
311+ if low_key in ["xvfb-metrics" , "xvfb_metrics" ]:
312+ xvfb_metrics = userdata [key ]
313+ if xvfb_metrics == "true" :
314+ xvfb_metrics = sb .xvfb_metrics # revert to default
315+ sb .xvfb_metrics = xvfb_metrics
316+ continue
305317 # Handle: -D start-page=URL / start_page=URL / url=URL
306318 if low_key in ["start-page" , "start_page" , "url" ]:
307319 start_page = userdata [key ]
@@ -601,6 +613,13 @@ def get_configured_sb(context):
601613 if low_key == "wire" :
602614 sb .use_wire = True
603615 continue
616+ # Handle: -D window-position=X,Y / window_position=X,Y
617+ if low_key in ["window-position" , "window_position" ]:
618+ window_position = userdata [key ]
619+ if window_position == "true" :
620+ window_position = sb .window_position # revert to default
621+ sb .window_position = window_position
622+ continue
604623 # Handle: -D window-size=Width,Height / window_size=Width,Height
605624 if low_key in ["window-size" , "window_size" ]:
606625 window_size = userdata [key ]
@@ -904,6 +923,29 @@ def get_configured_sb(context):
904923 else :
905924 sb .enable_ws = False
906925 sb .disable_ws = True
926+ if sb .window_position :
927+ window_position = sb .window_position
928+ if window_position .count ("," ) != 1 :
929+ message = (
930+ '\n \n window_position expects an "x,y" string!'
931+ '\n (Your input was: "%s")\n ' % window_position
932+ )
933+ raise Exception (message )
934+ window_position = window_position .replace (" " , "" )
935+ win_x = None
936+ win_y = None
937+ try :
938+ win_x = int (window_position .split ("," )[0 ])
939+ win_y = int (window_position .split ("," )[1 ])
940+ except Exception :
941+ message = (
942+ '\n \n Expecting integer values for "x,y"!'
943+ '\n (window_position input was: "%s")\n '
944+ % window_position
945+ )
946+ raise Exception (message )
947+ settings .WINDOW_START_X = win_x
948+ settings .WINDOW_START_Y = win_y
907949 if sb .window_size :
908950 window_size = sb .window_size
909951 if window_size .count ("," ) != 1 :
@@ -938,9 +980,11 @@ def get_configured_sb(context):
938980 sb_config .is_pytest = False
939981 sb_config .is_nosetest = False
940982 sb_config .is_context_manager = False
983+ sb_config .window_position = sb .window_position
941984 sb_config .window_size = sb .window_size
942985 sb_config .maximize_option = sb .maximize_option
943986 sb_config .xvfb = sb .xvfb
987+ sb_config .xvfb_metrics = sb .xvfb_metrics
944988 sb_config .reuse_class_session = sb ._reuse_class_session
945989 sb_config .save_screenshot = sb .save_screenshot_after_test
946990 sb_config .no_screenshot = sb .no_screenshot_after_test
@@ -1162,12 +1206,10 @@ def behave_dashboard_prepare():
11621206 sb_config .item_count_untested = sb_config .item_count
11631207 dash_path = os .path .join (os .getcwd (), "dashboard.html" )
11641208 star_len = len ("Dashboard: " ) + len (dash_path )
1165- try :
1209+ with suppress ( Exception ) :
11661210 terminal_size = os .get_terminal_size ().columns
11671211 if terminal_size > 30 and star_len > terminal_size :
11681212 star_len = terminal_size
1169- except Exception :
1170- pass
11711213 stars = "*" * star_len
11721214 c1 = ""
11731215 cr = ""
@@ -1263,16 +1305,14 @@ def _perform_behave_unconfigure_():
12631305
12641306
12651307def do_final_driver_cleanup_as_needed ():
1266- try :
1308+ with suppress ( Exception ) :
12671309 if hasattr (sb_config , "last_driver" ) and sb_config .last_driver :
12681310 if (
12691311 not is_windows
12701312 or sb_config .browser == "ie"
12711313 or sb_config .last_driver .service .process
12721314 ):
12731315 sb_config .last_driver .quit ()
1274- except Exception :
1275- pass
12761316
12771317
12781318def _perform_behave_terminal_summary_ ():
@@ -1281,12 +1321,10 @@ def _perform_behave_terminal_summary_():
12811321 )
12821322 dash_path = os .path .join (os .getcwd (), "dashboard.html" )
12831323 equals_len = len ("Dashboard: " ) + len (dash_path )
1284- try :
1324+ with suppress ( Exception ) :
12851325 terminal_size = os .get_terminal_size ().columns
12861326 if terminal_size > 30 and equals_len > terminal_size :
12871327 equals_len = terminal_size
1288- except Exception :
1289- pass
12901328 equals = "=" * (equals_len + 2 )
12911329 c2 = ""
12921330 cr = ""
0 commit comments