11
11
import pytest
12
12
13
13
logger = logging .getLogger ('pywebview' )
14
+ logger .setLevel (logging .DEBUG )
14
15
15
16
16
17
def run_test (
@@ -60,6 +61,15 @@ def run_test(
60
61
61
62
62
63
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
+ """
63
73
value_id = 'v' + uuid4 ().hex [:8 ]
64
74
func_args = str (func_args ).replace (',)' , ')' )
65
75
@@ -95,7 +105,9 @@ def _create_window(
95
105
):
96
106
def thread ():
97
107
try :
108
+ logger .info ('Running test thread' )
98
109
take_screenshot ()
110
+ take_screenshot2 ()
99
111
move_mouse_cocoa ()
100
112
if thread_func :
101
113
thread_func (window , * thread_param )
@@ -113,6 +125,7 @@ def thread():
113
125
t = threading .Thread (target = thread )
114
126
t .start ()
115
127
128
+ logger .info ('Starting webview' )
116
129
webview .start (** start_args )
117
130
118
131
@@ -133,7 +146,9 @@ def take_screenshot():
133
146
from subprocess import Popen
134
147
from datetime import datetime
135
148
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
+
137
152
138
153
def _destroy_window (_ , window , delay ):
139
154
def stop ():
@@ -149,3 +164,29 @@ def stop():
149
164
t .start ()
150
165
151
166
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