Skip to content

Commit 310697d

Browse files
authored
Merge pull request #2166 from seleniumbase/graphics-library-and-colorama-refactoring
Refactor Colorama, update graphics library, and add raw `driver` methods
2 parents 7e3761d + 0431974 commit 310697d

33 files changed

+259
-70
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ pytest test_coffee_cart.py --trace
698698
--dashboard # (Enable the SeleniumBase Dashboard. Saved at: dashboard.html)
699699
--dash-title=STRING # (Set the title shown for the generated dashboard.)
700700
--enable-3d-apis # (Enables WebGL and 3D APIs.)
701-
--swiftshader # (Use Chrome's "--use-gl=swiftshader" feature.)
701+
--swiftshader # (Chrome "--use-gl=angle" / "--use-angle=swiftshader-webgl")
702702
--incognito # (Enable Chrome's Incognito mode.)
703703
--guest # (Enable Chrome's Guest mode.)
704704
--dark # (Enable Chrome's Dark mode.)

examples/raw_parameter_script.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@
117117
sb.proxy_string = None
118118
sb.proxy_bypass_list = None
119119
sb.proxy_pac_url = None
120+
sb._swiftshader = False
120121
sb.multi_proxy = False
121-
sb.swiftshader = False
122122
sb.ad_block_on = False
123123
sb.highlights = None
124124
sb.interval = None

