Merge pull request #1550 from seleniumbase/fix-issue-with-getting-console-width

Fix console width issue when using SB Manager
This commit is contained in:
Michael Mintz 2022-10-14 15:22:41 -04:00 committed by GitHub
commit a78d44024c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 53 additions and 17 deletions

View File

@ -5,9 +5,9 @@
<meta property="og:image" content="https://seleniumbase.github.io/cdn/img/mac_sb_logo_5b.png" />
<link rel="icon" href="https://seleniumbase.github.io/img/logo3b.png" />
<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>
<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>
<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>
<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>
<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>

View File

@ -5,7 +5,7 @@ packaging>=20.9;python_version<"3.6"
packaging>=21.3;python_version>="3.6"
setuptools>=44.1.1;python_version<"3.6"
setuptools>=59.6.0;python_version>="3.6" and python_version<"3.7"
setuptools>=65.4.1;python_version>="3.7"
setuptools>=65.5.0;python_version>="3.7"
tomli>=1.2.3;python_version>="3.6" and python_version<"3.7"
tomli>=2.0.1;python_version>="3.7"
tqdm>=4.64.1

View File

@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "4.6.0"
__version__ = "4.6.1"

View File

@ -130,7 +130,7 @@ def main():
used_width = None # code_width and few spaces on right for padding
magic_syntax = None # the syntax generated by rich.syntax.Syntax()
try:
console_width = os.get_terminal_size()[0]
console_width = os.get_terminal_size().columns
if console_width:
console_width = int(console_width)
except Exception:

View File

@ -7965,6 +7965,11 @@ class BaseCase(unittest.TestCase):
if not sb_config._multithreaded:
print(msg)
else:
if type(msg) is not str:
try:
msg = str(msg)
except Exception:
pass
sys.stderr.write(msg + "\n")
def start_tour(self, name=None, interval=0):

View File

@ -1,22 +1,15 @@
"""
This module contains shared utility methods.
"""
import fasteners
import subprocess
import sys
import time
from selenium.common.exceptions import ElementNotVisibleException
from selenium.common.exceptions import NoAlertPresentException
from selenium.common.exceptions import NoSuchAttributeException
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoSuchFrameException
from selenium.common.exceptions import NoSuchWindowException
from seleniumbase.common.exceptions import TextNotVisibleException
from seleniumbase.fixtures import constants
from seleniumbase import config as sb_config
def pip_install(package, version=None):
import fasteners
pip_install_lock = fasteners.InterProcessLock(
constants.PipInstall.LOCKFILE
)
@ -32,11 +25,47 @@ def pip_install(package, version=None):
)
def is_windows():
platform = sys.platform
if "win32" in platform or "win64" in platform or "x64" in platform:
return True
else:
return False
def get_terminal_width():
import os
width = 80 # default
try:
width = os.get_terminal_size().columns
except Exception:
try:
if is_windows():
raise Exception("Don't even try 'tput cols' on Windows!")
width = int(subprocess.check_output(["tput", "cols"]))
except Exception:
try:
import shutil
width = shutil.get_terminal_size((80, 20)).columns
except Exception:
pass
return width
def format_exc(exception, message):
"""
Formats an exception message to make the output cleaner.
"""
from selenium.common.exceptions import ElementNotVisibleException
from selenium.common.exceptions import NoAlertPresentException
from selenium.common.exceptions import NoSuchAttributeException
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoSuchFrameException
from selenium.common.exceptions import NoSuchWindowException
from seleniumbase.common.exceptions import NoSuchFileException
from seleniumbase.common.exceptions import TextNotVisibleException
if exception == Exception:
exc = Exception
@ -101,6 +130,8 @@ def check_if_time_limit_exceeded():
and sb_config.time_limit
and not sb_config.recorder_mode
):
import time
time_limit = sb_config.time_limit
now_ms = int(time.time() * 1000)
if now_ms > sb_config.start_time_ms + sb_config.time_limit_ms:

View File

@ -95,6 +95,7 @@ def SB(
from seleniumbase import config as sb_config
from seleniumbase.config import settings
from seleniumbase.fixtures import constants
from seleniumbase.fixtures import shared_utils
sb_config_backup = sb_config
sys_argv = sys.argv
@ -692,6 +693,7 @@ def SB(
else:
sb.headless_active = False
test_name = None
terminal_width = shared_utils.get_terminal_width()
if test:
import colorama
import os
@ -703,7 +705,6 @@ def SB(
stack_base = traceback.format_stack()[0].split(os.sep)[-1]
test_name = stack_base.split(", in ")[0].replace('", line ', ":")
test_name += ":SB"
terminal_width = os.get_terminal_size()[0]
start_text = "=== {%s} starts ===" % test_name
remaining_spaces = terminal_width - len(start_text)
left_space = ""
@ -764,7 +765,6 @@ def SB(
if not test_passed:
result = "failed"
c1 = colorama.Fore.RED
terminal_width = os.get_terminal_size()[0]
end_text = (
"=== {%s} %s in %.2fs ==="
% (test_name, result, run_time)

View File

@ -131,7 +131,7 @@ setup(
'packaging>=21.3;python_version>="3.6"',
'setuptools>=44.1.1;python_version<"3.6"',
'setuptools>=59.6.0;python_version>="3.6" and python_version<"3.7"',
'setuptools>=65.4.1;python_version>="3.7"',
'setuptools>=65.5.0;python_version>="3.7"',
'tomli>=1.2.3;python_version>="3.6" and python_version<"3.7"',
'tomli>=2.0.1;python_version>="3.7"',
"tqdm>=4.64.1",