Skip to content

Commit 21d6a75

Browse files
authored
Merge pull request #2014 from seleniumbase/cleaner-logging
Cleaner Logging
2 parents b3dd883 + 591f86f commit 21d6a75

File tree

14 files changed

+64
-37
lines changed

14 files changed

+64
-37
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,7 @@ pytest --reruns=1 --reruns-delay=1
13381338
<p><div><a href="https://github.com/mdmintz">https://github.com/mdmintz</a></div></p>
13391339
13401340
<div><a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.github.io/cdn/img/fancy_logo_14.png" title="SeleniumBase" width="220" /></a></div> <div><a href="https://github.com/seleniumbase/SeleniumBase/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-22BBCC.svg" title="SeleniumBase" /></a> <a href="https://gitter.im/seleniumbase/SeleniumBase" target="_blank"><img src="https://img.shields.io/gitter/room/seleniumbase/SeleniumBase.svg" alt="Gitter chat"/></a></div> <div><a href="https://github.com/seleniumbase/SeleniumBase"><img src="https://img.shields.io/badge/tested%20with-SeleniumBase-04C38E.svg" alt="Tested with SeleniumBase" /></a></div> <div><a href="https://seleniumbase.io"><img src="https://img.shields.io/badge/docs-seleniumbase.io-11BBAA.svg" alt="SeleniumBase Docs" /></a></div>
1341-
<div><a href="https://pepy.tech/project/seleniumbase" target="_blank"><img src="https://pepy.tech/badge/seleniumbase" alt="SeleniumBase PyPI downloads" /></a></div>
1341+
<div><a href="https://pepy.tech/project/seleniumbase" target="_blank"><img src="https://static.pepy.tech/badge/seleniumbase" alt="SeleniumBase PyPI downloads" /></a></div>
13421342
<div><a href="https://github.com/seleniumbase/SeleniumBase/stargazers"><img src="https://img.shields.io/github/stars/seleniumbase/seleniumbase.svg?color=19A57B" title="Stargazers" /></a></div>
13431343
13441344
--------

mkdocs_build/requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
regex>=2023.8.8
55
pkginfo>=1.9.6
66
PyYAML>=6.0.1
7-
readme-renderer>=40.0
7+
readme-renderer>=41.0
88
pymdown-extensions>=10.1
99
importlib-metadata>=6.8.0
1010
pipdeptree>=2.13.0
@@ -18,9 +18,9 @@ livereload==2.6.3
1818
Markdown==3.4.4
1919
MarkupSafe==2.1.3
2020
Jinja2==3.1.2
21-
click==8.1.6
21+
click==8.1.7
2222
ghp-import==2.1.0
23-
lunr==0.6.2
23+
lunr==0.7.0.post1
2424
tornado==6.3.3
2525
watchdog==3.0.0
2626
cairocffi==1.6.1

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ packaging>=21.3;python_version<"3.7"
44
packaging>=23.1;python_version>="3.7"
55
setuptools>=59.6.0;python_version<"3.7"
66
setuptools>=68.0.0;python_version>="3.7" and python_version<"3.8"
7-
setuptools>=68.1.0;python_version>="3.8"
7+
setuptools>=68.1.2;python_version>="3.8"
88
wheel>=0.37.1;python_version<"3.7"
99
wheel>=0.41.1;python_version>="3.7"
1010
attrs==22.1.0;python_version<"3.7"

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.17.7"
2+
__version__ = "4.17.8"

seleniumbase/behave/behave_sb.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ def get_configured_sb(context):
940940
if sb_config.dash_title:
941941
constants.Dashboard.TITLE = sb_config.dash_title.replace("_", " ")
942942

943-
log_helper.log_folder_setup(sb.log_path, sb.archive_logs)
943+
log_helper.log_folder_setup("latest_logs/", sb.archive_logs)
944944
download_helper.reset_downloads_folder()
945945
proxy_helper.remove_proxy_zip_if_present()
946946
return sb
@@ -1152,10 +1152,9 @@ def _perform_behave_unconfigure_():
11521152
except Exception:
11531153
pass
11541154
sb_config.shared_driver = None
1155-
if hasattr(sb_config, "log_path"):
1156-
log_helper.archive_logs_if_set(
1157-
sb_config.log_path, sb_config.archive_logs
1158-
)
1155+
if hasattr(sb_config, "archive_logs"):
1156+
log_helper.archive_logs_if_set("latest_logs/", sb_config.archive_logs)
1157+
log_helper.clear_empty_logs()
11591158
# Dashboard post-processing: Disable time-based refresh and stamp complete
11601159
if not hasattr(sb_config, "dashboard") or not sb_config.dashboard:
11611160
# Done with "behave_unconfigure" unless using the Dashboard

seleniumbase/core/download_helper.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,22 @@ def get_downloads_folder():
2424
def reset_downloads_folder():
2525
"""Clears the downloads folder.
2626
If settings.ARCHIVE_EXISTING_DOWNLOADS is set to True, archives it."""
27+
archived_downloads_folder = os.path.join(os.getcwd(), ARCHIVE_DIR) + os.sep
2728
if os.path.exists(downloads_path) and not os.listdir(downloads_path) == []:
28-
archived_downloads_folder = os.path.join(
29-
downloads_path, "..", ARCHIVE_DIR
30-
)
3129
reset_downloads_folder_assistant(archived_downloads_folder)
30+
if os.path.exists(downloads_path) and os.listdir(downloads_path) == []:
31+
try:
32+
os.rmdir(downloads_path)
33+
except OSError:
34+
pass
35+
if (
36+
os.path.exists(archived_downloads_folder)
37+
and os.listdir(archived_downloads_folder) == []
38+
):
39+
try:
40+
os.rmdir(archived_downloads_folder)
41+
except OSError:
42+
pass
3243