examples/test_chromedriver.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""This test is only for Chrome!
22
(Verify that your chromedriver is compatible with your version of Chrome.)"""
33
import colorama
4+
import sys
45
from seleniumbase import BaseCase
56
BaseCase.main(__name__, __file__)
67

@@ -15,7 +16,13 @@ def test_chromedriver_matches_chrome(self):
1516
major_chrome_version = chrome_version.split(".")[0]
1617
chromedriver_version = self.get_chromedriver_version()
1718
major_chromedriver_version = chromedriver_version.split(".")[0]
18-
colorama.init(autoreset=True)
19+
if (
20+
"win32" in sys.platform
21+
and hasattr(colorama, "just_fix_windows_console")
22+
):
23+
colorama.just_fix_windows_console()
24+
else:
25+
colorama.init(autoreset=True)
1926
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
2027
c2 = colorama.Fore.BLUE + colorama.Back.LIGHTGREEN_EX
2128
c3 = colorama.Fore.BLUE + colorama.Back.LIGHTYELLOW_EX

examples/translations/dutch_test_1.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
class MijnTestklasse(Testgeval):
77
def test_voorbeeld_1(self):
88
self.openen("https://nl.wikipedia.org/wiki/Hoofdpagina")
9-
self.controleren_element('a[title*="hoofdpagina gaan"]')
9+
self.controleren_element('a[title*="Welkom voor nieuwkomers"]')
1010
self.controleren_tekst("Welkom op Wikipedia", "td.hp-welkom")
11-
self.typ("#searchInput", "Stroopwafel")
12-
self.klik("#searchButton")
11+
self.typ("#searchform input", "Stroopwafel")
12+
self.klik("#searchform button")
1313
self.controleren_tekst("Stroopwafel", "#firstHeading")
1414
self.controleren_element('img[src*="Stroopwafels"]')
15-
self.typ("#searchInput", "Rijksmuseum Amsterdam")
16-
self.klik("#searchButton")
15+
self.typ("#searchform input", "Rijksmuseum Amsterdam")
16+
self.klik("#searchform button")
1717
self.controleren_tekst("Rijksmuseum", "#firstHeading")
1818
self.controleren_element('img[src*="Rijksmuseum"]')
1919
self.terug()

help_docs/customizing_test_runs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ pytest my_first_test.py --settings-file=custom_settings.py
178178
--dashboard # (Enable the SeleniumBase Dashboard. Saved at: dashboard.html)
179179
--dash-title=STRING # (Set the title shown for the generated dashboard.)
180180
--enable-3d-apis # (Enables WebGL and 3D APIs.)
181-
--swiftshader # (Use Chrome's "--use-gl=swiftshader" feature.)
181+
--swiftshader # (Chrome "--use-gl=angle" / "--use-angle=swiftshader-webgl")
182182
--incognito # (Enable Chrome's Incognito mode.)
183183
--guest # (Enable Chrome's Guest mode.)
184184
--dark # (Enable Chrome's Dark mode.)

mkdocs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,6 @@ nav:
180180
extra:
181181
analytics:
182182
provider: google
183-
# property: G-P5KFWRNLRN
184-
property: UA-167313767-1
185-
# google_analytics: ['UA-167313767-1', 'seleniumbase.io']
183+
property: G-P5KFWRNLRN
184+
# property: UA-167313767-1
185+
# google_analytics: ['G-P5KFWRNLRN', 'seleniumbase.io']

mkdocs_build/requirements.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# mkdocs dependencies for generating the seleniumbase.io website
22
# Minimum Python version: 3.8 (for generating docs only)
33

4-
regex>=2023.8.8
4+
regex>=2023.10.3
55
PyYAML>=6.0.1
66
pymdown-extensions>=10.3
77
pipdeptree>=2.13.0
88
python-dateutil>=2.8.2
9-
Markdown==3.4.4
9+
Markdown==3.5
1010
markdown2==2.4.10
1111
MarkupSafe==2.1.3
1212
Jinja2==3.1.2
@@ -15,12 +15,12 @@ ghp-import==2.1.0
1515
watchdog==3.0.0
1616
cairocffi==1.6.1
1717
pathspec==0.11.2
18-
Babel==2.12.1
18+
Babel==2.13.0
1919
paginate==0.5.6
2020
pyquery==2.0.0
2121
readtime==3.0.0
2222
mkdocs==1.5.3
23-
mkdocs-material==9.4.2
23+
mkdocs-material==9.4.4
2424
mkdocs-exclude-search==0.6.5
2525
mkdocs-simple-hooks==0.1.5
2626
mkdocs-material-extensions==1.2

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ attrs>=23.1.0
77
certifi>=2023.7.22
88
filelock>=3.12.2;python_version<"3.8"
99
filelock>=3.12.4;python_version>="3.8"
10-
platformdirs>=3.10.0
10+
platformdirs>=3.11.0
1111
parse>=1.19.1
1212
parse-type>=0.6.2
1313
six==1.16.0
@@ -63,7 +63,7 @@ rich==13.6.0
6363

6464
coverage==6.2;python_version<"3.7"
6565
coverage==7.2.7;python_version>="3.7" and python_version<"3.8"
66-
coverage==7.3.1;python_version>="3.8"
66+
coverage==7.3.2;python_version>="3.8"
6767
pytest-cov==4.0.0;python_version<"3.7"
6868
pytest-cov==4.1.0;python_version>="3.7"
6969
flake8==5.0.4;python_version<"3.9"

seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "4.19.1"
2+
__version__ = "4.19.2"

seleniumbase/behave/behave_sb.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@
111111
from seleniumbase.fixtures import constants
112112
from seleniumbase.fixtures import shared_utils
113113

114+
is_linux = shared_utils.is_linux()
115+
is_windows = shared_utils.is_windows()
114116
sb_config.__base_class = None
115117

116118

@@ -829,10 +831,10 @@ def get_configured_sb(context):
829831
'\n (Your browser choice was: "%s")\n' % sb.browser
830832
)
831833
# The Xvfb virtual display server is for Linux OS Only.
832-
if sb.xvfb and not shared_utils.is_linux():
834+
if sb.xvfb and not is_linux:
833835
sb.xvfb = False
834836
if (
835-
shared_utils.is_linux()
837+
is_linux
836838
and not sb.headed
837839
and not sb.headless
838840
and not sb.headless2
@@ -1020,7 +1022,7 @@ def dashboard_pre_processing():
10201022
filename = None
10211023
feature_name = None
10221024
scenario_name = None
1023-
if shared_utils.is_windows():
1025+
if is_windows:
10241026
output = output.decode("latin1")
10251027
else:
10261028
output = output.decode("utf-8")
@@ -1129,8 +1131,11 @@ def behave_dashboard_prepare():
11291131
stars = "*" * star_len
11301132
c1 = ""
11311133
cr = ""
1132-
if not shared_utils.is_linux():
1133-
colorama.init(autoreset=True)
1134+
if not is_linux:
1135+
if is_windows and hasattr(colorama, "just_fix_windows_console"):
1136+
colorama.just_fix_windows_console()
1137+
else:
1138+
colorama.init(autoreset=True)
11341139
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
11351140
cr = colorama.Style.RESET_ALL
11361141
print("Dashboard: %s%s%s\n%s" % (c1, dash_path, cr, stars))
@@ -1144,7 +1149,7 @@ def _perform_behave_unconfigure_():
11441149
if sb_config.shared_driver:
11451150
try:
11461151
if (
1147-
not shared_utils.is_windows()
1152+
not is_windows
11481153
or sb_config.browser == "ie"
11491154
or sb_config.shared_driver.service.process
11501155
):
@@ -1221,7 +1226,7 @@ def do_final_driver_cleanup_as_needed():
12211226
try:
12221227
if hasattr(sb_config, "last_driver") and sb_config.last_driver:
12231228
if (
1224-
not shared_utils.is_windows()
1229+
not is_windows
12251230
or sb_config.browser == "ie"
12261231
or sb_config.last_driver.service.process
12271232
):
@@ -1245,8 +1250,11 @@ def _perform_behave_terminal_summary_():
12451250
equals = "=" * (equals_len + 2)
12461251
c2 = ""
12471252
cr = ""
1248-
if not shared_utils.is_linux():
1249-
colorama.init(autoreset=True)
1253+
if not is_linux:
1254+
if is_windows and hasattr(colorama, "just_fix_windows_console"):
1255+
colorama.just_fix_windows_console()
1256+
else:
1257+
colorama.init(autoreset=True)
12501258
c2 = colorama.Fore.MAGENTA + colorama.Back.LIGHTYELLOW_EX
12511259
cr = colorama.Style.RESET_ALL
12521260
if sb_config.dashboard:

seleniumbase/console_scripts/logo_helper.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
http://www.patorjk.com/software/taag/#p=display&f=Slant&t=SeleniumBase """
44

