@@ -14,14 +14,13 @@ def __init__(self, action_handler):
1414 "Clear" : self ._execute_clear ,
1515 "Scroll" : self ._execute_scroll ,
1616 "KeyboardPress" : self ._execute_keyboard_press ,
17- "FalsyConditionStatement" : self ._execute_falsy ,
18- "Check" : self ._execute_check ,
1917 "GetNewPage" : self ._execute_get_new_page ,
2018 "Upload" : self ._execute_upload ,
2119 "SelectDropdown" : self ._execute_select_dropdown ,
2220 "Drag" : self ._execute_drag ,
2321 "GoToPage" : self ._execute_go_to_page , # Added missing action
2422 "GoBack" : self ._execute_go_back , # Added browser back navigation
23+ "Mouse" : self ._execute_mouse , # Added mouse action
2524 }
2625
2726 async def initialize (self ):
@@ -146,14 +145,6 @@ async def _execute_keyboard_press(self, action):
146145 else :
147146 return {"success" : False , "message" : "Keyboard press failed." }
148147
149- async def _execute_falsy (self , action ):
150- """Execute falsy condition statement."""
151- return {"success" : True , "message" : "Falsy condition met." }
152-
153- async def _execute_check (self , action ):
154- """Execute check action."""
155- return {"success" : True , "message" : "Check action completed." }
156-
157148 async def _execute_get_new_page (self , action ):
158149 """Execute get new page action."""
159150 success = await self ._actions .get_new_page ()
@@ -335,4 +326,68 @@ async def _execute_go_back(self, action):
335326 return {"success" : False , "message" : "Go back action not supported by action handler" }
336327 except Exception as e :
337328 logging .error (f"Go back action failed: { str (e )} " )
338- return {"success" : False , "message" : f"Go back failed: { str (e )} " , "playwright_error" : str (e )}
329+ return {"success" : False , "message" : f"Go back failed: { str (e )} " , "playwright_error" : str (e )}
330+
331+ async def _execute_mouse (self , action ):
332+ """Unified mouse action supporting move and wheel.
333+
334+ Accepted param formats:
335+ - { op: "move", x: number, y: number }
336+ - { op: "wheel", deltaX: number, deltaY: number }
337+ - Back-compat: if op is omitted, decide by presence of keys
338+ """
339+ try :
340+ param = action .get ("param" )
341+ if not param or not isinstance (param , dict ):
342+ return {"success" : False , "message" : "Missing or invalid param for mouse action" }
343+
344+ op = param .get ("op" )
345+
346+ # Auto-detect if op not provided or empty
347+ if not op :
348+ if "x" in param and "y" in param :
349+ op = "move"
350+ elif "deltaX" in param or "deltaY" in param :
351+ op = "wheel"
352+ else :
353+ return {"success" : False , "message" : "Missing mouse operation parameters (x/y or deltaX/deltaY)" }
354+
355+ if op == "move" :
356+ if not self ._validate_params (action , ["param.x" , "param.y" ]):
357+ return {"success" : False , "message" : "Missing x or y coordinates for mouse move" }
358+
359+ x = param .get ("x" )
360+ y = param .get ("y" )
361+
362+ # Validate coordinates are numbers
363+ if not isinstance (x , (int , float )) or not isinstance (y , (int , float )):
364+ return {"success" : False , "message" : "x and y coordinates must be numbers" }
365+
366+ success = await self ._actions .mouse_move (x , y )
367+ if success :
368+ return {"success" : True , "message" : f"Mouse moved to ({ x } , { y } )" }
369+ else :
370+ return {"success" : False , "message" : "Mouse move action failed" }
371+
372+ elif op == "wheel" :
373+ # Default missing keys to 0
374+ dx = param .get ("deltaX" , 0 )
375+ dy = param .get ("deltaY" , 0 )
376+
377+ # Validate deltas are numbers
378+ if not isinstance (dx , (int , float )) or not isinstance (dy , (int , float )):
379+ return {"success" : False , "message" : "deltaX and deltaY must be numbers" }
380+
381+ success = await self ._actions .mouse_wheel (dx , dy )
382+ if success :
383+ return {"success" : True , "message" : f"Mouse wheel scrolled (deltaX: { dx } , deltaY: { dy } )" }
384+ else :
385+ return {"success" : False , "message" : "Mouse wheel action failed" }
386+
387+ else :
388+ logging .error (f"Unknown mouse op: { op } . Expected 'move' or 'wheel'." )
389+ return {"success" : False , "message" : f"Unknown mouse operation: { op } . Expected 'move' or 'wheel'" }
390+
391+ except Exception as e :
392+ logging .error (f"Mouse action execution failed: { str (e )} " )
393+ return {"success" : False , "message" : f"Mouse action failed with an exception: { e } " }
0 commit comments