Skip to content

Commit a78d440

Browse files
authored
Merge pull request #1550 from seleniumbase/fix-issue-with-getting-console-width
Fix console width issue when using SB Manager
2 parents c406380 + a039817 commit a78d440

File tree

8 files changed

+53
-17
lines changed

8 files changed

+53
-17
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
<meta property="og:image" content="https://seleniumbase.github.io/cdn/img/mac_sb_logo_5b.png" />
66
<link rel="icon" href="https://seleniumbase.github.io/img/logo3b.png" />
77

8-
<p align="center"><a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.github.io/cdn/img/sb_media_logo_t4.png" alt="SeleniumBase" title="SeleniumBase" width="408" /></a></p>
8+
<p align="center"><a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.github.io/cdn/img/sb_media_logo_t3.png" alt="SeleniumBase" title="SeleniumBase" width="476" /></a></p>
99

10-
<p align="center"><b>SeleniumBase</b> simplifies <a href="https://www.selenium.dev/documentation/webdriver/" target="_blank">WebDriver</a> automation with <b>Python</b>.</p>
10+
<p align="center"><b>SeleniumBase</b> simplifies <a href="https://www.selenium.dev/documentation/webdriver/" target="_blank">WebDriver</a> testing with <b>Python</b> and <a href="https://docs.pytest.org/en/latest/how-to/usage.html">pytest</a>.</p>
1111

1212
<p align="center"><a href="https://pypi.python.org/pypi/seleniumbase" target="_blank"><img src="https://img.shields.io/pypi/v/seleniumbase.svg?color=3399EE" alt="PyPI version" /></a> <a href="https://github.com/seleniumbase/SeleniumBase/releases" target="_blank"><img src="https://img.shields.io/github/v/release/seleniumbase/SeleniumBase.svg?color=22AAEE" alt="GitHub version" /></a> <a href="https://seleniumbase.io"><img src="https://img.shields.io/badge/docs-seleniumbase.io-11BBAA.svg" alt="SeleniumBase Docs" /></a> <a href="https://github.com/seleniumbase/SeleniumBase/actions" target="_blank"><img src="https://github.com/seleniumbase/SeleniumBase/workflows/CI%20build/badge.svg" alt="SeleniumBase GitHub Actions" /></a> <a href="https://gitter.im/seleniumbase/SeleniumBase" target="_blank"><img src="https://badges.gitter.im/seleniumbase/SeleniumBase.svg" alt="SeleniumBase" /></a></p>
1313

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ packaging>=20.9;python_version<"3.6"
55
packaging>=21.3;python_version>="3.6"
66
setuptools>=44.1.1;python_version<"3.6"
77
setuptools>=59.6.0;python_version>="3.6" and python_version<"3.7"
8-
setuptools>=65.4.1;python_version>="3.7"
8+
setuptools>=65.5.0;python_version>="3.7"
99
tomli>=1.2.3;python_version>="3.6" and python_version<"3.7"
1010
tomli>=2.0.1;python_version>="3.7"
1111
tqdm>=4.64.1

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.6.0"
2+
__version__ = "4.6.1"

seleniumbase/console_scripts/sb_print.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def main():
130130
used_width = None # code_width and few spaces on right for padding
131131
magic_syntax = None # the syntax generated by rich.syntax.Syntax()
132132
try:
133-
console_width = os.get_terminal_size()[0]
133+
console_width = os.get_terminal_size().columns
134134
if console_width:
135135
console_width = int(console_width)
136136
except Exception:

seleniumbase/fixtures/base_case.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7965,6 +7965,11 @@ def _print(self, msg):
79657965
if not sb_config._multithreaded:
79667966
print(msg)
79677967
else:
7968+
if type(msg) is not str:
7969+
try:
7970+
msg = str(msg)
7971+
except Exception:
7972+
pass
79687973
sys.stderr.write(msg + "\n")
79697974

79707975
def start_tour(self, name=None, interval=0):

seleniumbase/fixtures/shared_utils.py

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
"""
22
This module contains shared utility methods.
33
"""
4-
import fasteners
54
import subprocess
65
import sys
7-
import time
8-
from selenium.common.exceptions import ElementNotVisibleException
9-
from selenium.common.exceptions import NoAlertPresentException
10-
from selenium.common.exceptions import NoSuchAttributeException
11-
from selenium.common.exceptions import NoSuchElementException
12-
from selenium.common.exceptions import NoSuchFrameException
13-
from selenium.common.exceptions import NoSuchWindowException
14-
from seleniumbase.common.exceptions import TextNotVisibleException
156
from seleniumbase.fixtures import constants
167
from seleniumbase import config as sb_config
178

