48
48
-D headless2 (Use the new headless mode, which supports extensions.)
49
49
-D headed (Run tests in headed/GUI mode on Linux OS, where not default.)
50
50
-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".)
51
52
-D locale=LOCALE_CODE (Set the Language Locale Code for the web browser.)
52
53
-D pdb (Activate Post Mortem Debug Mode if a test fails.)
53
54
-D interval=SECONDS (The autoplay interval for presentations & tour steps)
90
91
-D rcs | -D reuse-class-session (Reuse session for tests in class/feature)
91
92
-D crumbs (Delete all cookies between tests reusing a session.)
92
93
-D disable-beforeunload (Disable the "beforeunload" event on Chrome.)
94
+ -D window-position=X,Y (Set the browser's starting window position.)
93
95
-D window-size=WIDTH,HEIGHT (Set the browser's starting window size.)
94
96
-D maximize (Start tests with the browser window maximized.)
95
97
-D screenshot (Save a screenshot at the end of each test.)
104
106
import os
105
107
import re
106
108
import sys
109
+ from contextlib import suppress
107
110
from seleniumbase import config as sb_config
108
111
from seleniumbase .config import settings
109
112
from seleniumbase .core import download_helper
@@ -145,6 +148,7 @@ def get_configured_sb(context):
145
148
sb .headless_active = False
146
149
sb .headed = False
147
150
sb .xvfb = False
151
+ sb .xvfb_metrics = None
148
152
sb .start_page = None
149
153
sb .locale_code = None
150
154
sb .pdb_option = False
@@ -193,6 +197,7 @@ def get_configured_sb(context):
193
197
sb ._disable_beforeunload = False
194
198
sb .visual_baseline = False
195
199
sb .use_wire = False
200
+ sb .window_position = None
196
201
sb .window_size = None
197
202
sb .maximize_option = False
198
203
sb .is_context_manager = False
@@ -302,6 +307,13 @@ def get_configured_sb(context):
302
307
if low_key == "xvfb" :
303
308
sb .xvfb = True
304
309
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
305
317
# Handle: -D start-page=URL / start_page=URL / url=URL
306
318
if low_key in ["start-page" , "start_page" , "url" ]:
307
319
start_page = userdata [key ]
@@ -601,6 +613,13 @@ def get_configured_sb(context):
601
613
if low_key == "wire" :
602
614
sb .use_wire = True
603
615
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
604
623
# Handle: -D window-size=Width,Height / window_size=Width,Height
605
624
if low_key in ["window-size" , "window_size" ]:
606
625
window_size = userdata [key ]
@@ -904,6 +923,29 @@ def get_configured_sb(context):
904
923
else :
905
924
sb .enable_ws = False
906
925
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
907
949
if sb .window_size :
908
950
window_size = sb .window_size
909
951
if window_size .count ("," ) != 1 :
@@ -938,9 +980,11 @@ def get_configured_sb(context):
938
980
sb_config .is_pytest = False
939
981
sb_config .is_nosetest = False
940
982
sb_config .is_context_manager = False
983
+ sb_config .window_position = sb .window_position
941
984
sb_config .window_size = sb .window_size
942
985
sb_config .maximize_option = sb .maximize_option
943
986
sb_config .xvfb = sb .xvfb
987
+ sb_config .xvfb_metrics = sb .xvfb_metrics
944
988
sb_config .reuse_class_session = sb ._reuse_class_session
945
989
sb_config .save_screenshot = sb .save_screenshot_after_test
946
990
sb_config .no_screenshot = sb .no_screenshot_after_test
@@ -1162,12 +1206,10 @@ def behave_dashboard_prepare():
1162
1206
sb_config .item_count_untested = sb_config .item_count
1163
1207
dash_path = os .path .join (os .getcwd (), "dashboard.html" )
1164
1208
star_len = len ("Dashboard: " ) + len (dash_path )
1165
- try :
1209
+ with suppress ( Exception ) :
1166
1210
terminal_size = os .get_terminal_size ().columns
1167
1211
if terminal_size > 30 and star_len > terminal_size :
1168
1212
star_len = terminal_size
1169
- except Exception :
1170
- pass
1171
1213
stars = "*" * star_len
1172
1214
c1 = ""
1173
1215
cr = ""
@@ -1263,16 +1305,14 @@ def _perform_behave_unconfigure_():
1263
1305
1264
1306
1265
1307
def do_final_driver_cleanup_as_needed ():
1266
- try :
1308
+ with suppress ( Exception ) :
1267
1309
if hasattr (sb_config , "last_driver" ) and sb_config .last_driver :
1268
1310
if (
1269
1311
not is_windows
1270
1312
or sb_config .browser == "ie"
1271
1313
or sb_config .last_driver .service .process
1272
1314
):
1273
1315
sb_config .last_driver .quit ()
1274
- except Exception :
1275
- pass
1276
1316
1277
1317
1278
1318
def _perform_behave_terminal_summary_ ():
@@ -1281,12 +1321,10 @@ def _perform_behave_terminal_summary_():
1281
1321
)
1282
1322
dash_path = os .path .join (os .getcwd (), "dashboard.html" )
1283
1323
equals_len = len ("Dashboard: " ) + len (dash_path )
1284
- try :
1324
+ with suppress ( Exception ) :
1285
1325
terminal_size = os .get_terminal_size ().columns
1286
1326
if terminal_size > 30 and equals_len > terminal_size :
1287
1327
equals_len = terminal_size
1288
- except Exception :
1289
- pass
1290
1328
equals = "=" * (equals_len + 2 )
1291
1329
c2 = ""
1292
1330
cr = ""
0 commit comments