3344

3445
def reset_downloads_folder_assistant(archived_downloads_folder):

seleniumbase/core/log_helper.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,3 +563,18 @@ def log_folder_setup(log_path, archive_logs=False):
563563
pass
564564
else:
565565
shutil.rmtree(archived_logs) # (Archive test run later)
566+
567+
568+
def clear_empty_logs():
569+
latest_logs_dir = os.path.join(os.getcwd(), "latest_logs") + os.sep
570+
archived_folder = os.path.join(os.getcwd(), "archived_logs") + os.sep
571+
if os.path.exists(latest_logs_dir) and not os.listdir(latest_logs_dir):
572+
try:
573+
os.rmdir(latest_logs_dir)
574+
except OSError:
575+
pass
576+
if os.path.exists(archived_folder) and not os.listdir(archived_folder):
577+
try:
578+
os.rmdir(archived_folder)
579+
except OSError:
580+
pass

seleniumbase/fixtures/base_case.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def click(
395395
self.__shadow_click(selector, timeout)
396396
return
397397
if self.__needs_minimum_wait() or self.browser == "safari":
398-
time.sleep(0.022)
398+
time.sleep(0.03)
399399
element = page_actions.wait_for_element_visible(
400400
self.driver,
401401
selector,
@@ -628,20 +628,20 @@ def click(
628628
except Exception:
629629
pass
630630
if self.__needs_minimum_wait() or self.browser == "safari":
631-
time.sleep(0.026)
631+
time.sleep(0.03)
632632
try:
633633
if self.driver.current_url != pre_action_url:
634634
self.__ad_block_as_needed()
635635
self.__disable_beforeunload_as_needed()
636636
if self.__needs_minimum_wait():
637-
time.sleep(0.026)
637+
time.sleep(0.03)
638638
except Exception:
639639
try:
640640
self.wait_for_ready_state_complete()
641641
except Exception:
642642
pass
643643
if self.__needs_minimum_wait():
644-
time.sleep(0.026)
644+
time.sleep(0.03)
645645
else:
646646
time.sleep(0.08)
647647
if self.demo_mode:
@@ -12595,7 +12595,7 @@ def __click_with_offset(
1259512595
self.__scroll_to_element(element, selector, by)
1259612596
self.wait_for_ready_state_complete()
1259712597
if self.__needs_minimum_wait():
12598-
time.sleep(0.025)
12598+
time.sleep(0.03)
1259912599
if self.demo_mode and mark is None:
1260012600
mark = True
1260112601
if mark:

seleniumbase/fixtures/constants.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ class MultiBrowser:
147147
DRIVER_FIXING_LOCK = Files.DOWNLOADS_FOLDER + "/driver_fixing.lock"
148148
DRIVER_REPAIRED = Files.DOWNLOADS_FOLDER + "/driver_fixed.lock"
149149
CERT_FIXING_LOCK = Files.DOWNLOADS_FOLDER + "/cert_fixing.lock"
150-
DOWNLOAD_FILE_LOCK = Files.DOWNLOADS_FOLDER + "/download_file.lock"
150+
DOWNLOAD_FILE_LOCK = Files.DOWNLOADS_FOLDER + "/downloading.lock"
151+
FILE_IO_LOCK = Files.DOWNLOADS_FOLDER + "/file_io.lock"
151152

152153

153154
class SavedCookies:

seleniumbase/fixtures/page_utils.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,10 @@ def _download_file_to(file_url, destination_folder, new_file_name=None):
256256

257257

258258
def _save_data_as(data, destination_folder, file_name):
259-
download_file_lock = fasteners.InterProcessLock(
260-
constants.MultiBrowser.DOWNLOAD_FILE_LOCK
259+
file_io_lock = fasteners.InterProcessLock(
260+
constants.MultiBrowser.FILE_IO_LOCK
261261
)
262-
with download_file_lock:
262+
with file_io_lock:
263263
out_file = codecs.open(
264264
os.path.join(destination_folder, file_name), "w+", encoding="utf-8"
265265
)
@@ -268,10 +268,10 @@ def _save_data_as(data, destination_folder, file_name):
268268

269269

270270
def _append_data_to_file(data, destination_folder, file_name):
271-
download_file_lock = fasteners.InterProcessLock(
272-
constants.MultiBrowser.DOWNLOAD_FILE_LOCK
271+
file_io_lock = fasteners.InterProcessLock(
272+
constants.MultiBrowser.FILE_IO_LOCK
273273
)
274-
with download_file_lock:
274+
with file_io_lock:
275275
existing_data = ""
276276
if os.path.exists(os.path.join(destination_folder, file_name)):
277277
with open(os.path.join(destination_folder, file_name), "r") as f:
@@ -286,10 +286,10 @@ def _append_data_to_file(data, destination_folder, file_name):
286286

287287

288288
def _get_file_data(folder, file_name):
289-
download_file_lock = fasteners.InterProcessLock(
290-
constants.MultiBrowser.DOWNLOAD_FILE_LOCK
289+
file_io_lock = fasteners.InterProcessLock(
290+
constants.MultiBrowser.FILE_IO_LOCK
291291
)
292-
with download_file_lock:
292+
with file_io_lock:
293293
if not os.path.exists(os.path.join(folder, file_name)):
294294
raise Exception("File not found!")
295295
with open(os.path.join(folder, file_name), "r") as f:

0 commit comments

Comments
 (0)