189

1910
def pip_install(package, version=None):
11+
import fasteners
12+
2013
pip_install_lock = fasteners.InterProcessLock(
2114
constants.PipInstall.LOCKFILE
2215
)
@@ -32,11 +25,47 @@ def pip_install(package, version=None):
3225
)
3326

3427

28+
def is_windows():
29+
platform = sys.platform
30+
if "win32" in platform or "win64" in platform or "x64" in platform:
31+
return True
32+
else:
33+
return False
34+
35+
36+
def get_terminal_width():
37+
import os
38+
39+
width = 80 # default
40+
try:
41+
width = os.get_terminal_size().columns
42+
except Exception:
43+
try:
44+
if is_windows():
45+
raise Exception("Don't even try 'tput cols' on Windows!")
46+
width = int(subprocess.check_output(["tput", "cols"]))
47+
except Exception:
48+
try:
49+
import shutil
50+
51+
width = shutil.get_terminal_size((80, 20)).columns
52+
except Exception:
53+
pass
54+
return width
55+
56+
3557
def format_exc(exception, message):
3658
"""
3759
Formats an exception message to make the output cleaner.
3860
"""
61+
from selenium.common.exceptions import ElementNotVisibleException
62+
from selenium.common.exceptions import NoAlertPresentException
63+
from selenium.common.exceptions import NoSuchAttributeException
64+
from selenium.common.exceptions import NoSuchElementException
65+
from selenium.common.exceptions import NoSuchFrameException
66+
from selenium.common.exceptions import NoSuchWindowException
3967
from seleniumbase.common.exceptions import NoSuchFileException
68+
from seleniumbase.common.exceptions import TextNotVisibleException
4069

4170
if exception == Exception:
4271
exc = Exception
@@ -101,6 +130,8 @@ def check_if_time_limit_exceeded():
101130
and sb_config.time_limit
102131
and not sb_config.recorder_mode
103132
):
133+
import time
134+
104135
time_limit = sb_config.time_limit
105136
now_ms = int(time.time() * 1000)
106137
if now_ms > sb_config.start_time_ms + sb_config.time_limit_ms:

seleniumbase/plugins/sb_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def SB(
9595
from seleniumbase import config as sb_config
9696
from seleniumbase.config import settings
9797
from seleniumbase.fixtures import constants
98+
from seleniumbase.fixtures import shared_utils
9899

99100
sb_config_backup = sb_config
100101
sys_argv = sys.argv
@@ -692,6 +693,7 @@ def SB(
692693
else:
693694
sb.headless_active = False
694695
test_name = None
696+
terminal_width = shared_utils.get_terminal_width()
695697
if test:
696698
import colorama
697699
import os
@@ -703,7 +705,6 @@ def SB(
703705
stack_base = traceback.format_stack()[0].split(os.sep)[-1]
704706
test_name = stack_base.split(", in ")[0].replace('", line ', ":")
705707
test_name += ":SB"
706-
terminal_width = os.get_terminal_size()[0]
707708
start_text = "=== {%s} starts ===" % test_name
708709
remaining_spaces = terminal_width - len(start_text)
709710
left_space = ""
@@ -764,7 +765,6 @@ def SB(
764765
if not test_passed:
765766
result = "failed"
766767
c1 = colorama.Fore.RED
767-
terminal_width = os.get_terminal_size()[0]
768768
end_text = (
769769
"=== {%s} %s in %.2fs ==="
770770
% (test_name, result, run_time)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
'packaging>=21.3;python_version>="3.6"',
132132
'setuptools>=44.1.1;python_version<"3.6"',
133133
'setuptools>=59.6.0;python_version>="3.6" and python_version<"3.7"',
134-
'setuptools>=65.4.1;python_version>="3.7"',
134+
'setuptools>=65.5.0;python_version>="3.7"',
135135
'tomli>=1.2.3;python_version>="3.6" and python_version<"3.7"',
136136
'tomli>=2.0.1;python_version>="3.7"',
137137
"tqdm>=4.64.1",

0 commit comments

Comments
 (0)