Skip to content

Commit ea37887

Browse files
committed
Refactor the code
1 parent 614af48 commit ea37887

40 files changed

+655
-730
lines changed

sbase/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from seleniumbase import encryption # noqa
77
from seleniumbase import get_driver # noqa
88
from seleniumbase import js_utils # noqa
9+
from seleniumbase import shared_utils # noqa
910
from seleniumbase import MasterQA # noqa
1011
from seleniumbase import page_actions # noqa
1112
from seleniumbase import page_utils # noqa

seleniumbase/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from seleniumbase.fixtures import js_utils # noqa
1515
from seleniumbase.fixtures import page_actions # noqa
1616
from seleniumbase.fixtures import page_utils # noqa
17+
from seleniumbase.fixtures import shared_utils # noqa
1718
from seleniumbase.fixtures.base_case import BaseCase # noqa
1819
from seleniumbase.masterqa.master_qa import MasterQA # noqa
1920
from seleniumbase.plugins.sb_manager import SB # noqa

seleniumbase/behave/behave_sb.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@
8282
-D incognito (Enable Chrome's Incognito mode.)
8383
-D guest (Enable Chrome's Guest mode.)
8484
-D devtools (Open Chrome's DevTools when the browser opens.)
85-
-D reuse-session | -D rs (Reuse browser session for all tests.)
86-
-D reuse-class-session | -D rcs (Reuse session for tests in class/feature)
85+
-D rs | -D reuse-session (Reuse browser session for all tests.)
86+
-D rcs | -D reuse-class-session (Reuse session for tests in class/feature)
8787
-D crumbs (Delete all cookies between tests reusing a session.)
8888
-D disable-beforeunload (Disable the "beforeunload" event on Chrome.)
8989
-D window-size=WIDTH,HEIGHT (Set the browser's starting window size.)
@@ -95,24 +95,21 @@
9595
-D external-pdf (Set Chromium "plugins.always_open_pdf_externally":True.)
9696
-D timeout-multiplier=MULTIPLIER (Multiplies the default timeout values.)
9797
"""
98-
9998
import ast
10099
import colorama
101100
import os
102101
import re
103102
import sys
103+
from seleniumbase import config as sb_config
104104
from seleniumbase.config import settings
105-
from seleniumbase.core import log_helper
106105
from seleniumbase.core import download_helper
106+
from seleniumbase.core import log_helper
107107
from seleniumbase.core import proxy_helper
108108
from seleniumbase.core import session_helper
109109
from seleniumbase.fixtures import constants
110-
from seleniumbase import config as sb_config
110+
from seleniumbase.fixtures import shared_utils
111111

112112
sb_config.__base_class = None
113-
is_windows = False
114-
if sys.platform in ["win32", "win64", "x64"]:
115-
is_windows = True
116113

117114

118115
def set_base_class(base_class):
@@ -817,10 +814,10 @@ def get_configured_sb(context):
817814
'\n (Your browser choice was: "%s")\n' % sb.browser
818815
)
819816
# The Xvfb virtual display server is for Linux OS Only.
820-
if sb.xvfb and "linux" not in sys.platform:
817+
if sb.xvfb and not shared_utils.is_linux():
821818
sb.xvfb = False
822819
if (
823-
"linux" in sys.platform
820+
shared_utils.is_linux()
824821
and not sb.headed
825822
and not sb.headless
826823
and not sb.headless2
@@ -931,7 +928,6 @@ def get_configured_sb(context):
931928
log_helper.log_folder_setup(sb.log_path, sb.archive_logs)
932929
download_helper.reset_downloads_folder()
933930
proxy_helper.remove_proxy_zip_if_present()
934-
935931
return sb
936932

937933

@@ -1007,7 +1003,7 @@ def dashboard_pre_processing():
10071003
filename = None
10081004
feature_name = None
10091005
scenario_name = None
1010-
if is_windows:
1006+
if shared_utils.is_windows():
10111007
output = output.decode("latin1")
10121008
else:
10131009
output = output.decode("utf-8")
@@ -1116,25 +1112,22 @@ def behave_dashboard_prepare():
11161112
stars = "*" * star_len
11171113
c1 = ""
11181114
cr = ""
1119-
if "linux" not in sys.platform:
1115+
if not shared_utils.is_linux():
11201116
colorama.init(autoreset=True)
11211117
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
11221118
cr = colorama.Style.RESET_ALL
11231119
print("Dashboard: %s%s%s\n%s" % (c1, dash_path, cr, stars))
11241120

11251121

11261122
def _perform_behave_unconfigure_():
1127-
from seleniumbase.core import log_helper
1128-
from seleniumbase.core import proxy_helper
1129-
11301123
if hasattr(sb_config, "multi_proxy") and not sb_config.multi_proxy:
11311124
proxy_helper.remove_proxy_zip_if_present()
11321125
if hasattr(sb_config, "reuse_session") and sb_config.reuse_session:
11331126
# Close the shared browser session
11341127
if sb_config.shared_driver:
11351128
try:
11361129
if (
1137-
not is_windows
1130+
not shared_utils.is_windows()
11381131
or sb_config.browser == "ie"
11391132
or sb_config.shared_driver.service.process
11401133
):
@@ -1210,7 +1203,7 @@ def do_final_driver_cleanup_as_needed():
12101203
try:
12111204
if hasattr(sb_config, "last_driver") and sb_config.last_driver:
12121205
if (
1213-
not is_windows
1206+
not shared_utils.is_windows()
12141207
or sb_config.browser == "ie"
12151208
or sb_config.last_driver.service.process
12161209
):
@@ -1232,7 +1225,7 @@ def _perform_behave_terminal_summary_():
12321225
equals = "=" * (equals_len + 2)
12331226
c2 = ""
12341227
cr = ""
1235-
if "linux" not in sys.platform:
1228+
if not shared_utils.is_linux():
12361229
colorama.init(autoreset=True)
12371230
c2 = colorama.Fore.MAGENTA + colorama.Back.LIGHTYELLOW_EX
12381231
cr = colorama.Style.RESET_ALL

seleniumbase/console_scripts/run.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import sys
4141
import time
4242
from seleniumbase.fixtures import constants
43-
from seleniumbase.fixtures import shared_utils
4443

4544
colorama.init(autoreset=True)
4645

@@ -144,8 +143,8 @@ def show_install_usage():
144143
print(" sbase get chromedriver")
145144
print(" sbase get geckodriver")
146145
print(" sbase get edgedriver")
147-
print(" sbase get chromedriver 112")
148-
print(" sbase get chromedriver 112.0.5615.49")
146+
print(" sbase get chromedriver 114")
147+
print(" sbase get chromedriver 114.0.5735.90")
149148
print(" sbase get chromedriver latest")
150149
print(" sbase get chromedriver latest-1")
151150
print(" sbase get chromedriver -p")
@@ -976,12 +975,14 @@ def main():
976975
retry_msg_1 = "* Unable to download driver! Retrying in 3s..."
977976
retry_msg_2 = "** Unable to download driver! Retrying in 5s..."
978977
if " --proxy=" in " ".join(sys.argv):
978+
from seleniumbase.core import proxy_helper
979+
979980
for arg in sys.argv:
980981
if arg.startswith("--proxy="):
981982
proxy_string = arg.split("--proxy=")[1]
982983
if "@" in proxy_string:
983984
proxy_string = proxy_string.split("@")[1]
984-
shared_utils.validate_proxy_string(proxy_string)
985+
proxy_helper.validate_proxy_string(proxy_string)
985986
break
986987
try:
987988
sb_install.main()

seleniumbase/console_scripts/sb_behave_gui.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,10 @@
2323
"\n* SBase Commander requires Python 3.7 or newer!"
2424
"\n** You are currently using Python %s" % current_version
2525
)
26+
from seleniumbase.fixtures import shared_utils
2627
import tkinter as tk # noqa: E402
2728
from tkinter.scrolledtext import ScrolledText # noqa: E402
2829

29-
is_windows = False
30-
if sys.platform in ["win32", "win64", "x64"]:
31-
is_windows = True
32-
3330

3431
def set_colors(use_colors):
3532
c0 = ""
@@ -127,7 +124,7 @@ def do_behave_run(
127124

128125
if headless:
129126
full_run_command += " -D headless"
130-
elif "linux" in sys.platform:
127+
elif shared_utils.is_linux():
131128
full_run_command += " -D gui"
132129

133130
if save_screenshots:
@@ -188,7 +185,7 @@ def create_tkinter_gui(tests, command_string, t_count, f_count, s_tests):
188185
"Use Edge Browser (-D edge)",
189186
"Use Firefox Browser (-D firefox)",
190187
]
191-
if "darwin" in sys.platform:
188+
if shared_utils.is_mac():
192189
options_list.append("Use Safari Browser (-D safari)")
193190
brx = tk.StringVar(root)
194191
brx.set(options_list[0])
@@ -267,7 +264,7 @@ def create_tkinter_gui(tests, command_string, t_count, f_count, s_tests):
267264
row += " " * 200
268265
ara[count] = tk.IntVar()
269266
cb = None
270-
if not is_windows:
267+
if not shared_utils.is_windows():
271268
cb = tk.Checkbutton(
272269
text_area,
273270
text=(row),
@@ -362,7 +359,7 @@ def create_tkinter_gui(tests, command_string, t_count, f_count, s_tests):
362359

363360
def main():
364361
use_colors = True
365-
if "linux" in sys.platform:
362+
if shared_utils.is_linux():
366363
use_colors = False
367364
c0, c1, c2, c3, c4, c5, c6, cr = set_colors(use_colors)
368365
command_args = sys.argv[2:]
@@ -414,7 +411,7 @@ def main():
414411
f_count = 0
415412
s_count = 0
416413
t_count = 0
417-
if is_windows:
414+
if shared_utils.is_windows():
418415
output = output.decode("latin1")
419416
else:
420417
output = output.decode("utf-8")

seleniumbase/console_scripts/sb_caseplans.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,11 @@
2727
"\n* SBase Case Plans Generator requires Python 3.7 or newer!"
2828
"\n** You are currently using Python %s" % current_version
2929
)
30+
from seleniumbase.fixtures import shared_utils
3031
import tkinter as tk # noqa: E402
3132
from tkinter import messagebox # noqa: E402
3233
from tkinter.scrolledtext import ScrolledText # noqa: E402
3334

34-
is_windows = False
35-
if sys.platform in ["win32", "win64", "x64"]:
36-
is_windows = True
37-
3835

3936
def set_colors(use_colors):
4037
c0 = ""
@@ -404,7 +401,7 @@ def create_tkinter_gui(tests, command_string):
404401
row += " " * 200
405402
ara[count] = tk.IntVar()
406403
cb = None
407-
if not is_windows:
404+
if not shared_utils.is_windows():
408405
cb = tk.Checkbutton(
409406
text_area,
410407
text=(row),

seleniumbase/console_scripts/sb_commander.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,10 @@
2828
"\n* SBase Commander requires Python 3.7 or newer!"
2929
"\n** You are currently using Python %s" % current_version
3030
)
31+
from seleniumbase.fixtures import shared_utils
3132
import tkinter as tk # noqa: E402
3233
from tkinter.scrolledtext import ScrolledText # noqa: E402
3334

34-
is_windows = False
35-
if sys.platform in ["win32", "win64", "x64"]:
36-
is_windows = True
37-
3835

3936
def set_colors(use_colors):
4037
c0 = ""
@@ -154,7 +151,7 @@ def do_pytest_run(
154151

155152
if headless:
156153
full_run_command += " --headless"
157-
elif "linux" in sys.platform:
154+
elif shared_utils.is_linux():
158155
full_run_command += " --gui"
159156

160157
if save_screenshots:
@@ -191,7 +188,7 @@ def create_tkinter_gui(tests, command_string, files, solo_tests):
191188
"Use Edge Browser (--edge)",
192189
"Use Firefox Browser (--firefox)",
193190
]
194-
if "darwin" in sys.platform:
191+
if shared_utils.is_mac():
195192
options_list.append("Use Safari Browser (--safari)")
196193
brx = tk.StringVar(root)
197194
brx.set(options_list[0])
@@ -302,7 +299,7 @@ def create_tkinter_gui(tests, command_string, files, solo_tests):
302299
row += " " * 200
303300
ara[count] = tk.IntVar()
304301
cb = None
305-
if not is_windows:
302+
if not shared_utils.is_windows():
306303
cb = tk.Checkbutton(
307304
text_area,
308305
text=(row),
@@ -401,7 +398,7 @@ def create_tkinter_gui(tests, command_string, files, solo_tests):
401398

402399
def main():
403400
use_colors = True
404-
if "linux" in sys.platform:
401+
if shared_utils.is_linux():
405402
use_colors = False
406403
c0, c1, c2, c3, c4, c5, cr = set_colors(use_colors)
407404
command_args = sys.argv[2:]

0 commit comments

Comments
 (0)