Skip to content

Commit 0ebde01

Browse files
committed
Fix tests
1 parent 5e1fdab commit 0ebde01

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

tests/util.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import pytest
1212

1313
logger = logging.getLogger('pywebview')
14+
logger.setLevel(logging.DEBUG)
1415

1516

1617
def run_test(
@@ -60,6 +61,15 @@ def run_test(
6061

6162

6263
def assert_js(window, func_name, expected_result, *func_args):
64+
"""
65+
A helper function to run a Javascript function in the window and assert the result.
66+
67+
@param window: window instance created with webview.create_window
68+
@param func_name: the name of the Javascript function to run
69+
@param expected_result: the expected result of the function
70+
@param func_args: arguments to pass to the function
71+
72+
"""
6373
value_id = 'v' + uuid4().hex[:8]
6474
func_args = str(func_args).replace(',)', ')')
6575

@@ -95,7 +105,9 @@ def _create_window(
95105
):
96106
def thread():
97107
try:
108+
logger.info('Running test thread')
98109
take_screenshot()
110+
take_screenshot2()
99111
move_mouse_cocoa()
100112
if thread_func:
101113
thread_func(window, *thread_param)
@@ -113,6 +125,7 @@ def thread():
113125
t = threading.Thread(target=thread)
114126
t.start()
115127

128+
logger.info('Starting webview')
116129
webview.start(**start_args)
117130

118131

@@ -133,7 +146,9 @@ def take_screenshot():
133146
from subprocess import Popen
134147
from datetime import datetime
135148

136-
Popen(['screencapture', '-x', f'/tmp/screenshot-{datetime.now().timestamp()}.png']).wait()
149+
os.makedirs('/tmp/screenshots', exist_ok=True)
150+
Popen(['screencapture', '-x', f'/tmp/screenshots/screenshot-{datetime.now().timestamp()}.png']).wait()
151+
137152

138153
def _destroy_window(_, window, delay):
139154
def stop():
@@ -149,3 +164,29 @@ def stop():
149164
t.start()
150165

151166
return event
167+
168+
169+
170+
def take_screenshot2():
171+
from PIL import ImageGrab
172+
from datetime import datetime
173+
174+
# Create the directory if it doesn't exist
175+
save_dir = "/tmp/screenshots"
176+
os.makedirs(save_dir, exist_ok=True)
177+
178+
# Get current timestamp for unique file name
179+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
180+
file_name = f"screenshot_pil_{timestamp}.png"
181+
182+
# Full path to save the screenshot
183+
save_path = os.path.join(save_dir, file_name)
184+
185+
# Take the screenshot
186+
screenshot = ImageGrab.grab()
187+
188+
# Save the screenshot
189+
screenshot.save(save_path, "PNG")
190+
191+
print(f"Screenshot saved at: {save_path}")
192+
return save_path

0 commit comments

Comments
 (0)