55
import colorama
6+
import sys
67

78
r"""
89
______ __ _ ____
@@ -14,7 +15,13 @@
1415

1516

1617
def get_seleniumbase_logo():
17-
colorama.init(autoreset=True)
18+
if (
19+
"win32" in sys.platform
20+
and hasattr(colorama, "just_fix_windows_console")
21+
):
22+
colorama.just_fix_windows_console()
23+
else:
24+
colorama.init(autoreset=True)
1825
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
1926
c2 = colorama.Fore.BLUE + colorama.Back.LIGHTGREEN_EX
2027
c3 = colorama.Back.CYAN

seleniumbase/console_scripts/run.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@
4141
import time
4242
from seleniumbase.config import settings
4343
from seleniumbase.fixtures import constants
44+
from seleniumbase.fixtures import shared_utils
4445

45-
colorama.init(autoreset=True)
46+
if shared_utils.is_windows() and hasattr(colorama, "just_fix_windows_console"):
47+
colorama.just_fix_windows_console()
48+
else:
49+
colorama.init(autoreset=True)
4650

4751

4852
def show_usage():
@@ -1330,7 +1334,6 @@ def main():
13301334
show_detailed_help()
13311335
else:
13321336
show_usage()
1333-
colorama.init(autoreset=True)
13341337
c5 = colorama.Fore.RED + colorama.Back.LIGHTYELLOW_EX
13351338
c7 = colorama.Fore.BLACK + colorama.Back.MAGENTA
13361339
cr = colorama.Style.RESET_ALL

seleniumbase/console_scripts/sb_behave_gui.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ def set_colors(use_colors):
3838
c6 = ""
3939
cr = ""
4040
if use_colors:
41-
colorama.init(autoreset=True)
41+
if (
42+
"win32" in sys.platform
43+
and hasattr(colorama, "just_fix_windows_console")
44+
):
45+
colorama.just_fix_windows_console()
46+
else:
47+
colorama.init(autoreset=True)
4248
c0 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
4349
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTGREEN_EX
4450
c2 = colorama.Fore.RED + colorama.Back.LIGHTYELLOW_EX

seleniumbase/console_scripts/sb_caseplans.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ def set_colors(use_colors):
4242
c5 = ""
4343
cr = ""
4444
if use_colors:
45-
colorama.init(autoreset=True)
45+
if (
46+
"win32" in sys.platform
47+
and hasattr(colorama, "just_fix_windows_console")
48+
):
49+
colorama.just_fix_windows_console()
50+
else:
51+
colorama.init(autoreset=True)
4652
c0 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
4753
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTGREEN_EX
4854
c2 = colorama.Fore.RED + colorama.Back.LIGHTYELLOW_EX

seleniumbase/console_scripts/sb_commander.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ def set_colors(use_colors):
4242
c5 = ""
4343
cr = ""
4444
if use_colors:
45-
colorama.init(autoreset=True)
45+
if (
46+
"win32" in sys.platform
47+
and hasattr(colorama, "just_fix_windows_console")
48+
):
49+
colorama.just_fix_windows_console()
50+
else:
51+
colorama.init(autoreset=True)
4652
c0 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
4753
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTGREEN_EX
4854
c2 = colorama.Fore.RED + colorama.Back.LIGHTYELLOW_EX

seleniumbase/console_scripts/sb_install.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,10 @@ def main(override=None, intel_for_uc=None, force_uc=None):
293293
use_version = ""
294294
new_file = ""
295295
f_name = ""
296-
colorama.init(autoreset=True)
296+
if IS_WINDOWS and hasattr(colorama, "just_fix_windows_console"):
297+
colorama.just_fix_windows_console()
298+
else:
299+
colorama.init(autoreset=True)
297300
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
298301
c2 = colorama.Fore.BLUE + colorama.Back.LIGHTGREEN_EX
299302
c3 = colorama.Fore.BLUE + colorama.Back.LIGHTYELLOW_EX

seleniumbase/console_scripts/sb_mkchart.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,13 @@ def main():
6262
c7 = ""
6363
cr = ""
6464
if "linux" not in sys.platform:
65-
colorama.init(autoreset=True)
65+
if (
66+
"win32" in sys.platform
67+
and hasattr(colorama, "just_fix_windows_console")
68+
):
69+
colorama.just_fix_windows_console()
70+
else:
71+
colorama.init(autoreset=True)
6672
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
6773
c5 = colorama.Fore.RED + colorama.Back.LIGHTYELLOW_EX
6874
c7 = colorama.Fore.BLACK + colorama.Back.MAGENTA

seleniumbase/console_scripts/sb_mkdir.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,13 @@ def main():
5454
c7 = ""
5555
cr = ""
5656
if "linux" not in sys.platform:
57-
colorama.init(autoreset=True)
57+
if (
58+
"win32" in sys.platform
59+
and hasattr(colorama, "just_fix_windows_console")
60+
):
61+
colorama.just_fix_windows_console()
62+
else:
63+
colorama.init(autoreset=True)
5864
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
5965
c5 = colorama.Fore.RED + colorama.Back.LIGHTYELLOW_EX
6066
c7 = colorama.Fore.BLACK + colorama.Back.MAGENTA

seleniumbase/console_scripts/sb_mkfile.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,13 @@ def main():
9292
c7 = ""
9393
cr = ""
9494
if "linux" not in sys.platform:
95-
colorama.init(autoreset=True)
95+
if (
96+
"win32" in sys.platform
97+
and hasattr(colorama, "just_fix_windows_console")
98+
):
99+
colorama.just_fix_windows_console()
100+
else:
101+
colorama.init(autoreset=True)
96102
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
97103
c5 = colorama.Fore.RED + colorama.Back.LIGHTYELLOW_EX
98104
c7 = colorama.Fore.BLACK + colorama.Back.MAGENTA

seleniumbase/console_scripts/sb_mkpres.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,13 @@ def main():
6262
c7 = ""
6363
cr = ""
6464
if "linux" not in sys.platform:
65-
colorama.init(autoreset=True)
65+
if (
66+
"win32" in sys.platform
67+
and hasattr(colorama, "just_fix_windows_console")
68+
):
69+
colorama.just_fix_windows_console()
70+
else:
71+
colorama.init(autoreset=True)
6672
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
6773
c5 = colorama.Fore.RED + colorama.Back.LIGHTYELLOW_EX
6874
c7 = colorama.Fore.BLACK + colorama.Back.MAGENTA

seleniumbase/console_scripts/sb_mkrec.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,13 @@ def set_colors(use_colors):
7171
c7 = ""
7272
cr = ""
7373
if use_colors:
74-
colorama.init(autoreset=True)
74+
if (
75+
"win32" in sys.platform
76+
and hasattr(colorama, "just_fix_windows_console")
77+
):
78+
colorama.just_fix_windows_console()
79+
else:
80+
colorama.init(autoreset=True)
7581
c0 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
7682
c1 = colorama.Fore.RED + colorama.Back.LIGHTYELLOW_EX
7783
c2 = colorama.Fore.LIGHTRED_EX + colorama.Back.LIGHTYELLOW_EX

0 commit comments

Comments
 (0)