@@ -260,13 +260,18 @@ def _setup_resize_listener(driver):
260260def change_window_dimension_and_wait (driver , width , height , resizeCount ):
261261 try :
262262 if CDP_SUPPORT_SELENIUM and driver .capabilities ['browserName' ] == 'chrome' :
263+ print (f'Attempting to resize using CDP for width { width } and height { height } ' )
263264 driver .execute_cdp_cmd ('Emulation.setDeviceMetricsOverride' , { 'height' : height ,
264265 'width' : width , 'deviceScaleFactor' : 1 , 'mobile' : False })
265266 else :
267+ #driver.execute_script(f"window.resizeTo({width}, {height});")
266268 driver .set_window_size (width , height )
267269 except Exception as e :
268270 log (f'Resizing using cdp failed falling back driver for width { width } { e } ' , 'debug' )
271+ print (f'Error during CDP resize: { e } , falling back to driver resize for width { width } and height { height } ' )
272+ #driver.execute_script(f"window.resizeTo({width}, {height});")
269273 driver .set_window_size (width , height )
274+ print (f'Resized to { width } x{ height } , waiting for resize event...' )
270275
271276 try :
272277 WebDriverWait (driver , 1 ).until (
@@ -291,34 +296,29 @@ def capture_responsive_dom(driver, cookies, config, percy_dom_script=None, **kwa
291296 dom_snapshots = []
292297 window_size = driver .get_window_size ()
293298 current_width , current_height = window_size ['width' ], window_size ['height' ]
299+ log (f'Before window size: { current_width } x{ current_height } ' , 'debug' )
294300 last_window_width = current_width
295301 resize_count = 0
296302 # Initialize resize listener once before the loop
297- _setup_resize_listener ( driver )
303+
298304 driver .execute_script ("PercyDOM.waitForResize()" )
299305 target_height = current_height
300306
301307 if PERCY_RESPONSIVE_CAPTURE_MIN_HEIGHT :
302- min_height = kwargs .get ('minHeight' ) or config .get ('snapshot' , {}).get ('minHeight' )
303- if min_height :
308+ target_height = kwargs .get ('minHeight' ) or config .get ('snapshot' , {}).get ('minHeight' )
309+ if target_height :
304310 try :
305- min_height = int (min_height )
311+ target_height = int (target_height )
306312 except (TypeError , ValueError ):
307313 log (
308- f'Invalid minHeight value { min_height !r} ; expected integer, '
314+ f'Invalid minHeight value { target_height !r} ; expected integer, '
309315 'using current window height instead.' ,
310316 'debug' ,
311317 )
312- else :
313- target_height = driver .execute_script (
314- f"return window.outerHeight - window.innerHeight + { min_height } " )
315- log (
316- f'Calculated height for responsive capture using minHeight: { target_height } ' ,
317- 'debug' )
318-
319318 for width_dict in widths :
320319 width = width_dict ['width' ]
321320 height = width_dict .get ('height' , target_height )
321+ print (f'Capturing responsive snapshot for width: { width } and height: { height } ' )
322322 if last_window_width != width :
323323 resize_count += 1
324324 change_window_dimension_and_wait (driver , width , height , resize_count )
@@ -331,13 +331,17 @@ def capture_responsive_dom(driver, cookies, config, percy_dom_script=None, **kwa
331331 _setup_resize_listener (driver )
332332 driver .execute_script ("PercyDOM.waitForResize();" )
333333 resize_count = 0 # Reset count because the listener just started fresh
334-
334+ print ( f' { width } x { height } ready, taking snapshot...' )
335335 _responsive_sleep ()
336336 dom_snapshot = get_serialized_dom (
337337 driver , cookies , percy_dom_script = percy_dom_script , ** kwargs )
338338 dom_snapshot ['width' ] = width
339+
340+ print (f'Taken snapshot for width: { width } , height: { height } ' )
339341 dom_snapshots .append (dom_snapshot )
340-
342+ with open ("output_file.json" , "w" ) as file_handle :
343+ json .dump (dom_snapshots , file_handle , indent = 4 )
344+
341345 change_window_dimension_and_wait (driver , current_width , current_height , resize_count + 1 )
342346 return dom_snapshots
343347
0 commit comments