Skip to content

Commit d65c52c

Browse files
committed
Make multiple updates
1 parent bc9de47 commit d65c52c

26 files changed

+648
-797
lines changed

sbase/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
from seleniumbase import page_actions # noqa
1212
from seleniumbase import page_utils # noqa
1313
from seleniumbase import SB # noqa
14+
from seleniumbase import translate # noqa

seleniumbase/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from seleniumbase.__version__ import __version__
1111
from seleniumbase.common import decorators # noqa
1212
from seleniumbase.common import encryption # noqa
13-
from seleniumbase.core import colored_traceback
13+
from seleniumbase.core import colored_traceback # noqa
1414
from seleniumbase.core.browser_launcher import get_driver # noqa
1515
from seleniumbase.fixtures import js_utils # noqa
1616
from seleniumbase.fixtures import page_actions # noqa
@@ -36,8 +36,7 @@
3636
pdb.DefaultConfig.sticky_by_default = True
3737
colored_traceback.add_hook()
3838
os.environ["SE_AVOID_STATS"] = "true" # Disable Selenium Manager stats
39-
if sys.version_info >= (3, 7):
40-
webdriver.TouchActions = None # Lifeline for past selenium-wire versions
39+
webdriver.TouchActions = None # Lifeline for past selenium-wire versions
4140
if sys.version_info >= (3, 10):
4241
collections.Callable = collections.abc.Callable # Lifeline for nosetests
4342
del collections # Undo "import collections" / Simplify "dir(seleniumbase)"

seleniumbase/behave/behave_sb.py

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
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)
@@ -90,6 +91,7 @@
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.)
@@ -104,6 +106,7 @@
104106
import os
105107
import re
106108
import sys
109+
from contextlib import suppress
107110
from seleniumbase import config as sb_config
108111
from seleniumbase.config import settings
109112
from 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

12651307
def 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

12781318
def _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 = ""

seleniumbase/config/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@
110110
# (This applies when using --proxy=[PROXY_STRING] for using a proxy server.)
111111
RAISE_INVALID_PROXY_STRING_EXCEPTION = True
112112

113+
# Default browser coordinates when opening new windows for tests.
114+
WINDOW_START_X = 20
115+
WINDOW_START_Y = 54
116+
113117
# Default browser resolutions when opening new windows for tests.
114118
# (Headless resolutions take priority, and include all browsers.)
115119
# (Firefox starts maximized by default when running in GUI Mode.)

seleniumbase/console_scripts/sb_behave_gui.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616
import colorama
1717
import subprocess
1818
import sys
19+
import tkinter as tk
20+
from seleniumbase.fixtures import shared_utils
21+
from tkinter.scrolledtext import ScrolledText
1922

20-
if sys.version_info <= (3, 7):
23+
if sys.version_info <= (3, 8):
2124
current_version = ".".join(str(ver) for ver in sys.version_info[:3])
2225
raise Exception(
23-
"\n* SBase Commander requires Python 3.7 or newer!"
26+
"\n* SBase Commander requires Python 3.8 or newer!"
2427
"\n** You are currently using Python %s" % current_version
2528
)
26-
from seleniumbase.fixtures import shared_utils
27-
import tkinter as tk # noqa: E402
28-
from tkinter.scrolledtext import ScrolledText # noqa: E402
2929

3030

3131
def set_colors(use_colors):

seleniumbase/console_scripts/sb_caseplans.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@
2020
import os
2121
import subprocess
2222
import sys
23+
import tkinter as tk
24+
from seleniumbase.fixtures import shared_utils
25+
from tkinter import messagebox
26+
from tkinter.scrolledtext import ScrolledText
2327

24-
if sys.version_info <= (3, 7):
28+
if sys.version_info <= (3, 8):
2529
current_version = ".".join(str(ver) for ver in sys.version_info[:3])
2630
raise Exception(
27-
"\n* SBase Case Plans Generator requires Python 3.7 or newer!"
31+
"\n* SBase Case Plans Generator requires Python 3.8 or newer!"
2832
"\n** You are currently using Python %s" % current_version
2933
)
30-
from seleniumbase.fixtures import shared_utils
31-
import tkinter as tk # noqa: E402
32-
from tkinter import messagebox # noqa: E402
33-
from tkinter.scrolledtext import ScrolledText # noqa: E402
3434

3535

3636
def set_colors(use_colors):

seleniumbase/console_scripts/sb_commander.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121
import os
2222
import subprocess
2323
import sys
24+
import tkinter as tk
25+
from seleniumbase.fixtures import shared_utils
26+
from tkinter.scrolledtext import ScrolledText
2427

25-
if sys.version_info <= (3, 7):
28+
if sys.version_info <= (3, 8):
2629
current_version = ".".join(str(ver) for ver in sys.version_info[:3])
2730
raise Exception(
28-
"\n* SBase Commander requires Python 3.7 or newer!"
31+
"\n* SBase Commander requires Python 3.8 or newer!"
2932
"\n** You are currently using Python %s" % current_version
3033
)
31-
from seleniumbase.fixtures import shared_utils
32-
import tkinter as tk # noqa: E402
33-
from tkinter.scrolledtext import ScrolledText # noqa: E402
3434

3535

3636
def set_colors(use_colors):

seleniumbase/console_scripts/sb_recorder.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@
1818
import os
1919
import subprocess
2020
import sys
21+
import tkinter as tk
2122
from seleniumbase import config as sb_config
2223
from seleniumbase.fixtures import page_utils
2324
from seleniumbase.fixtures import shared_utils
25+
from tkinter import messagebox
2426

2527
sb_config.rec_subprocess_p = None
2628
sb_config.rec_subprocess_used = False
2729
sys_executable = sys.executable
2830
if " " in sys_executable:
2931
sys_executable = "python"
30-
if sys.version_info <= (3, 7):
32+
if sys.version_info <= (3, 8):
3133
current_version = ".".join(str(ver) for ver in sys.version_info[:3])
3234
raise Exception(
33-
"\n* Recorder Desktop requires Python 3.7 or newer!"
35+
"\n* Recorder Desktop requires Python 3.8 or newer!"
3436
"\n*** You are currently using Python %s" % current_version
3537
)
36-
import tkinter as tk # noqa: E402
37-
from tkinter import messagebox # noqa: E402
3838

3939

4040
def set_colors(use_colors):

0 commit comments

Comments
 (0)